If I had the following code how would I get the calling method and the class in the provider:
class HelloServiceProvider implements ServiceProviderInterface {
public function register(Application $app){
$app['hello'] = $app->share(function () {
// Get hello/indexAction
});
}
public function boot(Application $app){}
}
class hello {
public function addAction(){
$app['hello']()
}
}
$app->get('/hello', 'hello.controller:indexAction');
Is this even possible? Thanks
Is it, indeed, possible but you need some changes:
<?php
// file HelloServiceProvider.php
class HelloServiceProvider implements ServiceProviderInterface {
public function register(Application $app){
$app['hello'] = $app->share(function () {
// Get hello/indexAction
});
}
public function boot(Application $app){}
}
// file Hello.php
class Hello {
public function indexAction(Application $app){
$app['hello']()
}
}
// somewhere in your code:
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app->register(new HelloServiceProvider());
$app['hello.controller'] = $app->share(function() {
return new hello();
});
$app->get('/hello', 'hello.controller:indexAction');
Notice that the use statements are missing from code
You can get more information in the official documentation.