Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions app/Logger/Plugins/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -90,40 +92,54 @@ 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;
}

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;
Expand Down
Binary file modified builds/expose
Binary file not shown.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down