JMSDiExtraBundle icon indicating copy to clipboard operation
JMSDiExtraBundle copied to clipboard

Add annotation support in traits

Open qpleple opened this issue 12 years ago • 7 comments

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'

qpleple avatar Jul 11 '13 13:07 qpleple

+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.

jmcclell avatar Aug 10 '13 08:08 jmcclell

just use this style: http://jmsyst.com/bundles/JMSDiExtraBundle/master/doctrine

skydiablo avatar Aug 18 '13 16:08 skydiablo

@skydiablo I don't see how that has anything at all to do with traits.

jmcclell avatar Aug 30 '13 18:08 jmcclell

me too :S just ignore that ;)

skydiablo avatar Aug 30 '13 18:08 skydiablo

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.

jmcclell avatar Feb 27 '14 16:02 jmcclell

Is there a pull request for this?

schmittjoh avatar Feb 27 '14 16:02 schmittjoh

I didn't realize that qpleple didn't create a PR. I'll submit one after work.

jmcclell avatar Feb 27 '14 22:02 jmcclell