Hey there,
I’m looking for a rule of thumb developing a plugin for Kirby, when to use
load([
namespace\\class => ' __DIR__ . DS . 'some-folder' . DS . /some-file.php'
]);
and when to use require
… It seems that composer autoload files don’t go with load()
, or do they? And what’s the best practice on storing default options and accessing them from within the plugin (booleans, strings, but also arrays) … and should they be declared in the plugin’s main entry file?
Thank you, any help is appreciated!
In my plugins I have never mixed Composer and Load so I don’t know if there are compatibility issues between them.
I would suggest you to go with load
when your plugin needs more than one class and doesn’t depend on any Composer package. That’s what I did with Page Lock.
Using Composer you can leverage PSR-4 autoloading which doesn’t require you to register each class manually. See examples of this on the Blade Template and Meta Tags plugins. Also checkout the composer.json
file on those repos.
Another tip with Composer is to commit the vendor
directory so people can install your plugin simply by downloading the ZIP file or using Kirby’s CLI.
1 Like