Skip to content

Commit 7aae435

Browse files
committed
✨ unroll blueprint files to arrays, adding needed name key automatically
Signed-off-by: bnomei <[email protected]>
1 parent 6bad8e6 commit 7aae435

File tree

13 files changed

+931
-437
lines changed

13 files changed

+931
-437
lines changed

classes/Autoloader.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(array $options = [])
5959
'folder' => 'blueprints',
6060
'name' => self::ANY_PHP_OR_YML,
6161
'key' => 'relativepath',
62-
'require' => false,
62+
'require' => true, // false
6363
'transform' => fn ($key) => strtolower($key),
6464
],
6565
'classes' => [
@@ -213,6 +213,7 @@ private function registry(string $type): array
213213
}
214214
}
215215
}
216+
216217
if (empty($key)) {
217218
continue;
218219
} else {
@@ -246,12 +247,16 @@ private function registry(string $type): array
246247
is_array($route) ? $route : []
247248
);
248249
}
249-
} elseif ($options['require'] && $extension && strtolower($extension) === 'php') {
250-
$path = $file->getPathname();
251-
$this->registry[$type][$key] = require_once $path;
252250
} elseif ($options['folder'] === 'blueprints' && $extension && strtolower($extension) === 'php') {
253251
$path = $file->getPathname();
254-
$this->registry[$type][$key] = require_once $path;
252+
$this->registry[$type][$key] = include $path; // require will link, include will read
253+
if (is_array($this->registry[$type][$key])) {
254+
$kk = explode('/', $key);
255+
$this->registry[$type][$key]['name'] = array_pop($kk);
256+
}
257+
} elseif ($options['require'] && $extension && strtolower($extension) === 'php') {
258+
$path = $file->getPathname();
259+
$this->registry[$type][$key] = include $path; // require will link, include will read
255260
} elseif ($options['require'] && $extension && strtolower($extension) === 'json') {
256261
$path = $file->getPathname();
257262
$this->registry[$type][$key] = json_decode(file_get_contents($path), true);
@@ -264,6 +269,10 @@ private function registry(string $type): array
264269
} else {
265270
$this->registry[$type][$key] = Spyc::YAMLLoadString($yaml);
266271
}
272+
if (is_array($this->registry[$type][$key]) && $options['folder'] === 'blueprints') {
273+
$kk = explode('/', $key);
274+
$this->registry[$type][$key]['name'] = array_pop($kk);
275+
}
267276
} else {
268277
$this->registry[$type][$key] = $file->getRealPath();
269278
}

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/autoloader-for-kirby",
33
"type": "project",
4-
"version": "4.1.0",
4+
"version": "4.2.0",
55
"license": "MIT",
66
"description": "Helper to automatically load various Kirby extensions in a plugin",
77
"authors": [
@@ -60,11 +60,12 @@
6060
},
6161
"require-dev": {
6262
"getkirby/cms": "^4.0.0-beta.2",
63+
"larastan/larastan": "^2.9",
6364
"laravel/pint": "^1.13",
64-
"nunomaduro/larastan": "^2.6",
6565
"pestphp/pest": "^2.24",
6666
"pestphp/pest-plugin-drift": "^2.5",
67-
"pestphp/pest-plugin-type-coverage": "^2.4"
67+
"pestphp/pest-plugin-type-coverage": "^2.4",
68+
"spatie/ray": "^1.41"
6869
},
6970
"scripts": {
7071
"analyze": "./vendor/bin/phpstan",

0 commit comments

Comments
 (0)