Skip to content

Commit d1bc5b9

Browse files
committed
✨ support for autoloading block models (kirby v3.6)
closes #1
1 parent 4b5336f commit d1bc5b9

File tree

7 files changed

+215
-83
lines changed

7 files changed

+215
-83
lines changed

classes/Autoloader.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final class Autoloader
1212
// exclude files like filename.config.(php|yml)
1313
public const PHP = '/^[\w\d\-\_]+\.php$/';
1414
public const ANY_PHP = '/^[\w\d\-\_\.]+\.php$/';
15+
public const BLOCK_PHP = '/^[\w\d\-\_]+(Block)\.php$/';
1516
public const PAGE_PHP = '/^[\w\d\-\_]+(Page)\.php$/';
1617
public const USER_PHP = '/^[\w\d\-\_]+(User)\.php$/';
1718
public const YML = '/^[\w\d\-\_]+\.yml$/';
@@ -60,6 +61,14 @@ public function __construct(array $options = [])
6061
'require' => true,
6162
'lowercase' => true,
6263
],
64+
'blockmodels' => [
65+
'folder' => 'models',
66+
'name' => static::BLOCK_PHP,
67+
'key' => 'classname',
68+
'require' => false,
69+
'lowercase' => true,
70+
'map' => [],
71+
],
6372
'pagemodels' => [
6473
'folder' => 'models',
6574
'name' => static::PAGE_PHP,
@@ -158,7 +167,7 @@ private function registry(string $type): array
158167
}
159168
$this->registry[$type]['map'][$class] = $file->getRelativePathname();
160169

161-
foreach(['Page', 'User'] as $suffix) {
170+
foreach(['Page', 'User', 'Block'] as $suffix) {
162171
$at = strpos($key, $suffix);
163172
if ($at === strlen($key) - strlen($suffix)) {
164173
$key = substr($key, 0, -strlen($suffix));
@@ -239,6 +248,11 @@ public function controllers(): array
239248
return $this->registry('controllers');
240249
}
241250

251+
public function blockModels(): array
252+
{
253+
return $this->registry('blockmodels');
254+
}
255+
242256
public function pageModels(): array
243257
{
244258
return $this->registry('pagemodels');

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/autoloader-for-kirby",
33
"type": "project",
4-
"version": "1.2.9",
4+
"version": "1.3.0",
55
"license": "MIT",
66
"description": "Helper to automatically load various Kirby extensions in a plugin",
77
"authors": [

0 commit comments

Comments
 (0)