Decrease traction in objects

I am looking for a suitable way to reduce communication in the message set that I am writing for the Symfony2 framework, so that I can easily use it between applications.

Each instance of the message object must have a sender and a receiver instanceof Symfony\Component\Security\Core\User\UserInterface , which may be required only in the settings for the properties. However, when setting up the ORM relationship, it seems that I should specifically set targetEntity (for example, t21>), which means that all further applications of the Message object in different applications will require either code changes or shoehorn their use of a custom object, which, it seems to me, not included in the message batch area required.

Any suggestions / recommendations for reducing communication in this case?

EDIT: I tried setting a global parameter with an extension and using it in the annotation, something like @ORM\ManyToOne(targetEntity="%my.entity%") , but it seems that the annotation parser is not converting the parameters because the string was interpreted like a literal, which, of course, failed.

+7
source share
2 answers

Finally, I decided to create a MessengerIdentity stored in a database that takes an object and stores its name and class identifier. Then I used LifecycleEvent to load a reference to the object stored in the MessengerIdentity, so something like $messenger->getSender()->getUsername .

You can see my implementation on github (specifically, Doctrine objects and event listener ) ... you can also see a discussion from the doctrine2 group here .

EDIT: After further discussion, I decided that I did not like the implementation that I am talking about above (firstly, I essentially copied the code to other projects, which is very cluttered and with DRY violation), and therefore I reorganized my code so so that the Message object is an abstract superclass with abstract methods that business logic needs, referring to the sender and receiver.

Now the developer must create the final implementation of the Message object, and the base class does not even concern the implementations for the sender and receiver, which allowed achieving the desired result of reducing the dependence of the package on a specific user class.

+4
source

You can create a Model object with all the business logic, and then create an Entity that extends the model but adds manager entity code and doctrine annotations to it. This is how the FOSUserBundle works.

+1
source

All Articles