I have three bundles:
- MainBundle - holds entities and all generic functionality
- BundleA & BundleB which will extend Entities in MainBundle and each will also implement interface in that bundle.
With this solution i want to keep MainBundle unaware on other bundles and only have default functionality that Entity should have in it. And other two bundles are aware of MainBundle (but unaware of each other) and have some extend functionality.
Example entity in MainBundle:
<?php
namespace Random\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class Person
{
protected $id;
protected $first_name;
protected $last_name;
public function getId()
{
return $this->id;
}
public function getFirstName()
{
return $this->first_name;;
}
public function getLastName()
{
return $this->last_name;;
}
}
Example class in BundleA extending Entity in MainBundle:
<?php
namespace Random\BundleA\Model;
use Random\MainBundle\Entity\Person as BasePerson;
use Random\BundleA\Model\PersonInterface;
class Person extends BasePerson implements PersonInterface
{
public function foo()
{
$data = array(
'object_id' = $this->getId(),
'name' = $this->getFirstName(),
'extra' = 'foo'
);
return json_encode($data);
}
}
Example class in BundleB extending Entity in MainBundle:
<?php
namespace Random\BundleB\Model;
use Random\MainBundle\Entity\Person as BasePerson;
use Random\BundleB\Model\PersonInterface;
class Person extends BasePerson implements PersonInterface
{
public function bar()
{
$data = array(
'person_id' = $this->getId(),
'last_name' = $this->getLastName(),
'random' = 'bar'
);
return $data;
}
}
The problem with this setup is that Symfony/Doctrine expects Random\MainBundle\Entity\Person to be "mapped superclass" which i want it not to be.
EDIT:
In Doctrine1 i was able to extend any Doctrine_Record without having to define simple, concrete or column aggregation inheritance:
<?php
class Person extends BasePerson
{
// some functionality
}
class TestPerson extends Person
{
// additional functionality
}
And in controller i was able to simply:
<?php
$person = new TestPerson();
$person->save();
and TestPerson (which was actually Person) was saved into database (which i was later able to access using PersonTable).
Any ideas?