Bindings

Almost all ICanBoogie packages can be used on their own, without involving the framework, but special packages, usually containing configuration files and additional classes, make them very easy to use with it. These special packages are called bindings and are prefixed with bind-. For instance, icanboogie/bind-routing binds icanboogie/routing to ICanBoogie.

It's not unusual for these packages to add methods and getters/setters to classes through the prototype system. The Application instance usually gets the most bindings, but is not the only one; as views are bound to controllers, and active record cache to models. For instance, the icanboogie/bind-routing package adds the url_for() method and the routes getter to the Application instance:

<?php

/* @var $app \ICanBoogie\Application */

$app->url_for('articles:index');
$app->routes->get('/articles', ArticleController::class);

These packages always provide corresponding binding traits to help type hinting. The binding trait from the routing package looks something like this:

<?php

namespace ICanBoogie\Binding\Routing;

use ICanBoogie\Routing\RouteCollection;

/**
 * @method string url_for($route_or_route_id, $values = null)
 *
 * @property RouteCollection $routes
 */
trait ApplicationBindings
{

}

And can be used to type hint the target class as follows:

<?php

namespace ICanBoogie;

class Application extends ApplicationAbstract
{
    use Binding\Routing\ApplicationBindings;
}

The framework includes the following bindings, but more are available:

Prototyped bindings

When the application is instantiated it adds the app getter to Prototyped instances, which allows these instances to obtain the instance of the application.

The following example demonstrates how the application instance can be obtained from a Prototyped instance. The PrototypedBindings trait may be used to type hint these instances:

<?php

namespace ICanBoogie;

use ICanBoogie\Binding\PrototypedBindings;

/* @var $app Application */
/* @var $prototyped Prototyped|PrototypedBindings */

$prototyped = new Prototyped;

try
{
    $prototyped->app;
}
catch (PropertyNotDefined $e)
{
    // `app` is not defined yet
}

$app = boot();
$app === $prototyped->app;
// true