Created
June 6, 2012 10:41
-
-
Save merk/2881235 to your computer and use it in GitHub Desktop.
ResolveTargetEntityListener examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .... | |
# app/config/config.yml | |
doctrine: | |
# .... | |
orm: | |
# .... | |
resolve_target_entities: | |
Acme\InvoiceBundle\Model\InvoiceSubjectInterface: Acme\AppBundle\Entity\Customer | |
# .... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/Acme/AppBundle/Entity/Customer.php | |
namespace Acme\AppBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Acme\CustomerBundle\Entity\Customer as BaseCustomer; | |
use Acme\InvoiceBundle\Model\InvoiceSubjectInterface; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="customer") | |
*/ | |
class Customer extends BaseCustomer implements InvoiceSubjectInterface | |
{ | |
// In our example, any methods defined in the InvoiceSubjectInterface | |
// are already implemented in the BaseCustomer | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/Acme/InvoiceBundle/Entity/Invoice.php | |
namespace Acme\InvoiceBundle\Entity; | |
use Doctrine\ORM\Mapping AS ORM; | |
use Acme\InvoiceBundle\Model\InvoiceSubjectInterface; | |
/** | |
* Represents an Invoice. | |
* | |
* @ORM\Entity | |
* @ORM\Table(name="invoice") | |
*/ | |
class Invoice | |
{ | |
/** | |
* @ORM\ManyToOne(targetEntity="Acme\InvoiceBundle\Model\InvoiceSubjectInterface") | |
* @var InvoiceSubjectInterface | |
*/ | |
protected $subject; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/Acme/InvoiceBundle/Model/InvoiceSubjectInterface.php | |
namespace Acme\InvoiceBundle\Model; | |
/** | |
* An interface that the invoice Subject object should implement. | |
* In most circumstances, only a single object should implement | |
* this interface as the ResolveTargetEntityListener can only | |
* change the target to a single object. | |
* | |
* @author Tim Nagel <[email protected]> | |
*/ | |
interface InvoiceSubjectInterface | |
{ | |
// List any additional methods that your InvoiceBundle | |
// will need to access on the subject so that you can | |
// be sure that you have access to those methods. | |
/** | |
* @return string | |
*/ | |
public function getName(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment