Fix Pico::loadPlugin() when called before Pico::loadPlugins()
This commit is contained in:
parent
e8e60f49e5
commit
36b3aef1c7
27
lib/Pico.php
27
lib/Pico.php
@ -117,9 +117,9 @@ class Pico
|
|||||||
* List of loaded plugins
|
* List of loaded plugins
|
||||||
*
|
*
|
||||||
* @see Pico::getPlugins()
|
* @see Pico::getPlugins()
|
||||||
* @var object[]|null
|
* @var object[]
|
||||||
*/
|
*/
|
||||||
protected $plugins;
|
protected $plugins = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current configuration of this Pico instance
|
* Current configuration of this Pico instance
|
||||||
@ -469,8 +469,6 @@ class Pico
|
|||||||
*/
|
*/
|
||||||
protected function loadPlugins()
|
protected function loadPlugins()
|
||||||
{
|
{
|
||||||
$this->plugins = array();
|
|
||||||
|
|
||||||
// discover plugin files
|
// discover plugin files
|
||||||
$pluginFiles = array();
|
$pluginFiles = array();
|
||||||
$files = scandir($this->getPluginsDir());
|
$files = scandir($this->getPluginsDir());
|
||||||
@ -520,6 +518,10 @@ class Pico
|
|||||||
$plugin = new $className($this);
|
$plugin = new $className($this);
|
||||||
$className = get_class($plugin);
|
$className = get_class($plugin);
|
||||||
|
|
||||||
|
if (isset($this->plugins[$className])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$this->plugins[$className] = $plugin;
|
$this->plugins[$className] = $plugin;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
@ -563,9 +565,6 @@ class Pico
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->plugins === null) {
|
|
||||||
$this->plugins = array();
|
|
||||||
}
|
|
||||||
$this->plugins[$className] = $plugin;
|
$this->plugins[$className] = $plugin;
|
||||||
|
|
||||||
return $plugin;
|
return $plugin;
|
||||||
@ -1296,7 +1295,7 @@ class Pico
|
|||||||
$contentExtLength = strlen($contentExt);
|
$contentExtLength = strlen($contentExt);
|
||||||
|
|
||||||
$this->pages = array();
|
$this->pages = array();
|
||||||
$files = $this->getFiles($contentDir, $contentExt, Pico::SORT_NONE);
|
$files = $this->getFiles($contentDir, $contentExt, self::SORT_NONE);
|
||||||
foreach ($files as $i => $file) {
|
foreach ($files as $i => $file) {
|
||||||
// skip 404 page
|
// skip 404 page
|
||||||
if (basename($file) === '404' . $contentExt) {
|
if (basename($file) === '404' . $contentExt) {
|
||||||
@ -2012,13 +2011,11 @@ class Pico
|
|||||||
*/
|
*/
|
||||||
public function triggerEvent($eventName, array $params = array())
|
public function triggerEvent($eventName, array $params = array())
|
||||||
{
|
{
|
||||||
if ($this->plugins) {
|
foreach ($this->plugins as $plugin) {
|
||||||
foreach ($this->plugins as $plugin) {
|
// only trigger events for plugins that implement PicoPluginInterface
|
||||||
// only trigger events for plugins that implement PicoPluginInterface
|
// deprecated events (plugins for Pico 0.9 and older) will be triggered by `PicoDeprecated`
|
||||||
// deprecated events (plugins for Pico 0.9 and older) will be triggered by `PicoDeprecated`
|
if ($plugin instanceof PicoPluginInterface) {
|
||||||
if ($plugin instanceof PicoPluginInterface) {
|
$plugin->handleEvent($eventName, $params);
|
||||||
$plugin->handleEvent($eventName, $params);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user