Commit 35aa9a48 authored by romanb's avatar romanb

[2.0] Adding missing event classes and some AnnotationDriver refactorings.

parent 7a79785d
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL;
/**
* Container for all DBAL events.
*
* This class cannot be instantiated.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
final class Events
{
private function __construct() {}
const preExec = 'preExec';
const postExec = 'postExec';
const preExecute = 'preExecute';
const postExecute = 'postExecute';
}
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
namespace Doctrine\ORM; namespace Doctrine\ORM;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
/** /**
* Configuration container for all configuration options of Doctrine. * Configuration container for all configuration options of Doctrine.
* It combines all configuration options from DBAL & ORM. * It combines all configuration options from DBAL & ORM.
...@@ -44,16 +42,21 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -44,16 +42,21 @@ class Configuration extends \Doctrine\DBAL\Configuration
'resultCacheImpl' => null, 'resultCacheImpl' => null,
'queryCacheImpl' => null, 'queryCacheImpl' => null,
'metadataCacheImpl' => null, 'metadataCacheImpl' => null,
'metadataDriverImpl' => new AnnotationDriver(), 'metadataDriverImpl' => null,
'dqlClassAliasMap' => array(),
'cacheDir' => null, 'cacheDir' => null,
'allowPartialObjects' => true, 'allowPartialObjects' => true,
'useCExtension' => false 'useCExtension' => false
)); ));
//TODO: Move this to client code to avoid unnecessary work when a different metadata
// driver is used.
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache);
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$this->_attributes['metadataDriverImpl'] = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
} }
/** /**
* Gets a boolean flag that specifies whether partial objects are allowed. * Gets a boolean flag that indicates whether partial objects are allowed.
* *
* If partial objects are allowed, Doctrine will never use proxies or lazy loading * If partial objects are allowed, Doctrine will never use proxies or lazy loading
* and you always only get what you explicitly query for. * and you always only get what you explicitly query for.
...@@ -98,16 +101,6 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -98,16 +101,6 @@ class Configuration extends \Doctrine\DBAL\Configuration
return $this->_attributes['cacheDir']; return $this->_attributes['cacheDir'];
} }
public function getDqlClassAliasMap()
{
return $this->_attributes['dqlClassAliasMap'];
}
public function setDqlClassAliasMap(array $map)
{
$this->_attributes['dqlClassAliasMap'] = $map;
}
/** /**
* Sets the cache driver implementation that is used for metadata caching. * Sets the cache driver implementation that is used for metadata caching.
* *
...@@ -187,12 +180,24 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -187,12 +180,24 @@ class Configuration extends \Doctrine\DBAL\Configuration
{ {
$this->_attributes['metadataCacheImpl'] = $cacheImpl; $this->_attributes['metadataCacheImpl'] = $cacheImpl;
} }
/**
* Gets a boolean flag that indicates whether Doctrine should make use of the
* C extension.
*
* @return boolean TRUE if Doctrine is configured to use the C extension, FALSE otherwise.
*/
public function getUseCExtension() public function getUseCExtension()
{ {
return $this->_attributes['useCExtension']; return $this->_attributes['useCExtension'];
} }
/**
* Sets a boolean flag that indicates whether Doctrine should make use of the
* C extension.
*
* @param boolean $boolean Whether to make use of the C extension or not.
*/
public function setUseCExtension($boolean) public function setUseCExtension($boolean)
{ {
$this->_attributes['useCExtension'] = $boolean; $this->_attributes['useCExtension'] = $boolean;
......
...@@ -561,7 +561,9 @@ class EntityManager ...@@ -561,7 +561,9 @@ class EntityManager
} }
/** /**
* Gets the proxy generated used by the EntityManager to create entity proxies. * Gets the proxy generator used by the EntityManager to create entity proxies.
*
* @return DynamicProxyGenerator
*/ */
public function getProxyGenerator() public function getProxyGenerator()
{ {
......
...@@ -32,29 +32,4 @@ namespace Doctrine\ORM; ...@@ -32,29 +32,4 @@ namespace Doctrine\ORM;
* @version $Revision$ * @version $Revision$
*/ */
class EntityManagerException extends \Doctrine\Common\DoctrineException class EntityManagerException extends \Doctrine\Common\DoctrineException
{ {}
public static function invalidFlushMode() \ No newline at end of file
{
return new self("Invalid flush mode.");
}
public static function noEntityManagerAvailable()
{
return new self("No EntityManager available.");
}
public static function entityAlreadyBound($entityName)
{
return new self("The entity '$entityName' is already bound.");
}
public static function noManagerWithName($emName)
{
return new self("EntityManager named '$emName' not found.");
}
public static function unknownAttribute($name)
{
return new self("Unknown EntityManager attribute '$name'.");
}
}
\ No newline at end of file
<?php
namespace Doctrine\ORM\Event;
use Doctrine\Common\EventArgs;
/**
* Class that holds event arguments for a preInsert event.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class PreInsertEventArgs extends EventArgs
{
private $_entity;
private $_entityChangeSet;
public function __construct($entity, array $changeSet)
{
$this->_entity = $entity;
$this->_entityChangeSet = $changeSet;
}
public function getEntity()
{
return $this->_entity;
}
public function getEntityChangeSet()
{
return $this->_entityChangeSet;
}
/*public function getEntityId()
{
}*/
}
<?php
namespace Doctrine\ORM\Event;
use Doctrine\Common\EventArgs;
/**
* Class that holds event arguments for a preUpdate event.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class PreUpdateEventArgs extends EventArgs
{
private $_entity;
private $_entityChangeSet;
public function __construct($entity, array $changeSet)
{
$this->_entity = $entity;
$this->_entityChangeSet = $changeSet;
}
public function getEntity()
{
return $this->_entity;
}
public function getEntityChangeSet()
{
return $this->_entityState;
}
}
...@@ -37,23 +37,35 @@ require __DIR__ . '/DoctrineAnnotations.php'; ...@@ -37,23 +37,35 @@ require __DIR__ . '/DoctrineAnnotations.php';
*/ */
class AnnotationDriver implements Driver class AnnotationDriver implements Driver
{ {
/** The AnnotationReader. */
private $_reader;
/**
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
* docblock annotations.
*
* @param AnnotationReader $reader The AnnotationReader to use.
*/
public function __construct(AnnotationReader $reader)
{
$this->_reader = $reader;
}
/** /**
* Loads the metadata for the specified class into the provided container. * {@inheritdoc}
*/ */
public function loadMetadataForClass($className, ClassMetadata $metadata) public function loadMetadataForClass($className, ClassMetadata $metadata)
{ {
$reader = new AnnotationReader(new ArrayCache);
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$class = $metadata->getReflectionClass(); $class = $metadata->getReflectionClass();
// Evaluate DoctrineEntity annotation // Evaluate DoctrineEntity annotation
if (($entityAnnot = $reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\Entity')) === null) { if (($entityAnnot = $this->_reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\Entity')) === null) {
throw DoctrineException::updateMe("$className is no entity."); throw DoctrineException::updateMe("$className is no entity.");
} }
$metadata->setCustomRepositoryClass($entityAnnot->repositoryClass); $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
// Evaluate DoctrineTable annotation // Evaluate DoctrineTable annotation
if ($tableAnnot = $reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\Table')) { if ($tableAnnot = $this->_reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\Table')) {
$metadata->setPrimaryTable(array( $metadata->setPrimaryTable(array(
'name' => $tableAnnot->name, 'name' => $tableAnnot->name,
'schema' => $tableAnnot->schema 'schema' => $tableAnnot->schema
...@@ -61,12 +73,12 @@ class AnnotationDriver implements Driver ...@@ -61,12 +73,12 @@ class AnnotationDriver implements Driver
} }
// Evaluate InheritanceType annotation // Evaluate InheritanceType annotation
if ($inheritanceTypeAnnot = $reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\InheritanceType')) { if ($inheritanceTypeAnnot = $this->_reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\InheritanceType')) {
$metadata->setInheritanceType(constant('\Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value)); $metadata->setInheritanceType(constant('\Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
} }
// Evaluate DiscriminatorColumn annotation // Evaluate DiscriminatorColumn annotation
if ($discrColumnAnnot = $reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\DiscriminatorColumn')) { if ($discrColumnAnnot = $this->_reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\DiscriminatorColumn')) {
$metadata->setDiscriminatorColumn(array( $metadata->setDiscriminatorColumn(array(
'name' => $discrColumnAnnot->name, 'name' => $discrColumnAnnot->name,
'type' => $discrColumnAnnot->type, 'type' => $discrColumnAnnot->type,
...@@ -75,17 +87,17 @@ class AnnotationDriver implements Driver ...@@ -75,17 +87,17 @@ class AnnotationDriver implements Driver
} }
// Evaluate DiscriminatorValue annotation // Evaluate DiscriminatorValue annotation
if ($discrValueAnnot = $reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\DiscriminatorValue')) { if ($discrValueAnnot = $this->_reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\DiscriminatorValue')) {
$metadata->setDiscriminatorValue($discrValueAnnot->value); $metadata->setDiscriminatorValue($discrValueAnnot->value);
} }
// Evaluate DoctrineSubClasses annotation // Evaluate DoctrineSubClasses annotation
if ($subClassesAnnot = $reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\SubClasses')) { if ($subClassesAnnot = $this->_reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\SubClasses')) {
$metadata->setSubclasses($subClassesAnnot->value); $metadata->setSubclasses($subClassesAnnot->value);
} }
// Evaluate DoctrineChangeTrackingPolicy annotation // Evaluate DoctrineChangeTrackingPolicy annotation
if ($changeTrackingAnnot = $reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\ChangeTrackingPolicy')) { if ($changeTrackingAnnot = $this->_reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\ChangeTrackingPolicy')) {
$metadata->setChangeTrackingPolicy($changeTrackingAnnot->value); $metadata->setChangeTrackingPolicy($changeTrackingAnnot->value);
} }
...@@ -100,7 +112,7 @@ class AnnotationDriver implements Driver ...@@ -100,7 +112,7 @@ class AnnotationDriver implements Driver
// Check for JoinColummn/JoinColumns annotations // Check for JoinColummn/JoinColumns annotations
$joinColumns = array(); $joinColumns = array();
if ($joinColumnAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) { if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) {
$joinColumns[] = array( $joinColumns[] = array(
'name' => $joinColumnAnnot->name, 'name' => $joinColumnAnnot->name,
'referencedColumnName' => $joinColumnAnnot->referencedColumnName, 'referencedColumnName' => $joinColumnAnnot->referencedColumnName,
...@@ -109,7 +121,7 @@ class AnnotationDriver implements Driver ...@@ -109,7 +121,7 @@ class AnnotationDriver implements Driver
'onDelete' => $joinColumnAnnot->onDelete, 'onDelete' => $joinColumnAnnot->onDelete,
'onUpdate' => $joinColumnAnnot->onUpdate 'onUpdate' => $joinColumnAnnot->onUpdate
); );
} else if ($joinColumnsAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumns')) { } else if ($joinColumnsAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumns')) {
foreach ($joinColumnsAnnot->value as $joinColumn) { foreach ($joinColumnsAnnot->value as $joinColumn) {
//$joinColumns = $joinColumnsAnnot->value; //$joinColumns = $joinColumnsAnnot->value;
$joinColumns[] = array( $joinColumns[] = array(
...@@ -125,7 +137,7 @@ class AnnotationDriver implements Driver ...@@ -125,7 +137,7 @@ class AnnotationDriver implements Driver
// Field can only be annotated with one of: // Field can only be annotated with one of:
// @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
if ($columnAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) { if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) {
if ($columnAnnot->type == null) { if ($columnAnnot->type == null) {
throw DoctrineException::updateMe("Missing type on property " . $property->getName()); throw DoctrineException::updateMe("Missing type on property " . $property->getName());
} }
...@@ -135,49 +147,47 @@ class AnnotationDriver implements Driver ...@@ -135,49 +147,47 @@ class AnnotationDriver implements Driver
if (isset($columnAnnot->name)) { if (isset($columnAnnot->name)) {
$mapping['columnName'] = $columnAnnot->name; $mapping['columnName'] = $columnAnnot->name;
} }
if ($idAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
$mapping['id'] = true; $mapping['id'] = true;
} }
if ($generatedValueAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\GeneratedValue')) { if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\GeneratedValue')) {
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy)); $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
} }
$metadata->mapField($mapping); $metadata->mapField($mapping);
// Check for SequenceGenerator/TableGenerator definition // Check for SequenceGenerator/TableGenerator definition
if ($seqGeneratorAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\SequenceGenerator')) { if ($seqGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\SequenceGenerator')) {
$metadata->setSequenceGeneratorDefinition(array( $metadata->setSequenceGeneratorDefinition(array(
'sequenceName' => $seqGeneratorAnnot->sequenceName, 'sequenceName' => $seqGeneratorAnnot->sequenceName,
'allocationSize' => $seqGeneratorAnnot->allocationSize, 'allocationSize' => $seqGeneratorAnnot->allocationSize,
'initialValue' => $seqGeneratorAnnot->initialValue 'initialValue' => $seqGeneratorAnnot->initialValue
)); ));
} else if ($tblGeneratorAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) { } else if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) {
throw new DoctrineException("DoctrineTableGenerator not yet implemented."); throw new DoctrineException("DoctrineTableGenerator not yet implemented.");
} }
} else if ($oneToOneAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) { } else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) {
$mapping['targetEntity'] = $oneToOneAnnot->targetEntity; $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
$mapping['joinColumns'] = $joinColumns; $mapping['joinColumns'] = $joinColumns;
$mapping['mappedBy'] = $oneToOneAnnot->mappedBy; $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
$mapping['cascade'] = $oneToOneAnnot->cascade; $mapping['cascade'] = $oneToOneAnnot->cascade;
$metadata->mapOneToOne($mapping); $metadata->mapOneToOne($mapping);
} else if ($oneToManyAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToMany')) { } else if ($oneToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToMany')) {
$mapping['mappedBy'] = $oneToManyAnnot->mappedBy; $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
$mapping['targetEntity'] = $oneToManyAnnot->targetEntity; $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
$mapping['cascade'] = $oneToManyAnnot->cascade; $mapping['cascade'] = $oneToManyAnnot->cascade;
$metadata->mapOneToMany($mapping); $metadata->mapOneToMany($mapping);
} else if ($manyToOneAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToOne')) { } else if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToOne')) {
$mapping['joinColumns'] = $joinColumns; $mapping['joinColumns'] = $joinColumns;
$mapping['cascade'] = $manyToOneAnnot->cascade; $mapping['cascade'] = $manyToOneAnnot->cascade;
$mapping['targetEntity'] = $manyToOneAnnot->targetEntity; $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
$metadata->mapManyToOne($mapping); $metadata->mapManyToOne($mapping);
} else if ($manyToManyAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) { } else if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) {
$joinTable = array(); $joinTable = array();
if ($joinTableAnnot = $reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) { if ($joinTableAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) {
$joinTable = array( $joinTable = array(
'name' => $joinTableAnnot->name, 'name' => $joinTableAnnot->name,
'schema' => $joinTableAnnot->schema, 'schema' => $joinTableAnnot->schema
//'joinColumns' => $joinTableAnnot->joinColumns,
//'inverseJoinColumns' => $joinTableAnnot->inverseJoinColumns
); );
foreach ($joinTableAnnot->joinColumns as $joinColumn) { foreach ($joinTableAnnot->joinColumns as $joinColumn) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment