Thanks, I had considered using a mapped superclass, but it still doesn't seem to be within the scope of a messenger bundle to require the application's user entity to extend a specific class. Is there no way dynamically set the entity type of a OneToMany or ManyToMany relationship, via configuration or something?
On May 23, 4:40 pm, Jesse Greathosuse <jesse.greatho...@gmail.com> wrote: > I've never had any success with extending entities because you always > end up with a class that cant be used after you extend the entity. I > see a lot of people using "Base" entities which is essentially the > same thing as a model which an entity extends. > > Create a mapped super class which inherits your user model. Then > create the entity to extend that mapped super class. In the mapped > super class create mapping between your entity and user model. > > You don't need the oneb ut it's nice to have a mapping layer in > between them in case the apps use different variable names. > > //Models/User.php > namespace Models; > > /** @MappedSuperclass */ > > class User > { > > protected $username; > protected $userid; > protected $groups; > > public function __call($method, $args) > { > if (strpos($method, 'get') === 0) { > return $this->get(substr($method, 3)); > } else if (strpos($method, 'set') === 0) { > $this->set(substr($method, 3), $args[0]); > } else { > throw new \Exception('Method '.$method.' not found in > class: ' . get_class($this)); > } > } > > public function get($name) { > return $this->{strtolower($name)}; > } > > public function set($name, $value) > { > $this->{strtolower($name)} = $value; > } > > } > > //Entities/User.php > namespace Entities; > /** > * User > * > * @Table(name="user") > * @Entity > */ > class User extends \Models\User > { > > public function __construct() > { > //parent::__construct doesn't exist by default > //it only exists if it's explicitly defined > if (is_callable('parent::__construct')) { > parent::__construct(); > } > > //set up default collections so it doesn't break on empty > instantiation > $this->groups = new \Doctrine\Common\Collections > \ArrayCollection(); > } > > /** > * @var integer $id > * > * @Column(name="id", type="integer", nullable=true) > * @Id > * @GeneratedValue(strategy="IDENTITY") > */ > protected $id; > > /** > * @var string $name > * > * @Column(name="name", type="string", length=16, nullable=false) > */ > protected $name; > > } > > On May 23, 5:06 pm, Problematic <djsto...@gmail.com> wrote: > > > > > > > > > I'm looking for an appropriate way to reduce coupling in a messaging bundle > > I'm writing, 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? -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en