PHP code example of bnomei / autoloader-for-kirby

1. Go to this page and download the library: Download bnomei/autoloader-for-kirby library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bnomei / autoloader-for-kirby example snippets




// only autoloader
Kirby::plugin('bnomei/example', autoloader(__DIR__)->toArray());



// merge autoloader with custom config
Kirby::plugin('bnomei/example', autoloader(__DIR__)->toArray([
    'options' => [
        // options
    ],
    // other extensions
]));



// optionally change some settings
/*
autoloader(__DIR__, [
    'snippets' => [
        'folder' => 'schnippschnapp',
    ],
]);
*/

autoloader(__DIR__)->classes();
// use a different folder
// autoloader(__DIR__)->classes('src');

// set each option explicitly without merging
Kirby::plugin('bnomei/example', [
    'options' => [
        // options
    ],
    'blueprints' => autoloader(__DIR__)->blueprints(),
    'collections' => autoloader(__DIR__)->collections(),
    'commands' => autoloader(__DIR__)->commands(),
    'controllers' => autoloader(__DIR__)->controllers(),
    'blockModels' => autoloader(__DIR__)->blockModels(),
    'pageModels' => autoloader(__DIR__)->pageModels(),
    'routes' => autoloader(__DIR__)->routes(),
    'userModels' => autoloader(__DIR__)->userModels(),
    'snippets' => autoloader(__DIR__)->snippets(),
    'templates' => autoloader(__DIR__)->templates(),
    'translations' => autoloader(__DIR__)->translations(),
    // other extensions
]);



Kirby::plugin('bnomei/example', autoloader(__DIR__, [
        'blockModels' => [
            // mapping BlockModel class names to file names, like
            // MyCustomBlock::class => 'my.custom' (site/blueprints/blocks/my.custom.yml)
            'transform' => fn ($key) => \Bnomei\Autoloader::pascalToDotCase($key),
        ],
    ])->toArray()
);