1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

php static driver

This commit is contained in:
Fabio B. Silva 2012-08-07 21:31:01 -03:00 committed by fabio.silva
parent f0b04375de
commit 415c2a95f2
5 changed files with 89 additions and 6 deletions

View file

@ -129,4 +129,44 @@ abstract class CompanyContract
} }
abstract public function calculatePrice(); abstract public function calculatePrice();
static public function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
{
$metadata->setInheritanceType(\Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_JOINED);
$metadata->setTableName( 'company_contracts');
$metadata->setDiscriminatorColumn(array(
'name' => 'discr',
'type' => 'string',
));
$metadata->mapField(array(
'id' => true,
'name' => 'id',
'fieldName' => 'id',
));
$metadata->mapField(array(
'type' => 'boolean',
'name' => 'completed',
'fieldName' => 'completed',
));
$metadata->setDiscriminatorMap(array(
"fix" => "CompanyFixContract",
"flexible" => "CompanyFlexContract",
"flexultra" => "CompanyFlexUltraContract"
));
$metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'ContractSubscriber', 'postPersistHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'ContractSubscriber', 'prePersistHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::postUpdate, 'ContractSubscriber', 'postUpdateHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::preUpdate, 'ContractSubscriber', 'preUpdateHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::postRemove, 'ContractSubscriber', 'postRemoveHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::preRemove, 'ContractSubscriber', 'preRemoveHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::preFlush, 'ContractSubscriber', 'preFlushHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'ContractSubscriber', 'postLoadHandler');
}
} }

View file

@ -27,4 +27,13 @@ class CompanyFixContract extends CompanyContract
{ {
$this->fixPrice = $fixPrice; $this->fixPrice = $fixPrice;
} }
static public function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
{
$metadata->mapField(array(
'type' => 'integer',
'name' => 'fixPrice',
'fieldName' => 'fixPrice',
));
}
} }

View file

@ -107,4 +107,19 @@ class CompanyFlexContract extends CompanyContract
{ {
$this->managers->removeElement($manager); $this->managers->removeElement($manager);
} }
static public function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
{
$metadata->mapField(array(
'type' => 'integer',
'name' => 'hoursWorked',
'fieldName' => 'hoursWorked',
));
$metadata->mapField(array(
'type' => 'integer',
'name' => 'pricePerHour',
'fieldName' => 'pricePerHour',
));
}
} }

View file

@ -28,4 +28,27 @@ class CompanyFlexUltraContract extends CompanyFlexContract
{ {
$this->maxPrice = $maxPrice; $this->maxPrice = $maxPrice;
} }
static public function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
{
$metadata->mapField(array(
'type' => 'integer',
'name' => 'maxPrice',
'fieldName' => 'maxPrice',
));
$metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'ContractSubscriber', 'postPersistHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'ContractSubscriber', 'prePersistHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::postUpdate, 'ContractSubscriber', 'postUpdateHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::preUpdate, 'ContractSubscriber', 'preUpdateHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::postRemove, 'ContractSubscriber', 'postRemoveHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::preRemove, 'ContractSubscriber', 'preRemoveHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::preFlush, 'ContractSubscriber', 'preFlushHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'ContractSubscriber', 'postLoadHandler');
$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'FlexUltraContractSubscriber', 'prePersistHandler1');
$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'FlexUltraContractSubscriber', 'prePersistHandler2');
}
} }

View file

@ -758,9 +758,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/ */
public function testEntityListeners() public function testEntityListeners()
{ {
if ( ! ($this instanceof AnnotationDriverTest) if ($this instanceof PHPMappingDriverTest) {
&& ! ($this instanceof XmlMappingDriverTest)
&& ! ($this instanceof YamlMappingDriverTest)) {
$this->markTestIncomplete(); $this->markTestIncomplete();
} }
@ -818,9 +816,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/ */
public function testCallEntityListeners() public function testCallEntityListeners()
{ {
if ( ! ($this instanceof AnnotationDriverTest) if ($this instanceof PHPMappingDriverTest) {
&& ! ($this instanceof XmlMappingDriverTest)
&& ! ($this instanceof YamlMappingDriverTest)) {
$this->markTestIncomplete(); $this->markTestIncomplete();
} }