forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2.0] Placing loadClassMetadata() event so users can manipulate class…
… meta data through events
- Loading branch information
jwage
committed
Jul 15, 2009
1 parent
6c1690d
commit c4e330e
Showing
9 changed files
with
115 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Doctrine\ORM\Event; | ||
|
||
use Doctrine\Common\EventArgs; | ||
|
||
/** | ||
* Class that holds event arguments for a loadMetadata event. | ||
* | ||
* @author Jonathan H. Wage <[email protected]> | ||
* @since 2.0 | ||
*/ | ||
class LoadClassMetadataEventArgs extends EventArgs | ||
{ | ||
private $_classMetadata; | ||
|
||
public function __construct(\Doctrine\ORM\Mapping\ClassMetadata $classMetadata) | ||
{ | ||
$this->_classMetadata = $classMetadata; | ||
} | ||
|
||
public function getClassMetadata() | ||
{ | ||
return $this->_classMetadata; | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,9 @@ public function isTransient($className) | |
{ | ||
return false; | ||
} | ||
|
||
public function preload() | ||
{ | ||
return array(); | ||
} | ||
} |
This file contains 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
This file contains 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
51 changes: 51 additions & 0 deletions
51
tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\ORM\Mapping; | ||
|
||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Doctrine\ORM\Events; | ||
|
||
require_once __DIR__ . '/../../TestInit.php'; | ||
|
||
class ClassMetadataLoadEventTest extends \Doctrine\Tests\OrmTestCase | ||
{ | ||
public function testEvent() | ||
{ | ||
$em = $this->_getTestEntityManager(); | ||
$metadataFactory = $em->getMetadataFactory(); | ||
$evm = $em->getEventManager(); | ||
$evm->addEventListener(Events::loadClassMetadata, $this); | ||
$classMetadata = $metadataFactory->getMetadataFor('Doctrine\Tests\ORM\Mapping\LoadEventTestEntity'); | ||
$this->assertTrue($classMetadata->hasField('about')); | ||
} | ||
|
||
public function loadClassMetadata(\Doctrine\ORM\Event\LoadClassMetadataEventArgs $eventArgs) | ||
{ | ||
$classMetadata = $eventArgs->getClassMetadata(); | ||
$field = array( | ||
'fieldName' => 'about', | ||
'type' => 'string', | ||
'length' => 255 | ||
); | ||
$classMetadata->mapField($field); | ||
} | ||
} | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="load_event_test_entity") | ||
*/ | ||
class LoadEventTestEntity | ||
{ | ||
/** | ||
* @Id @Column(type="integer") | ||
* @GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
/** | ||
* @Column(type="string", length=255) | ||
*/ | ||
private $name; | ||
|
||
private $about; | ||
} |
This file contains 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