Skip to content

Commit

Permalink
🐛 blueprints from php loader, merging duplicates
Browse files Browse the repository at this point in the history
Signed-off-by: bnomei <[email protected]>
  • Loading branch information
bnomei committed Oct 12, 2023
1 parent f04a2d1 commit 10e8a62
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
21 changes: 11 additions & 10 deletions classes/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public function __construct(array $options = [])
'require' => true,
'transform' => fn ($key) => static::pascalToKebabCase($key),
],
'blockmodels' => [
'blockModels' => [
'folder' => 'models',
'name' => static::BLOCK_PHP,
'key' => 'classname',
'require' => false,
'transform' => fn ($key) => static::pascalToKebabCase($key),
'map' => [],
],
'pagemodels' => [
'pageModels' => [
'folder' => 'models',
'name' => static::PAGE_PHP,
'key' => 'classname',
Expand All @@ -103,7 +103,7 @@ public function __construct(array $options = [])
'require' => true,
'transform' => false,
],
'usermodels' => [
'userModels' => [
'folder' => 'models',
'name' => static::USER_PHP,
'key' => 'classname',
Expand Down Expand Up @@ -231,6 +231,9 @@ private function registry(string $type): array
} 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;
} elseif ($options['require'] && $extension && strtolower($extension) === 'json') {
$path = $file->getPathname();
$this->registry[$type][$key] = json_decode(file_get_contents($path), true);
Expand Down Expand Up @@ -274,7 +277,7 @@ private function registry(string $type): array
// if blueprint is not empty
if (!empty($blueprint)) {
// merge with existing blueprint
$this->registry['blueprints'] = array_merge_recursive($this->registry['blueprints'], $blueprint);
$this->registry['blueprints'] = array_merge($this->registry['blueprints'], $blueprint);
}
}
}
Expand Down Expand Up @@ -315,12 +318,12 @@ public function controllers(): array

public function blockModels(): array
{
return $this->registry('blockmodels');
return $this->registry('blockModels');
}

public function pageModels(): array
{
return $this->registry('pagemodels');
return $this->registry('pageModels');
}

public function routes(): array
Expand All @@ -335,7 +338,7 @@ public function apiRoutes(): array

public function userModels(): array
{
return $this->registry('usermodels');
return $this->registry('userModels');
}

public function snippets(): array
Expand Down Expand Up @@ -376,9 +379,7 @@ public function toArray(array $merge = []): array
foreach ($types as $callback) {
$c = (array) $callback();
$r = (array) $this->registry;
$this->registry = array_merge_recursive($r, $c);
// NOTE: if done like this PHP does not merge correctly for whatever reason
// $this->registry = array_merge_recursive($this->registry, $callback());
$this->registry = array_merge($r, $c);
}

// merge on top but do not store in the registry
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bnomei/autoloader-for-kirby",
"type": "project",
"version": "1.10.4",
"version": "1.11.0",
"license": "MIT",
"description": "Helper to automatically load various Kirby extensions in a plugin",
"authors": [
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php return array(
'root' => array(
'name' => 'bnomei/autoloader-for-kirby',
'pretty_version' => '1.10.4',
'version' => '1.10.4.0',
'pretty_version' => '1.11.0',
'version' => '1.11.0.0',
'reference' => NULL,
'type' => 'project',
'install_path' => __DIR__ . '/../../',
Expand All @@ -11,8 +11,8 @@
),
'versions' => array(
'bnomei/autoloader-for-kirby' => array(
'pretty_version' => '1.10.4',
'version' => '1.10.4.0',
'pretty_version' => '1.11.0',
'version' => '1.11.0.0',
'reference' => NULL,
'type' => 'project',
'install_path' => __DIR__ . '/../../',
Expand Down

0 comments on commit 10e8a62

Please sign in to comment.