I'm using Silex Framework. I wrote a simple route resource loader that is used that way :
$app->register( new RouteCollectionLoaderProvider);
$app["mp.route_loader"]->append(array(
array(
"type"=>"yaml",
"path"=>__DIR__."/Resources/routes/routes.yml",
"prefix"=>"/",
)
));
the source code is here : https://github.com/Mparaiso/silex-extensions/blob/master/src/Mparaiso/Provider/RouteCollectionLoaderProvider.php
i'm able to load routes named the regular way ,for instance , in a yaml file
index:
pattern: /
defaults: {_controller: Controller\DefaultController::index }
but i'm unable to load controllers defined as services :
$app["my.controller"] = function(){ return new MyController;};
info:
pattern: /info
defaults: {_controller: my.controller:info }
what would it take to be able to use the controller as a service syntax in a resource file ?
thanks
Silex ships with a ServiceControllerServiceProvider, which you can use to get controllers as services.
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app['my.controller'] = $app->share(function ($app) {
return new MyController($app['my.service']);
});
$app->get('/info', 'my.controller:info');
This should work with your custom loader as well.