Autoloader for Kirby
Helper to automatically load various Kirby extensions in a plugin
Commerical Usage
This package is free but if you use it in a commercial project please consider to
Installation
composer require bnomei/autoloader-for-kirby
This package is NOT a kirby plugin
- This is a composer package because that actually makes it easier to setup and does not mess with the loading order of extensions.
- Being a package it also can be used not only for local plugins but also as a composer dependency within plugins published online.
Autoloading of extensions
Add the autoloader for each extension type you want once and it will register all files in subfolders correctly.
Supported Extensions
The following extensions can be autoloaded:
- blueprints (php or yml)
- classes (php)
- collections (php)
- controllers (php)
- pageModels (php)
- userModels (php)
- snippets (php)
- templates (php)
- translations (php or yml or json)
NOTE: Loading translations from yaml or json files is added by this package and not originally part of kirby core.
NOTE: The
classes
autoloader is very basic. Using a custom array with kirby'sload()
-helper or composers psr-4 autoloading is recommended.
Usage
After requiring it as a dependency in either your project or plugin composer.json
you can use the autoload()
-helper to load various extension.
/site/plugins/example/index.php
// optionally change some settings
/*
autoloader(__DIR__, [
'snippets' => [
'folder' => 'schnippschnapp',
],
]);
*/
autoloader(__DIR__)->classes();
// use a different folder
// autoloader(__DIR__)->classes('src');
Kirby::plugin('bnomei/example', [
'options' => [
// options
],
'blueprints' => autoloader(__DIR__)->blueprints(),
'collections' => autoloader(__DIR__)->collections(),
'controllers' => autoloader(__DIR__)->controllers(),
'pageModels' => autoloader(__DIR__)->pageModels(),
'userModels' => autoloader(__DIR__)->userModels(),
'snippets' => autoloader(__DIR__)->snippets(),
'templates' => autoloader(__DIR__)->templates(),
'translations' => autoloader(__DIR__)->translations(),
// other extensions
]);
Settings
The package does come with default settings to fit most usecases.
Suggestion
This plugin works great in combination with my Kirby CLI Tool which helps you to create extension files faster.
Disclaimer
This package is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
License
It is discouraged to use this package in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.