Add annotation support in traits
It will allow to have helpers such as
trait EntityManagerTrait {
/** @Inject("doctrine.orm.entity_manager") */
public $em;
public function repo($entity) {
return $this->em->getRepository('AcmeBundle:' . $entity);
}
}
that can be use in any service
/** @Service */
class MyService {
use EntityManagerTrait;
public function myMethod() {
$this->repo('Post');
}
}
I could make it work by changing the regexp getting the name of the class in https://github.com/schmittjoh/JMSDiExtraBundle/blob/master/DependencyInjection/Compiler/AnnotationConfigurationPass.php#L114 from
'/\bclass\s+([^\s]+)\s+(?:extends|implements|{)/s'
to
'/\b(?:class|trait)\s+([^\s]+)\s+(?:extends|implements|{)/s'
+1
Are there any issues to @qpleple's suggested improvement that you see, @schmittjoh? It seems like a rather easy addition, but such simplistic additions tend to be full of unintended consequences in my experience. I'm not familiar enough with how your bundle works, but I desperately need this functionality. I'm going to delve into it myself, but it would be great to hear your take on it.
just use this style: http://jmsyst.com/bundles/JMSDiExtraBundle/master/doctrine
@skydiablo I don't see how that has anything at all to do with traits.
me too :S just ignore that ;)
Is there any chance that this makes it into the bundle? I've been running a patched version for ~6 months with no issue at this point. I can't find a reason not to allow traits.
Is there a pull request for this?
I didn't realize that qpleple didn't create a PR. I'll submit one after work.