jonsa / silex-ioc
IoC for Silex application
v0.2.0
2015-10-07 22:13 UTC
Requires
- jonsa/pimple-ioc: 1.3.*
- silex/silex: ~2.0@dev
Requires (Dev)
- phpunit/phpunit: 4.8.*
This package is not auto-updated.
Last update: 2025-07-05 22:52:47 UTC
README
Class resolver for the Silex application.
This project is a bridge between Pimple IoC and the Silex Application.
Installation
Add the IoC container to your composer.json
using the command line.
composer require jonsa/silex-ioc
Usage
The class resolver is registered in Silex as a ServiceProvider
use Jonsa\PimpleResolver\ServiceProvider as PimpleResolverServiceProvider; use Jonsa\SilexResolver\ServiceProvider as SilexResolverServiceProvider; use Silex\Application; $app = new Application(); $app->register(new PimpleResolverServiceProvider()); $app->register(new SilexResolverServiceProvider());
Events
The Silex event dispatcher is registered with PimpleResolver which makes it easy to inject into the resolver.
use Jonsa\PimpleResolver\Event\ClassResolvedEvent; use Jonsa\PimpleResolver\Events as ResolverEvents; $app->on(ResolverEvents::CLASS_RESOLVED, function (ClassResolvedEvent $event) { $object = $event->getResolvedObject(); ... });
Configuration
The ServiceProvider has one configuration parameter.
class ServiceProvider implements ServiceProviderInterface { public function __construct($resolveControllers = true) { ... } }
$resolveControllers
tells the ServiceProvider whether to replace the built-in controller resolver in Silex. If set to true controllers will be resolved out of the IoC container.