Skip to content

Commit

Permalink
✨ unroll blueprint files to arrays, adding needed name key automati…
Browse files Browse the repository at this point in the history
…cally

Signed-off-by: bnomei <[email protected]>
  • Loading branch information
bnomei committed Mar 21, 2024
1 parent 6bad8e6 commit 7aae435
Show file tree
Hide file tree
Showing 13 changed files with 931 additions and 437 deletions.
19 changes: 14 additions & 5 deletions classes/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(array $options = [])
'folder' => 'blueprints',
'name' => self::ANY_PHP_OR_YML,
'key' => 'relativepath',
'require' => false,
'require' => true, // false
'transform' => fn ($key) => strtolower($key),
],
'classes' => [
Expand Down Expand Up @@ -213,6 +213,7 @@ private function registry(string $type): array
}
}
}

if (empty($key)) {
continue;
} else {
Expand Down Expand Up @@ -246,12 +247,16 @@ private function registry(string $type): array
is_array($route) ? $route : []
);
}
} elseif ($options['require'] && $extension && strtolower($extension) === 'php') {
$path = $file->getPathname();
$this->registry[$type][$key] = require_once $path;
} elseif ($options['folder'] === 'blueprints' && $extension && strtolower($extension) === 'php') {
$path = $file->getPathname();
$this->registry[$type][$key] = require_once $path;
$this->registry[$type][$key] = include $path; // require will link, include will read
if (is_array($this->registry[$type][$key])) {
$kk = explode('/', $key);
$this->registry[$type][$key]['name'] = array_pop($kk);
}
} elseif ($options['require'] && $extension && strtolower($extension) === 'php') {
$path = $file->getPathname();
$this->registry[$type][$key] = include $path; // require will link, include will read
} elseif ($options['require'] && $extension && strtolower($extension) === 'json') {
$path = $file->getPathname();
$this->registry[$type][$key] = json_decode(file_get_contents($path), true);
Expand All @@ -264,6 +269,10 @@ private function registry(string $type): array
} else {
$this->registry[$type][$key] = Spyc::YAMLLoadString($yaml);
}
if (is_array($this->registry[$type][$key]) && $options['folder'] === 'blueprints') {
$kk = explode('/', $key);
$this->registry[$type][$key]['name'] = array_pop($kk);
}
} else {
$this->registry[$type][$key] = $file->getRealPath();
}
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bnomei/autoloader-for-kirby",
"type": "project",
"version": "4.1.0",
"version": "4.2.0",
"license": "MIT",
"description": "Helper to automatically load various Kirby extensions in a plugin",
"authors": [
Expand Down Expand Up @@ -60,11 +60,12 @@
},
"require-dev": {
"getkirby/cms": "^4.0.0-beta.2",
"larastan/larastan": "^2.9",
"laravel/pint": "^1.13",
"nunomaduro/larastan": "^2.6",
"pestphp/pest": "^2.24",
"pestphp/pest-plugin-drift": "^2.5",
"pestphp/pest-plugin-type-coverage": "^2.4"
"pestphp/pest-plugin-type-coverage": "^2.4",
"spatie/ray": "^1.41"
},
"scripts": {
"analyze": "./vendor/bin/phpstan",
Expand Down
Loading

0 comments on commit 7aae435

Please sign in to comment.