Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5987789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:51:57+00:00 2026-05-22T22:51:57+00:00

I’m looking for an appropriate way to reduce coupling in a messaging bundle I’m

  • 0

I’m looking for an appropriate way to reduce coupling in a messaging bundle I’m writing for the Symfony2 framework, so that I can easily use it between applications.

Each instance of the Message entity should have a sender and a recipient, instanceof Symfony\Component\Security\Core\User\UserInterface, which I can require just fine in the setters for the properties. However, in setting up the ORM relationships, it seems that I have to specifically set a targetEntity (Foo\BarBundle\Entity\User, for example), which means that all further uses of the Message entity in different applications will either require a code change, or shoehorn them into using a User entity, which doesn’t seem to me to be in a messaging bundle’s scope to require.

Any suggestions/best practices on how I can reduce coupling in this instance?

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:51:58+00:00Added an answer on May 22, 2026 at 10:51 pm

    The solution I finally settled on was to create a MessengerIdentity, stored in the database, that takes an object and stores its class name and identifier. Then I used a LifecycleEvent to load a reference to the entity stored in MessengerIdentity, so that something like $messenger->getSender()->getUsername is still possible.

    You can see my implementation on github (in particular, the entities and the Doctrine event listener)… you can also see the discussion from the doctrine2 usergroup here.

    EDIT: After further deliberation, I decided that I didn’t like the implementation I talk about above (for one thing, I was essentially copy-pasting the code into other projects, which felt very cluttered and in violation of DRY), and so I refactored my code so that the Message entity is an abstract mapped superclass, with abstract methods that the business logic will need, referencing the sender and recipient.

    It’s now up to the end developer to create the final implementation of the Message entity, and the base class doesn’t even touch the implementations for sender and recipient, which achieved my desired result of reducing dependence of the bundle on a particular user class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.