Addons

Addons are a great way to reuse and share code easily. They are based on the Contexts API and can add routes, write data, modify the response and so on.

Composer will automatically register an addon, but if you have downloaded it manually you must add the following code:

// Includes the addon autoload file.
require '/path/to/addon/autoload.php';

Then you need to enable it for your app by calling $app->addons->add().

use BearFramework\App;

$app App::get();

// Enables the addon specified.
$app->addons->add('bearframework/tasks-addon');

Creating an addon

There are only two requirements for an addon.

1. Create an autoload.php file that registers the addon.

// Registers a new addon by specifying its name and source directory.
BearFramework\Addons::register('myname/sample-addon'__DIR__);

2. Create an index file with your addon logic.

use BearFramework\App;

$app App::get();

$app->routes->add('/addon/', function() {
    return new 
App\Response('The sample addon has rendered this page.');
});

We've prepared a sample addon that you can download and modify.

Learn more

Handle HTTP requests
Store and retrieve data

The information on this page is created for version 1.1 of Bear Framework and may not be applicable for other versions of the framework.