diff --git a/lib/Pico.php b/lib/Pico.php index 829d749..6ffd810 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -540,7 +540,13 @@ class Pico */ protected function loadLocalPlugins() { - $pluginsLowered = array_change_key_case($this->plugins, CASE_LOWER); + // scope isolated require() + $includeClosure = function ($pluginFile) { + require($pluginFile); + }; + if (PHP_VERSION_ID >= 50400) { + $includeClosure = $includeClosure->bindTo(null); + } $pluginFiles = array(); $files = scandir($this->getPluginsDir()) ?: array(); @@ -549,56 +555,27 @@ class Pico continue; } + $className = $pluginFile = null; if (is_dir($this->getPluginsDir() . $file)) { $className = preg_replace('/^[0-9]+-/', '', $file); - $classNameLowered = strtolower($className); - - if (isset($pluginsLowered[$classNameLowered])) { - continue; - } - - if (file_exists($this->getPluginsDir() . $file . '/' . $className . '.php')) { - $pluginFiles[$className] = $file . '/' . $className . '.php'; - } else { - $subdirFiles = $this->getFilesGlob($this->getPluginsDir() . $file . '/?*.php', self::SORT_NONE); - foreach ($subdirFiles as $subdirFile) { - $subdirFile = basename($subdirFile, '.php'); - if ($classNameLowered === strtolower($subdirFile)) { - $pluginFiles[$className] = $file . '/' . $subdirFile . '.php'; - break; - } - } - } + $pluginFile = $file . '/' . $className . '.php'; - if (!isset($pluginFiles[$className])) { + if (!file_exists($this->getPluginsDir() . $pluginFile)) { throw new RuntimeException( - "Unable to load plugin '" . $className . "' from " - . "'" . $file . "/" . $className . ".php': File not found" + "Unable to load plugin '" . $className . "' from '" . $pluginFile . "': File not found" ); } } elseif (substr($file, -4) === '.php') { $className = preg_replace('/^[0-9]+-/', '', substr($file, 0, -4)); - $classNameLowered = strtolower($className); - - if (isset($pluginsLowered[$classNameLowered])) { - continue; - } - - $pluginFiles[$className] = $file; + $pluginFile = $file; } else { throw new RuntimeException("Unable to load plugin from '" . $file . "': Not a valid plugin file"); } - } - // scope isolated require() - $includeClosure = function ($pluginFile) { - require($pluginFile); - }; - if (PHP_VERSION_ID >= 50400) { - $includeClosure = $includeClosure->bindTo(null); - } + if (isset($this->plugins[$className])) { + continue; + } - foreach ($pluginFiles as $className => $pluginFile) { $includeClosure($this->getPluginsDir() . $pluginFile); if (class_exists($className, false)) { @@ -614,7 +591,9 @@ class Pico } } } else { - throw new RuntimeException("Unable to load plugin '" . $className . "' from '" . $pluginFile . "'"); + throw new RuntimeException( + "Unable to load plugin '" . $className . "' from '" . $pluginFile . "': Plugin class not found" + ); } } }