I come from a Spring/Java background and i'm learning Symfony/PHP. It's amazingly similar and i love it.
In Spring we can @Autowire dependencies. What is the equivalent of that in Symfony? I want to inject my dependencies using annotations. And i dont want to specify that in an xml or yml.
For example:
class foo {
/**
* @Inject \ABC\XYZ\Dependency
*/
private $dependency;
public function abc(){
$dependency->bar();
}
};
Also (now this just got on my mind now), is it possible to do something like this. Using annotations, declaring a name and scope for the service:
/**
* @Service("someService")
* @Scope("session / request / ..")
*/
class foo {
/**
* @Inject \ABC\XYZ\Dependency
*/
private $dependency;
public function abc(){
$dependency->bar();
}
};
Autowiring will be available as of Symfony 2.8: http://symfony.com/blog/new-in-symfony-2-8-service-auto-wiring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With