public function register()
{
$this->app['parameters'] = $this->app->share(function ($app) {
return new Parameters();
});
// Find the default Controller class of the current Laravel application
$controllerClass = $this->app['config']->get('authority-controller.controllerClass', 'Illuminate\\Routing\\Controller');
$this->app->resolving(function ($object) use($controllerClass) {
// Check if the current $object class is a Controller class and if it responds to paramsBeforeFilter method
if (is_a($object, $controllerClass) && respond_to($object, 'paramsBeforeFilter')) {
// Fill $params properties of the current controller
$this->app['parameters']->fillController($object);
}
});
$this->app['authority'] = $this->app->share(function ($app) {
$user = $app['auth']->user();
$authority = new Authority($user);
$fn = $app['config']->get('authority-controller.initialize');
$serializer = new Serializer();
if (is_string($fn)) {
$fn = $serializer->unserialize($fn);
}
if ($fn) {
$fn($authority);
}
return $authority;
});
$this->app->bind('Efficiently\\AuthorityController\\ControllerResource', function ($app, $parameters) {
list($controller, $resourceName, $resourceOptions) = $parameters;
return new ControllerResource($controller, $resourceName, $resourceOptions);
});
}