Controller provider for silex applications
Controller provider for silex, (*1)
This provider contains the logic to load your controllers dynamically, registering them in you Silex Applications. With this, you no longer needs to manually register each one of your controllers, passing their respective dependencies., (*2)
To install it:, (*3)
$ composer require "flaviojr/silex-controller-provider":"1.0"
To use this provider, you simply need to register it within your application:, (*4)
//Don't forget to register this provider first $app->register(new Silex\Provider\ServiceControllerServiceProvider); $app->register(new Sneek\Providers\ControllerProvider('controller-dir', 'Your-root-namespace'[, 'your-namespace-mirror']));
App\Controllers\HomeController, then the value to be passed is the string 'App'.
src/Controllers/CoffeeController, having the namespace
App\Controllers\CoffeeControlleryou have to pass the 'src' string, so that the provider know that 'src' is equivalent to 'App' in this case.
The provider register your controllers using their namespaces as index. To access they in your routes, you just need to pass their namespace followed by the method you are trying to access., (*5)