Packages can be used to override, extend or add new functionality to the framework. Packages can contain classes, config files, tasks and views.
Packages are installed in the app/packages directory. Here's the directory structure of a basic package containing only one class:
All packages must include a _init.php file. This is where you define constants, global functions and set up autoloading of the package classes. You can map classes using the Mako class loader or write your own autoloader.
<?php // Map classes mako\ClassLoader::addClasses(array ( 'Foo' => __DIR__ . '/classes/Foo.php', ));
Here's the directory structure of a more complex package containing tasks, views, config files and language files:
You use the Config::get method to load configurations inside a package. The only difference is that you have to prefix the name of the config file with the name of your package followed by two colons (::). The same convention is used when creating views or running tasks.
// Loads the "app/packages/foobar/config/config.php" file
$config = Config::get('foobar::config');
// Loads the "app/packages/foobar/views/view.php" file
$view = new View('foobar::view');
// Execute the default task action
php reactor task foobar::task
Installing packages is extremely easy. Just drop the package in the app/packages directory and you're ready to go!
You can also install packages using the CLI installer:
php reactor package install git://github.com/mako-framework/gravatar.git
Uninstalling the package can also be done via the CLI:
php reactor package remove gravatar
You need to initialize a package before you can use it in your application. This can be done using the Package::init method or by registering the package(s) you want to auto-initialize in app/config/mako.php config file.
Package::init('gravatar');