Skip to content

Commit

Permalink
Registering single plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Aug 2, 2019
1 parent a9af48d commit 047eaa5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
];

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
37 changes: 21 additions & 16 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 047eaa5

Please sign in to comment.