diff --git a/app/Logger/Plugins/PluginManager.php b/app/Logger/Plugins/PluginManager.php index d8b78eb..f9c8987 100644 --- a/app/Logger/Plugins/PluginManager.php +++ b/app/Logger/Plugins/PluginManager.php @@ -12,6 +12,8 @@ use PhpParser\NodeVisitor\CloningVisitor; use PhpParser\Parser\Php7; use PhpParser\PrettyPrinter\Standard; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Finder\SplFileInfo; class PluginManager { @@ -90,16 +92,27 @@ protected function loadCustomPlugins(): array return []; } - foreach (scandir($pluginDirectory) as $file) { - if (str($file)->startsWith('.')) { - continue; - } + $finder = (new Finder()) + ->files() + ->in($pluginDirectory) + ->name('*.php') + ->contains('Expose\Client\Logger\Plugins\BasePlugin') + ->filter(function (SplFileInfo $file) { + require_once $file->getPathname(); // required because autoloader won't be able to find this file in the normal path based on the namespace + + $pluginClass = 'Expose\Client\Logger\Plugins\\' . $file->getFilenameWithoutExtension(); - require_once $pluginDirectory . DIRECTORY_SEPARATOR . $file; + if (!class_exists($pluginClass) || !is_subclass_of($pluginClass, BasePlugin::class)) { + return false; + } - $pluginClass = 'Expose\\Client\\Logger\\Plugins\\' . pathinfo($file, PATHINFO_FILENAME); + return true; + }) + ->sortByName() + ; - $this->customPlugins[] = $pluginClass; + foreach ($finder as $file) { + $this->customPlugins[] = 'Expose\Client\Logger\Plugins\\' . $file->getFilenameWithoutExtension(); } return $this->customPlugins; @@ -107,23 +120,26 @@ protected function loadCustomPlugins(): array protected function loadDefaultPlugins(): array { - $defaultPluginDirectory = scandir($this->getDefaultPluginDirectory()); $this->defaultPlugins = []; - foreach ($defaultPluginDirectory as $file) { - if ($file === '.' || $file === '..') { - continue; - } - - require_once $this->getDefaultPluginDirectory() . DIRECTORY_SEPARATOR . $file; + $finder = (new Finder()) + ->files() + ->in($this->getDefaultPluginDirectory()) + ->name('*.php') + ->filter(function (SplFileInfo $file) { + $pluginClass = 'Expose\Client\Logger\Plugins\\' . $file->getFilenameWithoutExtension(); - $pluginClass = 'Expose\\Client\\Logger\\Plugins\\' . pathinfo($file, PATHINFO_FILENAME); + if (!class_exists($pluginClass) || !is_subclass_of($pluginClass, BasePlugin::class)) { + return false; + } - if (!class_exists($pluginClass) || !is_subclass_of($pluginClass, BasePlugin::class)) { - continue; - } + return true; + }) + ->sortByName() + ; - $this->defaultPlugins[] = $pluginClass; + foreach ($finder as $file) { + $this->defaultPlugins[] = 'Expose\Client\Logger\Plugins\\' . $file->getFilenameWithoutExtension(); } return $this->defaultPlugins; diff --git a/builds/expose b/builds/expose index bf6b965..3621a6f 100755 Binary files a/builds/expose and b/builds/expose differ diff --git a/composer.json b/composer.json index 62ae5cd..1deacfe 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "react/stream": "^1.1.1", "riverline/multipart-parser": "^2.0", "symfony/expression-language": "^5.2", + "symfony/finder": "^7.0", "symfony/http-kernel": "^7.0", "symfony/psr-http-message-bridge": "^7.0", "symfony/yaml": "^7.0"