diff --git a/README.md b/README.md index 3bb67e5..7cd077f 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,9 @@ git submodule add https://github.com/afbora/kirby-loader.git site/plugins/kirby- return [ 'afbora.loader.roots' => [ '/plugins/core', - '/plugins/theme', - '/plugins/gateways', + '/plugins/payment', + '/plugins/shipping', + '/theme', // Register single plugin ] ]; diff --git a/composer.json b/composer.json index 2964ab5..bf41aa7 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "afbora/kirby-loader", "description": "Kirby plugins loader from multiple roots", "keywords": [], - "version": "1.0", + "version": "1.1", "type": "kirby-plugin", "license": "MIT", "authors": [ diff --git a/src/Loader.php b/src/Loader.php index 5cb6c3d..af3a66e 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -28,24 +28,29 @@ public function register() } } - protected function pluginsLoader(string $root): array + protected function pluginsLoader(string $root): void { - $loaded = []; - foreach (Dir::read($root) as $dirname) { - if (in_array(substr($dirname, 0, 1), ['.', '_']) === true) { - continue; + if ($this->readDir(basename($root), dirname($root)) === false) { + foreach (Dir::read($root) as $dirname) { + $this->readDir($dirname, $root); } - if (is_dir($root . '/' . $dirname) === false) { - continue; - } - $dir = $root . '/' . $dirname; - $entry = $dir . '/index.php'; - if (file_exists($entry) === false) { - continue; - } - include_once $entry; - $loaded[] = $dir; } - return $loaded; + } + + protected function readDir(string $dirname, string $root): bool + { + if (in_array(substr($dirname, 0, 1), ['.', '_']) === true) { + return false; + } + $dir = $root . DIRECTORY_SEPARATOR . $dirname; + if (is_dir($dir) === false) { + return false; + } + $entry = $dir . DIRECTORY_SEPARATOR . 'index.php'; + if (file_exists($entry) === false) { + return false; + } + include_once $entry; + return true; } }