Merge pull request #314 from Ocramius/dcom-metadata-drivers-reuse
Doctrine\Common metadata drivers reuse
This commit is contained in:
commit
6ba205f561
@ -30,3 +30,11 @@ Also, related functions were affected:
|
|||||||
|
|
||||||
Internal changes were made to DQL and SQL generation. If you have implemented your own TreeWalker,
|
Internal changes were made to DQL and SQL generation. If you have implemented your own TreeWalker,
|
||||||
you probably need to update it. The method walkJoinVariableDeclaration is now named walkJoin.
|
you probably need to update it. The method walkJoinVariableDeclaration is now named walkJoin.
|
||||||
|
|
||||||
|
# Metadata Drivers
|
||||||
|
|
||||||
|
Metadata drivers have been rewritten to reuse code from Doctrine\Common. Anyone who is using the
|
||||||
|
`Doctrine\ORM\Mapping\Driver\Driver` interface should instead refer to
|
||||||
|
`Doctrine\Common\Persistence\Mapping\Driver\MappingDriver`. Same applies to
|
||||||
|
`Doctrine\ORM\Mapping\Driver\AbstractFileDriver`: you should now refer to
|
||||||
|
`Doctrine\Common\Persistence\Mapping\Driver\FileDriver`.
|
@ -23,7 +23,7 @@ use Doctrine\Common\Cache\Cache,
|
|||||||
Doctrine\Common\Cache\ArrayCache,
|
Doctrine\Common\Cache\ArrayCache,
|
||||||
Doctrine\Common\Annotations\AnnotationRegistry,
|
Doctrine\Common\Annotations\AnnotationRegistry,
|
||||||
Doctrine\Common\Annotations\AnnotationReader,
|
Doctrine\Common\Annotations\AnnotationReader,
|
||||||
Doctrine\ORM\Mapping\Driver\Driver,
|
Doctrine\Common\Persistence\Mapping\Driver\MappingDriver,
|
||||||
Doctrine\ORM\Mapping\Driver\AnnotationDriver,
|
Doctrine\ORM\Mapping\Driver\AnnotationDriver,
|
||||||
Doctrine\ORM\Mapping\QuoteStrategy,
|
Doctrine\ORM\Mapping\QuoteStrategy,
|
||||||
Doctrine\ORM\Mapping\DefaultQuoteStrategy,
|
Doctrine\ORM\Mapping\DefaultQuoteStrategy,
|
||||||
@ -114,11 +114,11 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
|||||||
/**
|
/**
|
||||||
* Sets the cache driver implementation that is used for metadata caching.
|
* Sets the cache driver implementation that is used for metadata caching.
|
||||||
*
|
*
|
||||||
* @param Driver $driverImpl
|
* @param MappingDriver $driverImpl
|
||||||
* @todo Force parameter to be a Closure to ensure lazy evaluation
|
* @todo Force parameter to be a Closure to ensure lazy evaluation
|
||||||
* (as soon as a metadata cache is in effect, the driver never needs to initialize).
|
* (as soon as a metadata cache is in effect, the driver never needs to initialize).
|
||||||
*/
|
*/
|
||||||
public function setMetadataDriverImpl(Driver $driverImpl)
|
public function setMetadataDriverImpl(MappingDriver $driverImpl)
|
||||||
{
|
{
|
||||||
$this->_attributes['metadataDriverImpl'] = $driverImpl;
|
$this->_attributes['metadataDriverImpl'] = $driverImpl;
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
|||||||
* Gets the cache driver implementation that is used for the mapping metadata.
|
* Gets the cache driver implementation that is used for the mapping metadata.
|
||||||
*
|
*
|
||||||
* @throws ORMException
|
* @throws ORMException
|
||||||
* @return Mapping\Driver\Driver
|
* @return MappingDriver
|
||||||
*/
|
*/
|
||||||
public function getMetadataDriverImpl()
|
public function getMetadataDriverImpl()
|
||||||
{
|
{
|
||||||
|
@ -19,25 +19,10 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping;
|
namespace Doctrine\ORM\Mapping;
|
||||||
|
|
||||||
use ReflectionClass, ReflectionProperty;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
|
* {@inheritDoc}
|
||||||
* of an entity and it's associations.
|
|
||||||
*
|
*
|
||||||
* Once populated, ClassMetadata instances are usually cached in a serialized form.
|
* @todo remove or rename ClassMetadataInfo to ClassMetadata
|
||||||
*
|
|
||||||
* <b>IMPORTANT NOTE:</b>
|
|
||||||
*
|
|
||||||
* The fields of this class are only public for 2 reasons:
|
|
||||||
* 1) To allow fast READ access.
|
|
||||||
* 2) To drastically reduce the size of a serialized instance (private/protected members
|
|
||||||
* get the whole class name, namespace inclusive, prepended to every property in
|
|
||||||
* the serialized representation).
|
|
||||||
*
|
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
|
||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
*/
|
||||||
class ClassMetadata extends ClassMetadataInfo
|
class ClassMetadata extends ClassMetadataInfo
|
||||||
{
|
{
|
||||||
|
@ -24,14 +24,15 @@ use ReflectionException,
|
|||||||
Doctrine\ORM\EntityManager,
|
Doctrine\ORM\EntityManager,
|
||||||
Doctrine\DBAL\Platforms,
|
Doctrine\DBAL\Platforms,
|
||||||
Doctrine\ORM\Events,
|
Doctrine\ORM\Events,
|
||||||
Doctrine\Common\Util\ClassUtils,
|
|
||||||
Doctrine\Common\Persistence\Mapping\RuntimeReflectionService,
|
|
||||||
Doctrine\Common\Persistence\Mapping\ReflectionService,
|
Doctrine\Common\Persistence\Mapping\ReflectionService,
|
||||||
Doctrine\Common\Persistence\Mapping\ClassMetadataFactory as ClassMetadataFactoryInterface;
|
Doctrine\Common\Persistence\Mapping\ClassMetadata as ClassMetadataInterface,
|
||||||
|
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory,
|
||||||
|
Doctrine\ORM\Id\IdentityGenerator,
|
||||||
|
Doctrine\ORM\Event\LoadClassMetadataEventArgs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
|
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
|
||||||
* metadata mapping informations of a class which describes how a class should be mapped
|
* metadata mapping information of a class which describes how a class should be mapped
|
||||||
* to a relational database.
|
* to a relational database.
|
||||||
*
|
*
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
@ -40,7 +41,7 @@ use ReflectionException,
|
|||||||
* @author Jonathan Wage <jonwage@gmail.com>
|
* @author Jonathan Wage <jonwage@gmail.com>
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
* @author Roman Borschel <roman@code-factory.org>
|
||||||
*/
|
*/
|
||||||
class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var EntityManager
|
* @var EntityManager
|
||||||
@ -48,12 +49,12 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
private $em;
|
private $em;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var AbstractPlatform
|
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||||
*/
|
*/
|
||||||
private $targetPlatform;
|
private $targetPlatform;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Doctrine\ORM\Mapping\Driver\Driver
|
* @var \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver
|
||||||
*/
|
*/
|
||||||
private $driver;
|
private $driver;
|
||||||
|
|
||||||
@ -63,27 +64,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
private $evm;
|
private $evm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Doctrine\Common\Cache\Cache
|
* @param EntityManager $em
|
||||||
*/
|
|
||||||
private $cacheDriver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $loadedMetadata = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $initialized = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ReflectionService
|
|
||||||
*/
|
|
||||||
private $reflectionService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param EntityManager $$em
|
|
||||||
*/
|
*/
|
||||||
public function setEntityManager(EntityManager $em)
|
public function setEntityManager(EntityManager $em)
|
||||||
{
|
{
|
||||||
@ -91,55 +72,9 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the cache driver used by the factory to cache ClassMetadata instances.
|
* {@inheritDoc}.
|
||||||
*
|
|
||||||
* @param \Doctrine\Common\Cache\Cache $cacheDriver
|
|
||||||
*/
|
*/
|
||||||
public function setCacheDriver($cacheDriver)
|
protected function initialize()
|
||||||
{
|
|
||||||
$this->cacheDriver = $cacheDriver;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the cache driver used by the factory to cache ClassMetadata instances.
|
|
||||||
*
|
|
||||||
* @return \Doctrine\Common\Cache\Cache
|
|
||||||
*/
|
|
||||||
public function getCacheDriver()
|
|
||||||
{
|
|
||||||
return $this->cacheDriver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLoadedMetadata()
|
|
||||||
{
|
|
||||||
return $this->loadedMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Forces the factory to load the metadata of all classes known to the underlying
|
|
||||||
* mapping driver.
|
|
||||||
*
|
|
||||||
* @return array The ClassMetadata instances of all mapped classes.
|
|
||||||
*/
|
|
||||||
public function getAllMetadata()
|
|
||||||
{
|
|
||||||
if ( ! $this->initialized) {
|
|
||||||
$this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
$metadata = array();
|
|
||||||
foreach ($this->driver->getAllClassNames() as $className) {
|
|
||||||
$metadata[] = $this->getMetadataFor($className);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lazy initialization of this stuff, especially the metadata driver,
|
|
||||||
* since these are not needed at all when a metadata cache is active.
|
|
||||||
*/
|
|
||||||
private function initialize()
|
|
||||||
{
|
{
|
||||||
$this->driver = $this->em->getConfiguration()->getMetadataDriverImpl();
|
$this->driver = $this->em->getConfiguration()->getMetadataDriverImpl();
|
||||||
$this->targetPlatform = $this->em->getConnection()->getDatabasePlatform();
|
$this->targetPlatform = $this->em->getConnection()->getDatabasePlatform();
|
||||||
@ -148,230 +83,99 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the class metadata descriptor for a class.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @param string $className The name of the class.
|
|
||||||
* @return \Doctrine\ORM\Mapping\ClassMetadata
|
|
||||||
*/
|
*/
|
||||||
public function getMetadataFor($className)
|
protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents)
|
||||||
{
|
{
|
||||||
if (isset($this->loadedMetadata[$className])) {
|
/* @var $class ClassMetadata */
|
||||||
return $this->loadedMetadata[$className];
|
/* @var $parent ClassMetadata */
|
||||||
}
|
if ($parent) {
|
||||||
|
$class->setInheritanceType($parent->inheritanceType);
|
||||||
|
$class->setDiscriminatorColumn($parent->discriminatorColumn);
|
||||||
|
$class->setIdGeneratorType($parent->generatorType);
|
||||||
|
$this->addInheritedFields($class, $parent);
|
||||||
|
$this->addInheritedRelations($class, $parent);
|
||||||
|
$class->setIdentifier($parent->identifier);
|
||||||
|
$class->setVersioned($parent->isVersioned);
|
||||||
|
$class->setVersionField($parent->versionField);
|
||||||
|
$class->setDiscriminatorMap($parent->discriminatorMap);
|
||||||
|
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
|
||||||
|
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
|
||||||
|
|
||||||
$realClassName = $className;
|
if ($parent->isMappedSuperclass) {
|
||||||
|
$class->setCustomRepositoryClass($parent->customRepositoryClassName);
|
||||||
// Check for namespace alias
|
|
||||||
if (strpos($className, ':') !== false) {
|
|
||||||
list($namespaceAlias, $simpleClassName) = explode(':', $className);
|
|
||||||
$realClassName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
|
|
||||||
} else {
|
|
||||||
$realClassName = ClassUtils::getRealClass($realClassName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->loadedMetadata[$realClassName])) {
|
|
||||||
// We do not have the alias name in the map, include it
|
|
||||||
$this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
|
|
||||||
return $this->loadedMetadata[$realClassName];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->cacheDriver) {
|
|
||||||
if (($cached = $this->cacheDriver->fetch("$realClassName\$CLASSMETADATA")) !== false) {
|
|
||||||
$this->wakeupReflection($cached, $this->getReflectionService());
|
|
||||||
$this->loadedMetadata[$realClassName] = $cached;
|
|
||||||
} else {
|
|
||||||
foreach ($this->loadMetadata($realClassName) as $loadedClassName) {
|
|
||||||
$this->cacheDriver->save(
|
|
||||||
"$loadedClassName\$CLASSMETADATA", $this->loadedMetadata[$loadedClassName], null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->loadMetadata($realClassName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($className != $realClassName) {
|
|
||||||
// We do not have the alias name in the map, include it
|
|
||||||
$this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->loadedMetadata[$className];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the factory has the metadata for a class loaded already.
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @return boolean TRUE if the metadata of the class in question is already loaded, FALSE otherwise.
|
|
||||||
*/
|
|
||||||
public function hasMetadataFor($className)
|
|
||||||
{
|
|
||||||
return isset($this->loadedMetadata[$className]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the metadata descriptor for a specific class.
|
|
||||||
*
|
|
||||||
* NOTE: This is only useful in very special cases, like when generating proxy classes.
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @param ClassMetadata $class
|
|
||||||
*/
|
|
||||||
public function setMetadataFor($className, $class)
|
|
||||||
{
|
|
||||||
$this->loadedMetadata[$className] = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get array of parent classes for the given entity class
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @return array $parentClasses
|
|
||||||
*/
|
|
||||||
protected function getParentClasses($name)
|
|
||||||
{
|
|
||||||
// Collect parent classes, ignoring transient (not-mapped) classes.
|
|
||||||
$parentClasses = array();
|
|
||||||
foreach (array_reverse($this->getReflectionService()->getParentClasses($name)) as $parentClass) {
|
|
||||||
if ( ! $this->driver->isTransient($parentClass)) {
|
|
||||||
$parentClasses[] = $parentClass;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $parentClasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Invoke driver
|
||||||
* Loads the metadata of the class in question and all it's ancestors whose metadata
|
try {
|
||||||
* is still not loaded.
|
$this->driver->loadMetadataForClass($class->getName(), $class);
|
||||||
*
|
} catch (ReflectionException $e) {
|
||||||
* @param string $name The name of the class for which the metadata should get loaded.
|
throw MappingException::reflectionFailure($class->getName(), $e);
|
||||||
* @param array $tables The metadata collection to which the loaded metadata is added.
|
|
||||||
*/
|
|
||||||
protected function loadMetadata($name)
|
|
||||||
{
|
|
||||||
if ( ! $this->initialized) {
|
|
||||||
$this->initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$loaded = array();
|
// If this class has a parent the id generator strategy is inherited.
|
||||||
|
// However this is only true if the hierarchy of parents contains the root entity,
|
||||||
$parentClasses = $this->getParentClasses($name);
|
// if it consists of mapped superclasses these don't necessarily include the id field.
|
||||||
$parentClasses[] = $name;
|
if ($parent && $rootEntityFound) {
|
||||||
|
if ($parent->isIdGeneratorSequence()) {
|
||||||
// Move down the hierarchy of parent classes, starting from the topmost class
|
$class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
|
||||||
$parent = null;
|
} else if ($parent->isIdGeneratorTable()) {
|
||||||
$rootEntityFound = false;
|
$class->tableGeneratorDefinition = $parent->tableGeneratorDefinition;
|
||||||
$visited = array();
|
|
||||||
foreach ($parentClasses as $className) {
|
|
||||||
if (isset($this->loadedMetadata[$className])) {
|
|
||||||
$parent = $this->loadedMetadata[$className];
|
|
||||||
if ( ! $parent->isMappedSuperclass) {
|
|
||||||
$rootEntityFound = true;
|
|
||||||
array_unshift($visited, $className);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = $this->newClassMetadataInstance($className);
|
if ($parent->generatorType) {
|
||||||
$this->initializeReflection($class, $this->getReflectionService());
|
|
||||||
|
|
||||||
if ($parent) {
|
|
||||||
$class->setInheritanceType($parent->inheritanceType);
|
|
||||||
$class->setDiscriminatorColumn($parent->discriminatorColumn);
|
|
||||||
$class->setIdGeneratorType($parent->generatorType);
|
$class->setIdGeneratorType($parent->generatorType);
|
||||||
$this->addInheritedFields($class, $parent);
|
|
||||||
$this->addInheritedRelations($class, $parent);
|
|
||||||
$class->setIdentifier($parent->identifier);
|
|
||||||
$class->setVersioned($parent->isVersioned);
|
|
||||||
$class->setVersionField($parent->versionField);
|
|
||||||
$class->setDiscriminatorMap($parent->discriminatorMap);
|
|
||||||
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
|
|
||||||
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
|
|
||||||
if ($parent->isMappedSuperclass) {
|
|
||||||
$class->setCustomRepositoryClass($parent->customRepositoryClassName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke driver
|
if ($parent->idGenerator) {
|
||||||
try {
|
$class->setIdGenerator($parent->idGenerator);
|
||||||
$this->driver->loadMetadataForClass($className, $class);
|
|
||||||
} catch (ReflectionException $e) {
|
|
||||||
throw MappingException::reflectionFailure($className, $e);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// If this class has a parent the id generator strategy is inherited.
|
$this->completeIdGeneratorMapping($class);
|
||||||
// However this is only true if the hierachy of parents contains the root entity,
|
|
||||||
// if it consinsts of mapped superclasses these don't necessarily include the id field.
|
|
||||||
if ($parent && $rootEntityFound) {
|
|
||||||
if ($parent->isIdGeneratorSequence()) {
|
|
||||||
$class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
|
|
||||||
} else if ($parent->isIdGeneratorTable()) {
|
|
||||||
$class->getTableGeneratorDefinition($parent->tableGeneratorDefinition);
|
|
||||||
}
|
|
||||||
if ($parent->generatorType) {
|
|
||||||
$class->setIdGeneratorType($parent->generatorType);
|
|
||||||
}
|
|
||||||
if ($parent->idGenerator) {
|
|
||||||
$class->setIdGenerator($parent->idGenerator);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->completeIdGeneratorMapping($class);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($parent && $parent->isInheritanceTypeSingleTable()) {
|
|
||||||
$class->setPrimaryTable($parent->table);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($parent && $parent->containsForeignIdentifier) {
|
|
||||||
$class->containsForeignIdentifier = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($parent && !empty ($parent->namedQueries)) {
|
|
||||||
$this->addInheritedNamedQueries($class, $parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($parent && !empty ($parent->namedNativeQueries)) {
|
|
||||||
$this->addInheritedNamedNativeQueries($class, $parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($parent && !empty ($parent->sqlResultSetMappings)) {
|
|
||||||
$this->addInheritedSqlResultSetMappings($class, $parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
$class->setParentClasses($visited);
|
|
||||||
|
|
||||||
if ( $class->isRootEntity() && ! $class->isInheritanceTypeNone() && ! $class->discriminatorMap) {
|
|
||||||
$this->addDefaultDiscriminatorMap($class);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->evm->hasListeners(Events::loadClassMetadata)) {
|
|
||||||
$eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($class, $this->em);
|
|
||||||
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
|
|
||||||
}
|
|
||||||
$this->wakeupReflection($class, $this->getReflectionService());
|
|
||||||
|
|
||||||
$this->validateRuntimeMetadata($class, $parent);
|
|
||||||
|
|
||||||
$this->loadedMetadata[$className] = $class;
|
|
||||||
|
|
||||||
$parent = $class;
|
|
||||||
|
|
||||||
if ( ! $class->isMappedSuperclass) {
|
|
||||||
$rootEntityFound = true;
|
|
||||||
array_unshift($visited, $className);
|
|
||||||
}
|
|
||||||
|
|
||||||
$loaded[] = $className;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loaded;
|
if ($parent && $parent->isInheritanceTypeSingleTable()) {
|
||||||
|
$class->setPrimaryTable($parent->table);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($parent && $parent->containsForeignIdentifier) {
|
||||||
|
$class->containsForeignIdentifier = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($parent && !empty($parent->namedQueries)) {
|
||||||
|
$this->addInheritedNamedQueries($class, $parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($parent && !empty($parent->namedNativeQueries)) {
|
||||||
|
$this->addInheritedNamedNativeQueries($class, $parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($parent && !empty($parent->sqlResultSetMappings)) {
|
||||||
|
$this->addInheritedSqlResultSetMappings($class, $parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
$class->setParentClasses($nonSuperclassParents);
|
||||||
|
|
||||||
|
if ( $class->isRootEntity() && ! $class->isInheritanceTypeNone() && ! $class->discriminatorMap) {
|
||||||
|
$this->addDefaultDiscriminatorMap($class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->evm->hasListeners(Events::loadClassMetadata)) {
|
||||||
|
$eventArgs = new LoadClassMetadataEventArgs($class, $this->em);
|
||||||
|
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->wakeupReflection($class, $this->getReflectionService());
|
||||||
|
$this->validateRuntimeMetadata($class, $parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate runtime metadata is correctly defined.
|
* Validate runtime metadata is correctly defined.
|
||||||
*
|
*
|
||||||
* @param ClassMetadata $class
|
* @param ClassMetadata $class
|
||||||
* @param ClassMetadata $parent
|
* @param $parent
|
||||||
|
* @throws MappingException
|
||||||
*/
|
*/
|
||||||
protected function validateRuntimeMetadata($class, $parent)
|
protected function validateRuntimeMetadata($class, $parent)
|
||||||
{
|
{
|
||||||
@ -394,20 +198,17 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
throw MappingException::missingDiscriminatorColumn($class->name);
|
throw MappingException::missingDiscriminatorColumn($class->name);
|
||||||
}
|
}
|
||||||
} else if ($parent && !$class->reflClass->isAbstract() && !in_array($class->name, array_values($class->discriminatorMap))) {
|
} else if ($parent && !$class->reflClass->isAbstract() && !in_array($class->name, array_values($class->discriminatorMap))) {
|
||||||
// enforce discriminator map for all entities of an inheritance hierachy, otherwise problems will occur.
|
// enforce discriminator map for all entities of an inheritance hierarchy, otherwise problems will occur.
|
||||||
throw MappingException::mappedClassNotPartOfDiscriminatorMap($class->name, $class->rootEntityName);
|
throw MappingException::mappedClassNotPartOfDiscriminatorMap($class->name, $class->rootEntityName);
|
||||||
}
|
}
|
||||||
} else if ($class->isMappedSuperclass && $class->name == $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) {
|
} else if ($class->isMappedSuperclass && $class->name == $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) {
|
||||||
// second condition is necessary for mapped superclasses in the middle of an inheritance hierachy
|
// second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy
|
||||||
throw MappingException::noInheritanceOnMappedSuperClass($class->name);
|
throw MappingException::noInheritanceOnMappedSuperClass($class->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ClassMetadata instance for the given class name.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @return \Doctrine\ORM\Mapping\ClassMetadata
|
|
||||||
*/
|
*/
|
||||||
protected function newClassMetadataInstance($className)
|
protected function newClassMetadataInstance($className)
|
||||||
{
|
{
|
||||||
@ -418,18 +219,18 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
* Adds a default discriminator map if no one is given
|
* Adds a default discriminator map if no one is given
|
||||||
*
|
*
|
||||||
* If an entity is of any inheritance type and does not contain a
|
* If an entity is of any inheritance type and does not contain a
|
||||||
* discrimiator map, then the map is generated automatically. This process
|
* discriminator map, then the map is generated automatically. This process
|
||||||
* is expensive computation wise.
|
* is expensive computation wise.
|
||||||
*
|
*
|
||||||
* The automatically generated discriminator map contains the lowercase shortname of
|
* The automatically generated discriminator map contains the lowercase short name of
|
||||||
* each class as key.
|
* each class as key.
|
||||||
*
|
*
|
||||||
* @param \Doctrine\ORM\Mapping\ClassMetadata $class
|
* @param \Doctrine\ORM\Mapping\ClassMetadata $class
|
||||||
|
* @throws MappingException
|
||||||
*/
|
*/
|
||||||
private function addDefaultDiscriminatorMap(ClassMetadata $class)
|
private function addDefaultDiscriminatorMap(ClassMetadata $class)
|
||||||
{
|
{
|
||||||
$allClasses = $this->driver->getAllClassNames();
|
$allClasses = $this->driver->getAllClassNames();
|
||||||
$subClassesMetadata = array();
|
|
||||||
$fqcn = $class->getName();
|
$fqcn = $class->getName();
|
||||||
$map = array($this->getShortName($class->name) => $fqcn);
|
$map = array($this->getShortName($class->name) => $fqcn);
|
||||||
|
|
||||||
@ -454,7 +255,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the lower-case shortname of a class.
|
* Get the lower-case short name of a class.
|
||||||
*
|
*
|
||||||
* @param string $className
|
* @param string $className
|
||||||
* @return string
|
* @return string
|
||||||
@ -469,40 +270,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
return strtolower(end($parts));
|
return strtolower(end($parts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache the metadata
|
|
||||||
*
|
|
||||||
* @param $className
|
|
||||||
* @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
|
|
||||||
*/
|
|
||||||
private function cacheMetadata($className, ClassMetadata $metadata)
|
|
||||||
{
|
|
||||||
$this->cacheDriver->save(
|
|
||||||
"$className\$CLASSMETADATA", $metadata, null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify if metadata is cached
|
|
||||||
*
|
|
||||||
* @param $className
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function cacheContainsMetadata($className)
|
|
||||||
{
|
|
||||||
return $this->cacheDriver->contains("$className\$CLASSMETADATA");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch metadata from cache
|
|
||||||
*
|
|
||||||
* @param $className
|
|
||||||
*/
|
|
||||||
private function fetchMetadataFromCache($className)
|
|
||||||
{
|
|
||||||
return $this->cacheDriver->fetch("$className\$CLASSMETADATA");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds inherited fields to the subclass mapping.
|
* Adds inherited fields to the subclass mapping.
|
||||||
*
|
*
|
||||||
@ -530,6 +297,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
*
|
*
|
||||||
* @param \Doctrine\ORM\Mapping\ClassMetadata $subClass
|
* @param \Doctrine\ORM\Mapping\ClassMetadata $subClass
|
||||||
* @param \Doctrine\ORM\Mapping\ClassMetadata $parentClass
|
* @param \Doctrine\ORM\Mapping\ClassMetadata $parentClass
|
||||||
|
* @throws MappingException
|
||||||
*/
|
*/
|
||||||
private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass)
|
private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass)
|
||||||
{
|
{
|
||||||
@ -627,7 +395,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
* Completes the ID generator mapping. If "auto" is specified we choose the generator
|
* Completes the ID generator mapping. If "auto" is specified we choose the generator
|
||||||
* most appropriate for the targeted database platform.
|
* most appropriate for the targeted database platform.
|
||||||
*
|
*
|
||||||
* @param \Doctrine\ORM\Mapping\ClassMetadata $class
|
* @param ClassMetadataInfo $class
|
||||||
|
* @throws ORMException
|
||||||
*/
|
*/
|
||||||
private function completeIdGeneratorMapping(ClassMetadataInfo $class)
|
private function completeIdGeneratorMapping(ClassMetadataInfo $class)
|
||||||
{
|
{
|
||||||
@ -725,70 +494,36 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this class is mapped by this EntityManager + ClassMetadata configuration
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @param $class
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function isTransient($class)
|
protected function wakeupReflection(ClassMetadataInterface $class, ReflectionService $reflService)
|
||||||
{
|
|
||||||
if ( ! $this->initialized) {
|
|
||||||
$this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for namespace alias
|
|
||||||
if (strpos($class, ':') !== false) {
|
|
||||||
list($namespaceAlias, $simpleClassName) = explode(':', $class);
|
|
||||||
$class = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->driver->isTransient($class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get reflectionService.
|
|
||||||
*
|
|
||||||
* @return \Doctrine\Common\Persistence\Mapping\ReflectionService
|
|
||||||
*/
|
|
||||||
public function getReflectionService()
|
|
||||||
{
|
|
||||||
if ($this->reflectionService === null) {
|
|
||||||
$this->reflectionService = new RuntimeReflectionService();
|
|
||||||
}
|
|
||||||
return $this->reflectionService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set reflectionService.
|
|
||||||
*
|
|
||||||
* @param reflectionService the value to set.
|
|
||||||
*/
|
|
||||||
public function setReflectionService(ReflectionService $reflectionService)
|
|
||||||
{
|
|
||||||
$this->reflectionService = $reflectionService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wakeup reflection after ClassMetadata gets unserialized from cache.
|
|
||||||
*
|
|
||||||
* @param ClassMetadataInfo $class
|
|
||||||
* @param ReflectionService $reflService
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function wakeupReflection(ClassMetadataInfo $class, ReflectionService $reflService)
|
|
||||||
{
|
{
|
||||||
|
/* @var $class ClassMetadata */
|
||||||
$class->wakeupReflection($reflService);
|
$class->wakeupReflection($reflService);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize Reflection after ClassMetadata was constructed.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @param ClassMetadataInfo $class
|
|
||||||
* @param ReflectionService $reflService
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
protected function initializeReflection(ClassMetadataInfo $class, ReflectionService $reflService)
|
protected function initializeReflection(ClassMetadataInterface $class, ReflectionService $reflService)
|
||||||
{
|
{
|
||||||
|
/* @var $class ClassMetadata */
|
||||||
$class->initializeReflection($reflService);
|
$class->initializeReflection($reflService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
|
||||||
|
{
|
||||||
|
return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
protected function getDriver()
|
||||||
|
{
|
||||||
|
return $this->driver;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,13 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping;
|
namespace Doctrine\ORM\Mapping;
|
||||||
|
|
||||||
|
use BadMethodCallException;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use RuntimeException;
|
||||||
use Doctrine\DBAL\Types\Type;
|
use Doctrine\DBAL\Types\Type;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||||
|
use Doctrine\Common\ClassLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
|
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
|
||||||
@ -617,7 +621,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Gets a ReflectionProperty for a specific field of the mapped class.
|
* Gets a ReflectionProperty for a specific field of the mapped class.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return ReflectionProperty
|
* @return \ReflectionProperty
|
||||||
*/
|
*/
|
||||||
public function getReflectionProperty($name)
|
public function getReflectionProperty($name)
|
||||||
{
|
{
|
||||||
@ -627,13 +631,13 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Gets the ReflectionProperty for the single identifier field.
|
* Gets the ReflectionProperty for the single identifier field.
|
||||||
*
|
*
|
||||||
* @return ReflectionProperty
|
* @return \ReflectionProperty
|
||||||
* @throws BadMethodCallException If the class has a composite identifier.
|
* @throws BadMethodCallException If the class has a composite identifier.
|
||||||
*/
|
*/
|
||||||
public function getSingleIdReflectionProperty()
|
public function getSingleIdReflectionProperty()
|
||||||
{
|
{
|
||||||
if ($this->isIdentifierComposite) {
|
if ($this->isIdentifierComposite) {
|
||||||
throw new \BadMethodCallException("Class " . $this->name . " has a composite identifier.");
|
throw new BadMethodCallException("Class " . $this->name . " has a composite identifier.");
|
||||||
}
|
}
|
||||||
return $this->reflFields[$this->identifier[0]];
|
return $this->reflFields[$this->identifier[0]];
|
||||||
}
|
}
|
||||||
@ -831,7 +835,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Restores some state that can not be serialized/unserialized.
|
* Restores some state that can not be serialized/unserialized.
|
||||||
*
|
*
|
||||||
* @param ReflectionService $reflService
|
* @param \Doctrine\Common\Persistence\Mapping\ReflectionService $reflService
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function wakeupReflection($reflService)
|
public function wakeupReflection($reflService)
|
||||||
@ -856,7 +860,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Initializes a new ClassMetadata instance that will hold the object-relational mapping
|
* Initializes a new ClassMetadata instance that will hold the object-relational mapping
|
||||||
* metadata of the class with the given name.
|
* metadata of the class with the given name.
|
||||||
*
|
*
|
||||||
* @param ReflectionService $reflService The reflection service.
|
* @param \Doctrine\Common\Persistence\Mapping\ReflectionService $reflService The reflection service.
|
||||||
*/
|
*/
|
||||||
public function initializeReflection($reflService)
|
public function initializeReflection($reflService)
|
||||||
{
|
{
|
||||||
@ -873,6 +877,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Validate Identifier
|
* Validate Identifier
|
||||||
*
|
*
|
||||||
|
* @throws MappingException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function validateIdentifier()
|
public function validateIdentifier()
|
||||||
@ -890,12 +895,13 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Validate association targets actually exist.
|
* Validate association targets actually exist.
|
||||||
*
|
*
|
||||||
|
* @throws MappingException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function validateAssocations()
|
public function validateAssocations()
|
||||||
{
|
{
|
||||||
foreach ($this->associationMappings as $mapping) {
|
foreach ($this->associationMappings as $mapping) {
|
||||||
if ( ! \Doctrine\Common\ClassLoader::classExists($mapping['targetEntity']) ) {
|
if ( ! ClassLoader::classExists($mapping['targetEntity']) ) {
|
||||||
throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']);
|
throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -904,12 +910,13 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Validate lifecycle callbacks
|
* Validate lifecycle callbacks
|
||||||
*
|
*
|
||||||
* @param ReflectionService $reflService
|
* @param \Doctrine\Common\Persistence\Mapping\ReflectionService $reflService
|
||||||
|
* @throws MappingException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function validateLifecycleCallbacks($reflService)
|
public function validateLifecycleCallbacks($reflService)
|
||||||
{
|
{
|
||||||
foreach ($this->lifecycleCallbacks as $event => $callbacks) {
|
foreach ($this->lifecycleCallbacks as $callbacks) {
|
||||||
foreach ($callbacks as $callbackFuncName) {
|
foreach ($callbacks as $callbackFuncName) {
|
||||||
if ( ! $reflService->hasPublicMethod($this->name, $callbackFuncName)) {
|
if ( ! $reflService->hasPublicMethod($this->name, $callbackFuncName)) {
|
||||||
throw MappingException::lifecycleCallbackMethodNotFound($this->name, $callbackFuncName);
|
throw MappingException::lifecycleCallbackMethodNotFound($this->name, $callbackFuncName);
|
||||||
@ -919,9 +926,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ReflectionClass instance of the mapped class.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @return ReflectionClass
|
|
||||||
*/
|
*/
|
||||||
public function getReflectionClass()
|
public function getReflectionClass()
|
||||||
{
|
{
|
||||||
@ -1032,7 +1037,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* reference to another object.
|
* reference to another object.
|
||||||
*
|
*
|
||||||
* @param string $fieldName The field name.
|
* @param string $fieldName The field name.
|
||||||
* @return array The field mapping.
|
* @throws MappingException
|
||||||
|
* @return array The field mapping.
|
||||||
*/
|
*/
|
||||||
public function getFieldMapping($fieldName)
|
public function getFieldMapping($fieldName)
|
||||||
{
|
{
|
||||||
@ -1048,6 +1054,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* @see ClassMetadataInfo::$associationMappings
|
* @see ClassMetadataInfo::$associationMappings
|
||||||
* @param string $fieldName The field name that represents the association in
|
* @param string $fieldName The field name that represents the association in
|
||||||
* the object model.
|
* the object model.
|
||||||
|
* @throws MappingException
|
||||||
* @return array The mapping.
|
* @return array The mapping.
|
||||||
*/
|
*/
|
||||||
public function getAssociationMapping($fieldName)
|
public function getAssociationMapping($fieldName)
|
||||||
@ -1165,7 +1172,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Validates & completes the given field mapping.
|
* Validates & completes the given field mapping.
|
||||||
*
|
*
|
||||||
* @param array $mapping The field mapping to validated & complete.
|
* @param array $mapping The field mapping to validated & complete.
|
||||||
* @return array The validated and completed field mapping.
|
* @throws MappingException
|
||||||
|
* @return array The validated and completed field mapping.
|
||||||
*/
|
*/
|
||||||
protected function _validateAndCompleteFieldMapping(array &$mapping)
|
protected function _validateAndCompleteFieldMapping(array &$mapping)
|
||||||
{
|
{
|
||||||
@ -1342,8 +1350,9 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Validates & completes a one-to-one association mapping.
|
* Validates & completes a one-to-one association mapping.
|
||||||
*
|
*
|
||||||
* @param array $mapping The mapping to validate & complete.
|
* @param array $mapping The mapping to validate & complete.
|
||||||
* @return array The validated & completed mapping.
|
* @throws RuntimeException
|
||||||
* @override
|
* @throws MappingException
|
||||||
|
* @return array The validated & completed mapping.@override
|
||||||
*/
|
*/
|
||||||
protected function _validateAndCompleteOneToOneMapping(array $mapping)
|
protected function _validateAndCompleteOneToOneMapping(array $mapping)
|
||||||
{
|
{
|
||||||
@ -1363,7 +1372,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
$uniqueContraintColumns = array();
|
$uniqueContraintColumns = array();
|
||||||
foreach ($mapping['joinColumns'] as $key => &$joinColumn) {
|
foreach ($mapping['joinColumns'] as &$joinColumn) {
|
||||||
if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) {
|
if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) {
|
||||||
if (count($mapping['joinColumns']) == 1) {
|
if (count($mapping['joinColumns']) == 1) {
|
||||||
if ( ! isset($mapping['id']) || ! $mapping['id']) {
|
if ( ! isset($mapping['id']) || ! $mapping['id']) {
|
||||||
@ -1399,7 +1408,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
|
|
||||||
if ($uniqueContraintColumns) {
|
if ($uniqueContraintColumns) {
|
||||||
if ( ! $this->table) {
|
if ( ! $this->table) {
|
||||||
throw new \RuntimeException("ClassMetadataInfo::setTable() has to be called before defining a one to one relationship.");
|
throw new RuntimeException("ClassMetadataInfo::setTable() has to be called before defining a one to one relationship.");
|
||||||
}
|
}
|
||||||
$this->table['uniqueConstraints'][$mapping['fieldName']."_uniq"] = array(
|
$this->table['uniqueConstraints'][$mapping['fieldName']."_uniq"] = array(
|
||||||
'columns' => $uniqueContraintColumns
|
'columns' => $uniqueContraintColumns
|
||||||
@ -1423,8 +1432,9 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Validates and completes the mapping.
|
* Validates and completes the mapping.
|
||||||
*
|
*
|
||||||
* @param array $mapping The mapping to validate and complete.
|
* @param array $mapping The mapping to validate and complete.
|
||||||
* @return array The validated and completed mapping.
|
* @throws MappingException
|
||||||
* @override
|
* @throws InvalidArgumentException
|
||||||
|
* @return array The validated and completed mapping.@override
|
||||||
*/
|
*/
|
||||||
protected function _validateAndCompleteOneToManyMapping(array $mapping)
|
protected function _validateAndCompleteOneToManyMapping(array $mapping)
|
||||||
{
|
{
|
||||||
@ -1440,7 +1450,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
|
|
||||||
if (isset($mapping['orderBy'])) {
|
if (isset($mapping['orderBy'])) {
|
||||||
if ( ! is_array($mapping['orderBy'])) {
|
if ( ! is_array($mapping['orderBy'])) {
|
||||||
throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
|
throw new InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1527,7 +1537,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
|
|
||||||
if (isset($mapping['orderBy'])) {
|
if (isset($mapping['orderBy'])) {
|
||||||
if ( ! is_array($mapping['orderBy'])) {
|
if ( ! is_array($mapping['orderBy'])) {
|
||||||
throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
|
throw new InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1535,9 +1545,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the identifier (primary key) field names of the class.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public function getIdentifierFieldNames()
|
public function getIdentifierFieldNames()
|
||||||
{
|
{
|
||||||
@ -1587,7 +1595,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Gets the mapped identifier field of this class.
|
* Gets the mapped identifier field of this class.
|
||||||
*
|
*
|
||||||
* @return string $identifier
|
* @return array|string $identifier
|
||||||
*/
|
*/
|
||||||
public function getIdentifier()
|
public function getIdentifier()
|
||||||
{
|
{
|
||||||
@ -1595,9 +1603,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the class has a (mapped) field with a certain name.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
*/
|
||||||
public function hasField($fieldName)
|
public function hasField($fieldName)
|
||||||
{
|
{
|
||||||
@ -1607,6 +1613,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Gets an array containing all the column names.
|
* Gets an array containing all the column names.
|
||||||
*
|
*
|
||||||
|
* @param array $fieldNames
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getColumnNames(array $fieldNames = null)
|
public function getColumnNames(array $fieldNames = null)
|
||||||
@ -1734,7 +1741,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
*/
|
*/
|
||||||
public function isIdGeneratorTable()
|
public function isIdGeneratorTable()
|
||||||
{
|
{
|
||||||
$this->generatorType == self::GENERATOR_TYPE_TABLE;
|
return $this->generatorType == self::GENERATOR_TYPE_TABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1762,7 +1769,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Gets the type of a field.
|
* Gets the type of a field.
|
||||||
*
|
*
|
||||||
* @param string $fieldName
|
* @param string $fieldName
|
||||||
* @return \Doctrine\DBAL\Types\Type
|
* @return \Doctrine\DBAL\Types\Type|string
|
||||||
*/
|
*/
|
||||||
public function getTypeOfField($fieldName)
|
public function getTypeOfField($fieldName)
|
||||||
{
|
{
|
||||||
@ -1773,6 +1780,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Gets the type of a column.
|
* Gets the type of a column.
|
||||||
*
|
*
|
||||||
|
* @param string $columnName
|
||||||
* @return \Doctrine\DBAL\Types\Type
|
* @return \Doctrine\DBAL\Types\Type
|
||||||
*/
|
*/
|
||||||
public function getTypeOfColumn($columnName)
|
public function getTypeOfColumn($columnName)
|
||||||
@ -1834,6 +1842,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Sets the inheritance type used by the class and it's subclasses.
|
* Sets the inheritance type used by the class and it's subclasses.
|
||||||
*
|
*
|
||||||
* @param integer $type
|
* @param integer $type
|
||||||
|
* @throws MappingException
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setInheritanceType($type)
|
public function setInheritanceType($type)
|
||||||
{
|
{
|
||||||
@ -1848,6 +1858,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
*
|
*
|
||||||
* @param string $fieldName
|
* @param string $fieldName
|
||||||
* @param array $overrideMapping
|
* @param array $overrideMapping
|
||||||
|
* @throws MappingException
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setAssociationOverride($fieldName, array $overrideMapping)
|
public function setAssociationOverride($fieldName, array $overrideMapping)
|
||||||
{
|
{
|
||||||
@ -1889,11 +1901,14 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
$this->associationMappings[$fieldName] = $mapping;
|
$this->associationMappings[$fieldName] = $mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the override for a mapped field.
|
* Sets the override for a mapped field.
|
||||||
*
|
*
|
||||||
* @param string $fieldName
|
* @param string $fieldName
|
||||||
* @param array $mapping
|
* @param array $overrideMapping
|
||||||
|
* @throws MappingException
|
||||||
|
* @param array $overrideMapping
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setAttributeOverride($fieldName, array $overrideMapping)
|
public function setAttributeOverride($fieldName, array $overrideMapping)
|
||||||
{
|
{
|
||||||
@ -1930,7 +1945,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Checks whether a mapped field is inherited from an entity superclass.
|
* Checks whether a mapped field is inherited from an entity superclass.
|
||||||
*
|
*
|
||||||
* @return boolean TRUE if the field is inherited, FALSE otherwise.
|
* @param string $fieldName
|
||||||
|
* @return bool TRUE if the field is inherited, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public function isInheritedField($fieldName)
|
public function isInheritedField($fieldName)
|
||||||
{
|
{
|
||||||
@ -2023,6 +2039,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Adds a mapped field to the class.
|
* Adds a mapped field to the class.
|
||||||
*
|
*
|
||||||
* @param array $mapping The field mapping.
|
* @param array $mapping The field mapping.
|
||||||
|
* @throws MappingException
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function mapField(array $mapping)
|
public function mapField(array $mapping)
|
||||||
{
|
{
|
||||||
@ -2039,6 +2057,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* This is mainly used to add inherited association mappings to derived classes.
|
* This is mainly used to add inherited association mappings to derived classes.
|
||||||
*
|
*
|
||||||
* @param array $mapping
|
* @param array $mapping
|
||||||
|
* @throws MappingException
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/)
|
public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/)
|
||||||
{
|
{
|
||||||
@ -2053,7 +2073,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Adds a field mapping without completing/validating it.
|
* Adds a field mapping without completing/validating it.
|
||||||
* This is mainly used to add inherited field mappings to derived classes.
|
* This is mainly used to add inherited field mappings to derived classes.
|
||||||
*
|
*
|
||||||
* @param array $mapping
|
* @param array $fieldMapping
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addInheritedFieldMapping(array $fieldMapping)
|
public function addInheritedFieldMapping(array $fieldMapping)
|
||||||
{
|
{
|
||||||
@ -2247,6 +2268,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Stores the association mapping.
|
* Stores the association mapping.
|
||||||
*
|
*
|
||||||
* @param array $assocMapping
|
* @param array $assocMapping
|
||||||
|
* @throws MappingException
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function _storeAssociationMapping(array $assocMapping)
|
protected function _storeAssociationMapping(array $assocMapping)
|
||||||
{
|
{
|
||||||
@ -2262,7 +2285,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Registers a custom repository class for the entity class.
|
* Registers a custom repository class for the entity class.
|
||||||
*
|
*
|
||||||
* @param string $mapperClassName The class name of the custom mapper.
|
* @param string $repositoryClassName The class name of the custom mapper.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setCustomRepositoryClass($repositoryClassName)
|
public function setCustomRepositoryClass($repositoryClassName)
|
||||||
{
|
{
|
||||||
@ -2277,8 +2301,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Dispatches the lifecycle event of the given entity to the registered
|
* Dispatches the lifecycle event of the given entity to the registered
|
||||||
* lifecycle callbacks and lifecycle listeners.
|
* lifecycle callbacks and lifecycle listeners.
|
||||||
*
|
*
|
||||||
* @param string $event The lifecycle event.
|
* @param string $lifecycleEvent The lifecycle event.
|
||||||
* @param Entity $entity The Entity on which the event occured.
|
* @param \Object $entity The Entity on which the event occured.
|
||||||
*/
|
*/
|
||||||
public function invokeLifecycleCallbacks($lifecycleEvent, $entity)
|
public function invokeLifecycleCallbacks($lifecycleEvent, $entity)
|
||||||
{
|
{
|
||||||
@ -2335,6 +2359,10 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Sets the discriminator column definition.
|
* Sets the discriminator column definition.
|
||||||
*
|
*
|
||||||
* @param array $columnDef
|
* @param array $columnDef
|
||||||
|
*
|
||||||
|
* @param $columnDef
|
||||||
|
* @throws MappingException
|
||||||
|
* @return void
|
||||||
* @see getDiscriminatorColumn()
|
* @see getDiscriminatorColumn()
|
||||||
*/
|
*/
|
||||||
public function setDiscriminatorColumn($columnDef)
|
public function setDiscriminatorColumn($columnDef)
|
||||||
@ -2382,6 +2410,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $className
|
* @param string $className
|
||||||
|
* @throws MappingException
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addDiscriminatorMapClass($name, $className)
|
public function addDiscriminatorMapClass($name, $className)
|
||||||
{
|
{
|
||||||
@ -2438,10 +2468,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the class has a mapped association with the given field name.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @param string $fieldName
|
|
||||||
* @return boolean
|
|
||||||
*/
|
*/
|
||||||
public function hasAssociation($fieldName)
|
public function hasAssociation($fieldName)
|
||||||
{
|
{
|
||||||
@ -2449,11 +2476,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the class has a mapped association for the specified field
|
* {@inheritDoc}
|
||||||
* and if yes, checks whether it is a single-valued association (to-one).
|
|
||||||
*
|
|
||||||
* @param string $fieldName
|
|
||||||
* @return boolean TRUE if the association exists and is single-valued, FALSE otherwise.
|
|
||||||
*/
|
*/
|
||||||
public function isSingleValuedAssociation($fieldName)
|
public function isSingleValuedAssociation($fieldName)
|
||||||
{
|
{
|
||||||
@ -2462,11 +2485,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the class has a mapped association for the specified field
|
* {@inheritDoc}
|
||||||
* and if yes, checks whether it is a collection-valued association (to-many).
|
|
||||||
*
|
|
||||||
* @param string $fieldName
|
|
||||||
* @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise.
|
|
||||||
*/
|
*/
|
||||||
public function isCollectionValuedAssociation($fieldName)
|
public function isCollectionValuedAssociation($fieldName)
|
||||||
{
|
{
|
||||||
@ -2493,6 +2512,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Return the single association join column (if any).
|
* Return the single association join column (if any).
|
||||||
*
|
*
|
||||||
* @param string $fieldName
|
* @param string $fieldName
|
||||||
|
* @throws MappingException
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getSingleAssociationJoinColumnName($fieldName)
|
public function getSingleAssociationJoinColumnName($fieldName)
|
||||||
@ -2507,6 +2527,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* Return the single association referenced join column name (if any).
|
* Return the single association referenced join column name (if any).
|
||||||
*
|
*
|
||||||
* @param string $fieldName
|
* @param string $fieldName
|
||||||
|
* @throws MappingException
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getSingleAssociationReferencedJoinColumnName($fieldName)
|
public function getSingleAssociationReferencedJoinColumnName($fieldName)
|
||||||
@ -2523,6 +2544,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* This method is used in foreign-key as primary-key contexts.
|
* This method is used in foreign-key as primary-key contexts.
|
||||||
*
|
*
|
||||||
* @param string $columnName
|
* @param string $columnName
|
||||||
|
* @throws MappingException
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getFieldForColumn($columnName)
|
public function getFieldForColumn($columnName)
|
||||||
@ -2545,7 +2567,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
/**
|
/**
|
||||||
* Sets the ID generator used to generate IDs for instances of this class.
|
* Sets the ID generator used to generate IDs for instances of this class.
|
||||||
*
|
*
|
||||||
* @param AbstractIdGenerator $generator
|
* @param \Doctrine\ORM\Id\AbstractIdGenerator $generator
|
||||||
*/
|
*/
|
||||||
public function setIdGenerator($generator)
|
public function setIdGenerator($generator)
|
||||||
{
|
{
|
||||||
@ -2591,6 +2613,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* value to use depending on the column type.
|
* value to use depending on the column type.
|
||||||
*
|
*
|
||||||
* @param array $mapping The version field mapping array
|
* @param array $mapping The version field mapping array
|
||||||
|
* @throws MappingException
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setVersionMapping(array &$mapping)
|
public function setVersionMapping(array &$mapping)
|
||||||
{
|
{
|
||||||
@ -2640,11 +2664,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A numerically indexed list of field names of this persistent class.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* This array includes identifier fields if present on this class.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function getFieldNames()
|
public function getFieldNames()
|
||||||
{
|
{
|
||||||
@ -2652,11 +2672,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A numerically indexed list of association names of this persistent class.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* This array includes identifier associations if present on this class.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function getAssociationNames()
|
public function getAssociationNames()
|
||||||
{
|
{
|
||||||
@ -2664,24 +2680,20 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the target class name of the given association.
|
* {@inheritDoc}
|
||||||
*
|
* @throws InvalidArgumentException
|
||||||
* @param string $assocName
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getAssociationTargetClass($assocName)
|
public function getAssociationTargetClass($assocName)
|
||||||
{
|
{
|
||||||
if ( ! isset($this->associationMappings[$assocName])) {
|
if ( ! isset($this->associationMappings[$assocName])) {
|
||||||
throw new \InvalidArgumentException("Association name expected, '" . $assocName ."' is not an association.");
|
throw new InvalidArgumentException("Association name expected, '" . $assocName ."' is not an association.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->associationMappings[$assocName]['targetEntity'];
|
return $this->associationMappings[$assocName]['targetEntity'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get fully-qualified class name of this persistent class.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
@ -2693,7 +2705,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
*
|
*
|
||||||
* @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
|
* @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
|
||||||
*
|
*
|
||||||
* @param AbstractPlatform $platform
|
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getQuotedIdentifierColumnNames($platform)
|
public function getQuotedIdentifierColumnNames($platform)
|
||||||
@ -2732,7 +2744,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
* @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
|
* @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
|
||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param AbstractPlatform $platform
|
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getQuotedColumnName($field, $platform)
|
public function getQuotedColumnName($field, $platform)
|
||||||
@ -2747,7 +2759,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
*
|
*
|
||||||
* @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
|
* @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
|
||||||
*
|
*
|
||||||
* @param AbstractPlatform $platform
|
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getQuotedTableName($platform)
|
public function getQuotedTableName($platform)
|
||||||
@ -2760,7 +2772,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
*
|
*
|
||||||
* @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
|
* @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
|
||||||
*
|
*
|
||||||
* @param AbstractPlatform $platform
|
* @param array $assoc
|
||||||
|
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getQuotedJoinTableName(array $assoc, $platform)
|
public function getQuotedJoinTableName(array $assoc, $platform)
|
||||||
@ -2769,8 +2782,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $fieldName
|
* {@inheritDoc}
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function isAssociationInverseSide($fieldName)
|
public function isAssociationInverseSide($fieldName)
|
||||||
{
|
{
|
||||||
@ -2778,8 +2790,7 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $fieldName
|
* {@inheritDoc}
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getAssociationMappedByTargetField($fieldName)
|
public function getAssociationMappedByTargetField($fieldName)
|
||||||
{
|
{
|
||||||
|
@ -1,210 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* 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 MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\MappingException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base driver for file-based metadata drivers.
|
|
||||||
*
|
|
||||||
* A file driver operates in a mode where it loads the mapping files of individual
|
|
||||||
* classes on demand. This requires the user to adhere to the convention of 1 mapping
|
|
||||||
* file per class and the file names of the mapping files must correspond to the full
|
|
||||||
* class name, including namespace, with the namespace delimiters '\', replaced by dots '.'.
|
|
||||||
*
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @link www.doctrine-project.com
|
|
||||||
* @since 2.0
|
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
|
||||||
*/
|
|
||||||
abstract class AbstractFileDriver implements Driver
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The paths where to look for mapping files.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $_paths = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The file extension of mapping documents.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $_fileExtension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a new FileDriver that looks in the given path(s) for mapping
|
|
||||||
* documents and operates in the specified operating mode.
|
|
||||||
*
|
|
||||||
* @param string|array $paths One or multiple paths where mapping documents can be found.
|
|
||||||
*/
|
|
||||||
public function __construct($paths)
|
|
||||||
{
|
|
||||||
$this->addPaths((array) $paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append lookup paths to metadata driver.
|
|
||||||
*
|
|
||||||
* @param array $paths
|
|
||||||
*/
|
|
||||||
public function addPaths(array $paths)
|
|
||||||
{
|
|
||||||
$this->_paths = array_unique(array_merge($this->_paths, $paths));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the defined metadata lookup paths.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPaths()
|
|
||||||
{
|
|
||||||
return $this->_paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the file extension used to look for mapping files under
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function getFileExtension()
|
|
||||||
{
|
|
||||||
return $this->_fileExtension;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the file extension used to look for mapping files under
|
|
||||||
*
|
|
||||||
* @param string $fileExtension The file extension to set
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setFileExtension($fileExtension)
|
|
||||||
{
|
|
||||||
$this->_fileExtension = $fileExtension;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the element of schema meta data for the class from the mapping file.
|
|
||||||
* This will lazily load the mapping file if it is not loaded yet
|
|
||||||
*
|
|
||||||
* @return array $element The element of schema meta data
|
|
||||||
*/
|
|
||||||
public function getElement($className)
|
|
||||||
{
|
|
||||||
$result = $this->_loadMappingFile($this->_findMappingFile($className));
|
|
||||||
|
|
||||||
if(!isset($result[$className])){
|
|
||||||
throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->_fileExtension);
|
|
||||||
}
|
|
||||||
return $result[$className];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the class with the specified name should have its metadata loaded.
|
|
||||||
* This is only the case if it is either mapped as an Entity or a
|
|
||||||
* MappedSuperclass.
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function isTransient($className)
|
|
||||||
{
|
|
||||||
$fileName = str_replace('\\', '.', $className) . $this->_fileExtension;
|
|
||||||
|
|
||||||
// Check whether file exists
|
|
||||||
foreach ((array) $this->_paths as $path) {
|
|
||||||
if (file_exists($path . DIRECTORY_SEPARATOR . $fileName)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the names of all mapped classes known to this driver.
|
|
||||||
*
|
|
||||||
* @return array The names of all mapped classes known to this driver.
|
|
||||||
*/
|
|
||||||
public function getAllClassNames()
|
|
||||||
{
|
|
||||||
$classes = array();
|
|
||||||
|
|
||||||
if ($this->_paths) {
|
|
||||||
foreach ((array) $this->_paths as $path) {
|
|
||||||
if ( ! is_dir($path)) {
|
|
||||||
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
|
||||||
new \RecursiveDirectoryIterator($path),
|
|
||||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($iterator as $file) {
|
|
||||||
if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: All files found here means classes are not transient!
|
|
||||||
$classes[] = str_replace('.', '\\', $fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $classes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the mapping file for the class with the given name by searching
|
|
||||||
* through the configured paths.
|
|
||||||
*
|
|
||||||
* @param $className
|
|
||||||
* @return string The (absolute) file name.
|
|
||||||
* @throws MappingException
|
|
||||||
*/
|
|
||||||
protected function _findMappingFile($className)
|
|
||||||
{
|
|
||||||
$fileName = str_replace('\\', '.', $className) . $this->_fileExtension;
|
|
||||||
|
|
||||||
// Check whether file exists
|
|
||||||
foreach ((array) $this->_paths as $path) {
|
|
||||||
if (file_exists($path . DIRECTORY_SEPARATOR . $fileName)) {
|
|
||||||
return $path . DIRECTORY_SEPARATOR . $fileName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw MappingException::mappingFileNotFound($className, $fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a mapping file with the given name and returns a map
|
|
||||||
* from class/entity names to their corresponding elements.
|
|
||||||
*
|
|
||||||
* @param string $file The mapping file to load.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
abstract protected function _loadMappingFile($file);
|
|
||||||
}
|
|
@ -19,13 +19,12 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\Common\Cache\ArrayCache,
|
use Doctrine\Common\Annotations\AnnotationReader,
|
||||||
Doctrine\Common\Annotations\AnnotationReader,
|
|
||||||
Doctrine\Common\Annotations\AnnotationRegistry,
|
|
||||||
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
|
||||||
Doctrine\ORM\Mapping\MappingException,
|
Doctrine\ORM\Mapping\MappingException,
|
||||||
Doctrine\ORM\Mapping\JoinColumn,
|
Doctrine\ORM\Mapping\JoinColumn,
|
||||||
Doctrine\ORM\Mapping\Column;
|
Doctrine\ORM\Mapping\Column,
|
||||||
|
Doctrine\Common\Persistence\Mapping\ClassMetadata,
|
||||||
|
Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The AnnotationDriver reads the mapping metadata from docblock annotations.
|
* The AnnotationDriver reads the mapping metadata from docblock annotations.
|
||||||
@ -36,105 +35,22 @@ use Doctrine\Common\Cache\ArrayCache,
|
|||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
* @author Roman Borschel <roman@code-factory.org>
|
||||||
*/
|
*/
|
||||||
class AnnotationDriver implements Driver
|
class AnnotationDriver extends AbstractAnnotationDriver
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The AnnotationReader.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @var AnnotationReader
|
|
||||||
*/
|
*/
|
||||||
protected $_reader;
|
protected $entityAnnotationClasses = array(
|
||||||
|
'Doctrine\ORM\Mapping\Entity' => 1,
|
||||||
|
'Doctrine\ORM\Mapping\MappedSuperclass' => 2,
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The paths where to look for mapping files.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
*/
|
||||||
protected $_paths = array();
|
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||||
|
|
||||||
/**
|
|
||||||
* The file extension of mapping documents.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $_fileExtension = '.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array
|
|
||||||
*/
|
|
||||||
protected $_classNames;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
|
|
||||||
* docblock annotations.
|
|
||||||
*
|
|
||||||
* @param AnnotationReader $reader The AnnotationReader to use, duck-typed.
|
|
||||||
* @param string|array $paths One or multiple paths where mapping classes can be found.
|
|
||||||
*/
|
|
||||||
public function __construct($reader, $paths = null)
|
|
||||||
{
|
|
||||||
$this->_reader = $reader;
|
|
||||||
if ($paths) {
|
|
||||||
$this->addPaths((array) $paths);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append lookup paths to metadata driver.
|
|
||||||
*
|
|
||||||
* @param array $paths
|
|
||||||
*/
|
|
||||||
public function addPaths(array $paths)
|
|
||||||
{
|
|
||||||
$this->_paths = array_unique(array_merge($this->_paths, $paths));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the defined metadata lookup paths.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPaths()
|
|
||||||
{
|
|
||||||
return $this->_paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the current annotation reader
|
|
||||||
*
|
|
||||||
* @return AnnotationReader
|
|
||||||
*/
|
|
||||||
public function getReader()
|
|
||||||
{
|
|
||||||
return $this->_reader;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the file extension used to look for mapping files under
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function getFileExtension()
|
|
||||||
{
|
|
||||||
return $this->_fileExtension;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the file extension used to look for mapping files under
|
|
||||||
*
|
|
||||||
* @param string $fileExtension The file extension to set
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setFileExtension($fileExtension)
|
|
||||||
{
|
|
||||||
$this->_fileExtension = $fileExtension;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
|
||||||
{
|
{
|
||||||
|
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
|
||||||
$class = $metadata->getReflectionClass();
|
$class = $metadata->getReflectionClass();
|
||||||
if ( ! $class) {
|
if ( ! $class) {
|
||||||
// this happens when running annotation driver in combination with
|
// this happens when running annotation driver in combination with
|
||||||
@ -142,7 +58,7 @@ class AnnotationDriver implements Driver
|
|||||||
$class = new \ReflectionClass($metadata->name);
|
$class = new \ReflectionClass($metadata->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
$classAnnotations = $this->_reader->getClassAnnotations($class);
|
$classAnnotations = $this->reader->getClassAnnotations($class);
|
||||||
|
|
||||||
if ($classAnnotations && is_numeric(key($classAnnotations))) {
|
if ($classAnnotations && is_numeric(key($classAnnotations))) {
|
||||||
foreach ($classAnnotations as $annot) {
|
foreach ($classAnnotations as $annot) {
|
||||||
@ -349,6 +265,7 @@ class AnnotationDriver implements Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate annotations on properties/fields
|
// Evaluate annotations on properties/fields
|
||||||
|
/* @var $property \ReflectionProperty */
|
||||||
foreach ($class->getProperties() as $property) {
|
foreach ($class->getProperties() as $property) {
|
||||||
if ($metadata->isMappedSuperclass && ! $property->isPrivate()
|
if ($metadata->isMappedSuperclass && ! $property->isPrivate()
|
||||||
||
|
||
|
||||||
@ -364,9 +281,9 @@ class AnnotationDriver implements Driver
|
|||||||
// Check for JoinColummn/JoinColumns annotations
|
// Check for JoinColummn/JoinColumns annotations
|
||||||
$joinColumns = array();
|
$joinColumns = array();
|
||||||
|
|
||||||
if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) {
|
if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) {
|
||||||
$joinColumns[] = $this->joinColumnToArray($joinColumnAnnot);
|
$joinColumns[] = $this->joinColumnToArray($joinColumnAnnot);
|
||||||
} else if ($joinColumnsAnnot = $this->_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[] = $this->joinColumnToArray($joinColumn);
|
$joinColumns[] = $this->joinColumnToArray($joinColumn);
|
||||||
}
|
}
|
||||||
@ -374,43 +291,43 @@ 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 = $this->_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 MappingException::propertyTypeIsRequired($className, $property->getName());
|
throw MappingException::propertyTypeIsRequired($className, $property->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapping = $this->columnToArray($property->getName(), $columnAnnot);
|
$mapping = $this->columnToArray($property->getName(), $columnAnnot);
|
||||||
|
|
||||||
if ($idAnnot = $this->_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 = $this->_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));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Version')) {
|
if ($this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Version')) {
|
||||||
$metadata->setVersionMapping($mapping);
|
$metadata->setVersionMapping($mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
$metadata->mapField($mapping);
|
$metadata->mapField($mapping);
|
||||||
|
|
||||||
// Check for SequenceGenerator/TableGenerator definition
|
// Check for SequenceGenerator/TableGenerator definition
|
||||||
if ($seqGeneratorAnnot = $this->_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 ($this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) {
|
} else if ($this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) {
|
||||||
throw MappingException::tableIdGeneratorNotImplemented($className);
|
throw MappingException::tableIdGeneratorNotImplemented($className);
|
||||||
} else if ($customGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\CustomIdGenerator')) {
|
} else if ($customGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\CustomIdGenerator')) {
|
||||||
$metadata->setCustomGeneratorDefinition(array(
|
$metadata->setCustomGeneratorDefinition(array(
|
||||||
'class' => $customGeneratorAnnot->class
|
'class' => $customGeneratorAnnot->class
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) {
|
} else if ($oneToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) {
|
||||||
if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
|
if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
|
||||||
$mapping['id'] = true;
|
$mapping['id'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,7 +339,7 @@ class AnnotationDriver implements Driver
|
|||||||
$mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
|
$mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
|
||||||
$mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnot->fetch);
|
$mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnot->fetch);
|
||||||
$metadata->mapOneToOne($mapping);
|
$metadata->mapOneToOne($mapping);
|
||||||
} else if ($oneToManyAnnot = $this->_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;
|
||||||
@ -430,13 +347,13 @@ class AnnotationDriver implements Driver
|
|||||||
$mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
|
$mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
|
||||||
$mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnot->fetch);
|
$mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnot->fetch);
|
||||||
|
|
||||||
if ($orderByAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) {
|
if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) {
|
||||||
$mapping['orderBy'] = $orderByAnnot->value;
|
$mapping['orderBy'] = $orderByAnnot->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$metadata->mapOneToMany($mapping);
|
$metadata->mapOneToMany($mapping);
|
||||||
} else if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToOne')) {
|
} else if ($manyToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToOne')) {
|
||||||
if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
|
if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
|
||||||
$mapping['id'] = true;
|
$mapping['id'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,10 +363,10 @@ class AnnotationDriver implements Driver
|
|||||||
$mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
|
$mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
|
||||||
$mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnot->fetch);
|
$mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnot->fetch);
|
||||||
$metadata->mapManyToOne($mapping);
|
$metadata->mapManyToOne($mapping);
|
||||||
} else if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) {
|
} else if ($manyToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) {
|
||||||
$joinTable = array();
|
$joinTable = array();
|
||||||
|
|
||||||
if ($joinTableAnnot = $this->_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
|
||||||
@ -473,7 +390,7 @@ class AnnotationDriver implements Driver
|
|||||||
$mapping['orphanRemoval'] = $manyToManyAnnot->orphanRemoval;
|
$mapping['orphanRemoval'] = $manyToManyAnnot->orphanRemoval;
|
||||||
$mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnot->fetch);
|
$mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnot->fetch);
|
||||||
|
|
||||||
if ($orderByAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) {
|
if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) {
|
||||||
$mapping['orderBy'] = $orderByAnnot->value;
|
$mapping['orderBy'] = $orderByAnnot->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,7 +439,6 @@ class AnnotationDriver implements Driver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$attributeOverrides = array();
|
|
||||||
// Evaluate AttributeOverrides annotation
|
// Evaluate AttributeOverrides annotation
|
||||||
if (isset($classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides'])) {
|
if (isset($classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides'])) {
|
||||||
$attributeOverridesAnnot = $classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides'];
|
$attributeOverridesAnnot = $classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides'];
|
||||||
@ -534,10 +450,11 @@ class AnnotationDriver implements Driver
|
|||||||
|
|
||||||
// Evaluate @HasLifecycleCallbacks annotation
|
// Evaluate @HasLifecycleCallbacks annotation
|
||||||
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
|
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
|
||||||
|
/* @var $method \ReflectionMethod */
|
||||||
foreach ($class->getMethods() as $method) {
|
foreach ($class->getMethods() as $method) {
|
||||||
// filter for the declaring class only, callbacks from parents will already be registered.
|
// filter for the declaring class only, callbacks from parents will already be registered.
|
||||||
if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
|
if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
|
||||||
$annotations = $this->_reader->getMethodAnnotations($method);
|
$annotations = $this->reader->getMethodAnnotations($method);
|
||||||
|
|
||||||
if ($annotations && is_numeric(key($annotations))) {
|
if ($annotations && is_numeric(key($annotations))) {
|
||||||
foreach ($annotations as $annot) {
|
foreach ($annotations as $annot) {
|
||||||
@ -581,90 +498,6 @@ class AnnotationDriver implements Driver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the class with the specified name is transient. Only non-transient
|
|
||||||
* classes, that is entities and mapped superclasses, should have their metadata loaded.
|
|
||||||
* A class is non-transient if it is annotated with either @Entity or
|
|
||||||
* @MappedSuperclass in the class doc block.
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function isTransient($className)
|
|
||||||
{
|
|
||||||
$classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className));
|
|
||||||
|
|
||||||
if ($classAnnotations && is_numeric(key($classAnnotations))) {
|
|
||||||
foreach ($classAnnotations as $annot) {
|
|
||||||
if ($annot instanceof \Doctrine\ORM\Mapping\Entity) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($annot instanceof \Doctrine\ORM\Mapping\MappedSuperclass) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) &&
|
|
||||||
! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getAllClassNames()
|
|
||||||
{
|
|
||||||
if ($this->_classNames !== null) {
|
|
||||||
return $this->_classNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! $this->_paths) {
|
|
||||||
throw MappingException::pathRequired();
|
|
||||||
}
|
|
||||||
|
|
||||||
$classes = array();
|
|
||||||
$includedFiles = array();
|
|
||||||
|
|
||||||
foreach ($this->_paths as $path) {
|
|
||||||
if ( ! is_dir($path)) {
|
|
||||||
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$iterator = new \RegexIterator(
|
|
||||||
new \RecursiveIteratorIterator(
|
|
||||||
new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS),
|
|
||||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
|
||||||
),
|
|
||||||
'/^.+' . str_replace('.', '\.', $this->_fileExtension) . '$/i',
|
|
||||||
\RecursiveRegexIterator::GET_MATCH
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($iterator as $file) {
|
|
||||||
$sourceFile = realpath($file[0]);
|
|
||||||
|
|
||||||
require_once $sourceFile;
|
|
||||||
|
|
||||||
$includedFiles[] = $sourceFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$declared = get_declared_classes();
|
|
||||||
|
|
||||||
foreach ($declared as $className) {
|
|
||||||
$rc = new \ReflectionClass($className);
|
|
||||||
$sourceFile = $rc->getFileName();
|
|
||||||
if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) {
|
|
||||||
$classes[] = $className;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_classNames = $classes;
|
|
||||||
|
|
||||||
return $classes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to resolve the fetch mode.
|
* Attempts to resolve the fetch mode.
|
||||||
*
|
*
|
||||||
@ -745,8 +578,8 @@ class AnnotationDriver implements Driver
|
|||||||
{
|
{
|
||||||
if ($reader == null) {
|
if ($reader == null) {
|
||||||
$reader = new AnnotationReader();
|
$reader = new AnnotationReader();
|
||||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new self($reader, $paths);
|
return new self($reader, $paths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,13 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\Common\Cache\ArrayCache,
|
use Doctrine\DBAL\Schema\AbstractSchemaManager,
|
||||||
Doctrine\Common\Annotations\AnnotationReader,
|
|
||||||
Doctrine\DBAL\Schema\AbstractSchemaManager,
|
|
||||||
Doctrine\DBAL\Schema\SchemaException,
|
Doctrine\DBAL\Schema\SchemaException,
|
||||||
|
Doctrine\Common\Persistence\Mapping\Driver\MappingDriver,
|
||||||
|
Doctrine\Common\Persistence\Mapping\ClassMetadata,
|
||||||
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
||||||
Doctrine\ORM\Mapping\MappingException,
|
Doctrine\Common\Util\Inflector,
|
||||||
Doctrine\Common\Util\Inflector;
|
Doctrine\ORM\Mapping\MappingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DatabaseDriver reverse engineers the mapping metadata from a database.
|
* The DatabaseDriver reverse engineers the mapping metadata from a database.
|
||||||
@ -37,7 +37,7 @@ use Doctrine\Common\Cache\ArrayCache,
|
|||||||
* @author Jonathan Wage <jonwage@gmail.com>
|
* @author Jonathan Wage <jonwage@gmail.com>
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||||
*/
|
*/
|
||||||
class DatabaseDriver implements Driver
|
class DatabaseDriver implements MappingDriver
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var AbstractSchemaManager
|
* @var AbstractSchemaManager
|
||||||
@ -74,10 +74,8 @@ class DatabaseDriver implements Driver
|
|||||||
private $namespace;
|
private $namespace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
|
|
||||||
* docblock annotations.
|
|
||||||
*
|
*
|
||||||
* @param AnnotationReader $reader The AnnotationReader to use.
|
* @param AbstractSchemaManager $schemaManager
|
||||||
*/
|
*/
|
||||||
public function __construct(AbstractSchemaManager $schemaManager)
|
public function __construct(AbstractSchemaManager $schemaManager)
|
||||||
{
|
{
|
||||||
@ -118,7 +116,7 @@ class DatabaseDriver implements Driver
|
|||||||
|
|
||||||
$this->tables = $this->manyToManyTables = $this->classToTableNames = array();
|
$this->tables = $this->manyToManyTables = $this->classToTableNames = array();
|
||||||
foreach ($tables as $tableName => $table) {
|
foreach ($tables as $tableName => $table) {
|
||||||
/* @var $table Table */
|
/* @var $table \Doctrine\DBAL\Schema\Table */
|
||||||
if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||||
$foreignKeys = $table->getForeignKeys();
|
$foreignKeys = $table->getForeignKeys();
|
||||||
} else {
|
} else {
|
||||||
@ -154,9 +152,9 @@ class DatabaseDriver implements Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||||
{
|
{
|
||||||
$this->reverseEngineerMappingFromDatabase();
|
$this->reverseEngineerMappingFromDatabase();
|
||||||
|
|
||||||
@ -320,7 +318,7 @@ class DatabaseDriver implements Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function isTransient($className)
|
public function isTransient($className)
|
||||||
{
|
{
|
||||||
@ -328,11 +326,7 @@ class DatabaseDriver implements Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all the class names supported by this driver.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* IMPORTANT: This method must return an array of class not tables names.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function getAllClassNames()
|
public function getAllClassNames()
|
||||||
{
|
{
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* 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 MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contract for metadata drivers.
|
|
||||||
*
|
|
||||||
* @since 2.0
|
|
||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
||||||
* @todo Rename: MetadataDriver or MappingDriver
|
|
||||||
*/
|
|
||||||
interface Driver
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Loads the metadata for the specified class into the provided container.
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @param ClassMetadataInfo $metadata
|
|
||||||
*/
|
|
||||||
function loadMetadataForClass($className, ClassMetadataInfo $metadata);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the names of all mapped classes known to this driver.
|
|
||||||
*
|
|
||||||
* @return array The names of all mapped classes known to this driver.
|
|
||||||
*/
|
|
||||||
function getAllClassNames();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the class with the specified name should have its metadata loaded.
|
|
||||||
* This is only the case if it is either mapped as an Entity or a
|
|
||||||
* MappedSuperclass.
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
function isTransient($className);
|
|
||||||
}
|
|
@ -19,8 +19,9 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\Driver\Driver,
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver,
|
||||||
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain,
|
||||||
|
Doctrine\Common\Persistence\Mapping\ClassMetadata,
|
||||||
Doctrine\ORM\Mapping\MappingException;
|
Doctrine\ORM\Mapping\MappingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,26 +33,20 @@ use Doctrine\ORM\Mapping\Driver\Driver,
|
|||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
* @author Roman Borschel <roman@code-factory.org>
|
||||||
* @todo Rename: MappingDriverChain or MetadataDriverChain
|
|
||||||
*/
|
*/
|
||||||
class DriverChain implements Driver
|
class DriverChain extends MappingDriverChain
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $drivers = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default driver
|
* The default driver
|
||||||
*
|
*
|
||||||
* @var Driver
|
* @var MappingDriver
|
||||||
*/
|
*/
|
||||||
private $defaultDriver;
|
private $defaultDriver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default driver.
|
* Get the default driver.
|
||||||
*
|
*
|
||||||
* @return Driver
|
* @return MappingDriver|null
|
||||||
*/
|
*/
|
||||||
public function getDefaultDriver()
|
public function getDefaultDriver()
|
||||||
{
|
{
|
||||||
@ -61,43 +56,21 @@ class DriverChain implements Driver
|
|||||||
/**
|
/**
|
||||||
* Set the default driver.
|
* Set the default driver.
|
||||||
*
|
*
|
||||||
* @param Driver $driver
|
* @param MappingDriver $driver
|
||||||
*/
|
*/
|
||||||
public function setDefaultDriver(Driver $driver)
|
public function setDefaultDriver(MappingDriver $driver)
|
||||||
{
|
{
|
||||||
$this->defaultDriver = $driver;
|
$this->defaultDriver = $driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a nested driver.
|
* {@inheritDoc}
|
||||||
*
|
* @throws MappingException
|
||||||
* @param Driver $nestedDriver
|
|
||||||
* @param string $namespace
|
|
||||||
*/
|
*/
|
||||||
public function addDriver(Driver $nestedDriver, $namespace)
|
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||||
{
|
{
|
||||||
$this->drivers[$namespace] = $nestedDriver;
|
/* @var $driver MappingDriver */
|
||||||
}
|
foreach ($this->getDrivers() as $namespace => $driver) {
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the array of nested drivers.
|
|
||||||
*
|
|
||||||
* @return array $drivers
|
|
||||||
*/
|
|
||||||
public function getDrivers()
|
|
||||||
{
|
|
||||||
return $this->drivers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the metadata for the specified class into the provided container.
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @param ClassMetadataInfo $metadata
|
|
||||||
*/
|
|
||||||
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
|
||||||
{
|
|
||||||
foreach ($this->drivers as $namespace => $driver) {
|
|
||||||
if (strpos($className, $namespace) === 0) {
|
if (strpos($className, $namespace) === 0) {
|
||||||
$driver->loadMetadataForClass($className, $metadata);
|
$driver->loadMetadataForClass($className, $metadata);
|
||||||
return;
|
return;
|
||||||
@ -113,50 +86,18 @@ class DriverChain implements Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the names of all mapped classes known to this driver.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @return array The names of all mapped classes known to this driver.
|
|
||||||
*/
|
|
||||||
public function getAllClassNames()
|
|
||||||
{
|
|
||||||
$classNames = array();
|
|
||||||
$driverClasses = array();
|
|
||||||
foreach ($this->drivers as $namespace => $driver) {
|
|
||||||
$oid = spl_object_hash($driver);
|
|
||||||
if (!isset($driverClasses[$oid])) {
|
|
||||||
$driverClasses[$oid] = $driver->getAllClassNames();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($driverClasses[$oid] as $className) {
|
|
||||||
if (strpos($className, $namespace) === 0) {
|
|
||||||
$classNames[$className] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array_keys($classNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the class with the specified name should have its metadata loaded.
|
|
||||||
*
|
|
||||||
* This is only the case for non-transient classes either mapped as an Entity or MappedSuperclass.
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @return boolean
|
|
||||||
*/
|
*/
|
||||||
public function isTransient($className)
|
public function isTransient($className)
|
||||||
{
|
{
|
||||||
foreach ($this->drivers as $namespace => $driver) {
|
if (!parent::isTransient($className)) {
|
||||||
if (strpos($className, $namespace) === 0) {
|
return false;
|
||||||
return $driver->isTransient($className);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->defaultDriver !== null) {
|
if ($this->defaultDriver !== null) {
|
||||||
return $this->defaultDriver->isTransient($className);
|
return $this->defaultDriver->isTransient($className);
|
||||||
}
|
}
|
||||||
|
|
||||||
// class isTransient, i.e. not an entity or mapped superclass
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,16 +19,11 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\Common\Cache\ArrayCache,
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata,
|
||||||
Doctrine\Common\Annotations\AnnotationReader,
|
Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
|
||||||
Doctrine\DBAL\Schema\AbstractSchemaManager,
|
|
||||||
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
|
||||||
Doctrine\ORM\Mapping\MappingException,
|
|
||||||
Doctrine\Common\Util\Inflector,
|
|
||||||
Doctrine\ORM\Mapping\Driver\AbstractFileDriver;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The PHPDriver includes php files which just populate ClassMetadataInfo
|
* The PHPDriver includes php files which just populate ClassMetadata
|
||||||
* instances with plain php code
|
* instances with plain php code
|
||||||
*
|
*
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||||
@ -39,31 +34,45 @@ use Doctrine\Common\Cache\ArrayCache,
|
|||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
* @author Roman Borschel <roman@code-factory.org>
|
||||||
* @todo Rename: PHPDriver
|
|
||||||
*/
|
*/
|
||||||
class PHPDriver extends AbstractFileDriver
|
class PHPDriver extends FileDriver
|
||||||
{
|
{
|
||||||
|
const DEFAULT_FILE_EXTENSION = '.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
*
|
||||||
|
* @var ClassMetadata
|
||||||
*/
|
*/
|
||||||
protected $_fileExtension = '.php';
|
|
||||||
protected $_metadata;
|
protected $_metadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION)
|
||||||
{
|
{
|
||||||
$this->_metadata = $metadata;
|
parent::__construct($locator, $fileExtension);
|
||||||
$this->_loadMappingFile($this->_findMappingFile($className));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
protected function _loadMappingFile($file)
|
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||||
{
|
{
|
||||||
|
$this->_metadata = $metadata;
|
||||||
|
$this->getElement($className);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
protected function loadMappingFile($file)
|
||||||
|
{
|
||||||
|
$result = array();
|
||||||
$metadata = $this->_metadata;
|
$metadata = $this->_metadata;
|
||||||
include $file;
|
include $file;
|
||||||
|
// @todo cannot assume that the only loaded metadata is $metadata. Some
|
||||||
|
// decision about the preferred approach should be taken
|
||||||
|
$result[$metadata->getName()] = $metadata;
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\MappingException;
|
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XmlDriver that additionally looks for mapping information in a global file.
|
* XmlDriver that additionally looks for mapping information in a global file.
|
||||||
@ -30,147 +30,14 @@ use Doctrine\ORM\Mapping\MappingException;
|
|||||||
*/
|
*/
|
||||||
class SimplifiedXmlDriver extends XmlDriver
|
class SimplifiedXmlDriver extends XmlDriver
|
||||||
{
|
{
|
||||||
protected $_prefixes = array();
|
const DEFAULT_FILE_EXTENSION = '.orm.xml';
|
||||||
protected $_globalBasename;
|
|
||||||
protected $_classCache;
|
|
||||||
protected $_fileExtension = '.orm.xml';
|
|
||||||
|
|
||||||
public function __construct($prefixes)
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION)
|
||||||
{
|
{
|
||||||
$this->addNamespacePrefixes($prefixes);
|
$locator = new SymfonyFileLocator((array) $prefixes, $fileExtension);
|
||||||
}
|
parent::__construct($locator, $fileExtension);
|
||||||
|
|
||||||
public function setGlobalBasename($file)
|
|
||||||
{
|
|
||||||
$this->_globalBasename = $file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getGlobalBasename()
|
|
||||||
{
|
|
||||||
return $this->_globalBasename;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addNamespacePrefixes($prefixes)
|
|
||||||
{
|
|
||||||
$this->_prefixes = array_merge($this->_prefixes, $prefixes);
|
|
||||||
$this->addPaths(array_flip($prefixes));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNamespacePrefixes()
|
|
||||||
{
|
|
||||||
return $this->_prefixes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isTransient($className)
|
|
||||||
{
|
|
||||||
if (null === $this->_classCache) {
|
|
||||||
$this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The mapping is defined in the global mapping file
|
|
||||||
if (isset($this->_classCache[$className])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->_findMappingFile($className);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
} catch (MappingException $e) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAllClassNames()
|
|
||||||
{
|
|
||||||
if (null === $this->_classCache) {
|
|
||||||
$this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
$classes = array();
|
|
||||||
|
|
||||||
if ($this->_paths) {
|
|
||||||
foreach ((array) $this->_paths as $path) {
|
|
||||||
if (!is_dir($path)) {
|
|
||||||
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
|
||||||
new \RecursiveDirectoryIterator($path),
|
|
||||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($iterator as $file) {
|
|
||||||
$fileName = $file->getBasename($this->_fileExtension);
|
|
||||||
|
|
||||||
if ($fileName == $file->getBasename() || $fileName == $this->_globalBasename) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: All files found here means classes are not transient!
|
|
||||||
if (isset($this->_prefixes[$path])) {
|
|
||||||
$classes[] = $this->_prefixes[$path].'\\'.str_replace('.', '\\', $fileName);
|
|
||||||
} else {
|
|
||||||
$classes[] = str_replace('.', '\\', $fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_merge($classes, array_keys($this->_classCache));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getElement($className)
|
|
||||||
{
|
|
||||||
if (null === $this->_classCache) {
|
|
||||||
$this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->_classCache[$className])) {
|
|
||||||
$this->_classCache[$className] = parent::getElement($className);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_classCache[$className];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function initialize()
|
|
||||||
{
|
|
||||||
$this->_classCache = array();
|
|
||||||
if (null !== $this->_globalBasename) {
|
|
||||||
foreach ($this->_paths as $path) {
|
|
||||||
if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) {
|
|
||||||
$this->_classCache = array_merge($this->_classCache, $this->_loadMappingFile($file));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _findMappingFile($className)
|
|
||||||
{
|
|
||||||
$defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension;
|
|
||||||
foreach ($this->_paths as $path) {
|
|
||||||
if (!isset($this->_prefixes[$path])) {
|
|
||||||
if (is_file($path.DIRECTORY_SEPARATOR.$defaultFileName)) {
|
|
||||||
return $path.DIRECTORY_SEPARATOR.$defaultFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$prefix = $this->_prefixes[$path];
|
|
||||||
|
|
||||||
if (0 !== strpos($className, $prefix.'\\')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = $path.'/'.strtr(substr($className, strlen($prefix)+1), '\\', '.').$this->_fileExtension;
|
|
||||||
if (is_file($filename)) {
|
|
||||||
return $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw MappingException::mappingFileNotFound($className, $filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\') + 1).$this->_fileExtension);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\MappingException;
|
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YamlDriver that additionally looks for mapping information in a global file.
|
* YamlDriver that additionally looks for mapping information in a global file.
|
||||||
@ -30,152 +30,14 @@ use Doctrine\ORM\Mapping\MappingException;
|
|||||||
*/
|
*/
|
||||||
class SimplifiedYamlDriver extends YamlDriver
|
class SimplifiedYamlDriver extends YamlDriver
|
||||||
{
|
{
|
||||||
protected $_prefixes = array();
|
const DEFAULT_FILE_EXTENSION = '.orm.yml';
|
||||||
protected $_globalBasename;
|
|
||||||
protected $_classCache;
|
|
||||||
protected $_fileExtension = '.orm.yml';
|
|
||||||
|
|
||||||
public function __construct($prefixes)
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION)
|
||||||
{
|
{
|
||||||
$this->addNamespacePrefixes($prefixes);
|
$locator = new SymfonyFileLocator((array) $prefixes, $fileExtension);
|
||||||
}
|
parent::__construct($locator, $fileExtension);
|
||||||
|
|
||||||
public function setGlobalBasename($file)
|
|
||||||
{
|
|
||||||
$this->_globalBasename = $file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getGlobalBasename()
|
|
||||||
{
|
|
||||||
return $this->_globalBasename;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addNamespacePrefixes($prefixes)
|
|
||||||
{
|
|
||||||
$this->_prefixes = array_merge($this->_prefixes, $prefixes);
|
|
||||||
$this->addPaths(array_flip($prefixes));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addNamespacePrefix($prefix, $path)
|
|
||||||
{
|
|
||||||
$this->_prefixes[$path] = $prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNamespacePrefixes()
|
|
||||||
{
|
|
||||||
return $this->_prefixes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isTransient($className)
|
|
||||||
{
|
|
||||||
if (null === $this->_classCache) {
|
|
||||||
$this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The mapping is defined in the global mapping file
|
|
||||||
if (isset($this->_classCache[$className])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->_findMappingFile($className);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
} catch (MappingException $e) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAllClassNames()
|
|
||||||
{
|
|
||||||
if (null === $this->_classCache) {
|
|
||||||
$this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
$classes = array();
|
|
||||||
|
|
||||||
if ($this->_paths) {
|
|
||||||
foreach ((array) $this->_paths as $path) {
|
|
||||||
if (!is_dir($path)) {
|
|
||||||
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
|
||||||
new \RecursiveDirectoryIterator($path),
|
|
||||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($iterator as $file) {
|
|
||||||
$fileName = $file->getBasename($this->_fileExtension);
|
|
||||||
|
|
||||||
if ($fileName == $file->getBasename() || $fileName == $this->_globalBasename) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: All files found here means classes are not transient!
|
|
||||||
if (isset($this->_prefixes[$path])) {
|
|
||||||
$classes[] = $this->_prefixes[$path].'\\'.str_replace('.', '\\', $fileName);
|
|
||||||
} else {
|
|
||||||
$classes[] = str_replace('.', '\\', $fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_merge($classes, array_keys($this->_classCache));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getElement($className)
|
|
||||||
{
|
|
||||||
if (null === $this->_classCache) {
|
|
||||||
$this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->_classCache[$className])) {
|
|
||||||
$this->_classCache[$className] = parent::getElement($className);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_classCache[$className];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function initialize()
|
|
||||||
{
|
|
||||||
$this->_classCache = array();
|
|
||||||
if (null !== $this->_globalBasename) {
|
|
||||||
foreach ($this->_paths as $path) {
|
|
||||||
if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) {
|
|
||||||
$this->_classCache = array_merge($this->_classCache, $this->_loadMappingFile($file));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _findMappingFile($className)
|
|
||||||
{
|
|
||||||
$defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension;
|
|
||||||
foreach ($this->_paths as $path) {
|
|
||||||
if (!isset($this->_prefixes[$path])) {
|
|
||||||
if (is_file($path.DIRECTORY_SEPARATOR.$defaultFileName)) {
|
|
||||||
return $path.DIRECTORY_SEPARATOR.$defaultFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$prefix = $this->_prefixes[$path];
|
|
||||||
|
|
||||||
if (0 !== strpos($className, $prefix.'\\')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = $path.'/'.strtr(substr($className, strlen($prefix)+1), '\\', '.').$this->_fileExtension;
|
|
||||||
if (is_file($filename)) {
|
|
||||||
return $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw MappingException::mappingFileNotFound($className, $filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\') + 1).$this->_fileExtension);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata,
|
||||||
Doctrine\ORM\Mapping\MappingException;
|
Doctrine\Common\Persistence\Mapping\Driver\MappingDriver,
|
||||||
|
Doctrine\ORM\Mapping\MappingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The StaticPHPDriver calls a static loadMetadata() method on your entity
|
* The StaticPHPDriver calls a static loadMetadata() method on your entity
|
||||||
@ -34,7 +35,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
|||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
* @author Roman Borschel <roman@code-factory.org>
|
||||||
*/
|
*/
|
||||||
class StaticPHPDriver implements Driver
|
class StaticPHPDriver implements MappingDriver
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Paths of entity directories.
|
* Paths of entity directories.
|
||||||
@ -57,27 +58,36 @@ class StaticPHPDriver implements Driver
|
|||||||
*/
|
*/
|
||||||
private $_fileExtension = '.php';
|
private $_fileExtension = '.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $paths Paths where to look for mappings
|
||||||
|
*/
|
||||||
public function __construct($paths)
|
public function __construct($paths)
|
||||||
{
|
{
|
||||||
$this->addPaths((array) $paths);
|
$this->addPaths((array) $paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add paths where to look for mappings
|
||||||
|
*
|
||||||
|
* @param array $paths
|
||||||
|
*/
|
||||||
public function addPaths(array $paths)
|
public function addPaths(array $paths)
|
||||||
{
|
{
|
||||||
$this->_paths = array_unique(array_merge($this->_paths, $paths));
|
$this->_paths = array_unique(array_merge($this->_paths, $paths));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||||
{
|
{
|
||||||
call_user_func_array(array($className, 'loadMetadata'), array($metadata));
|
call_user_func_array(array($className, 'loadMetadata'), array($metadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* @todo Same code exists in AnnotationDriver, should we re-use it somehow or not worry about it?
|
|
||||||
*/
|
*/
|
||||||
public function getAllClassNames()
|
public function getAllClassNames()
|
||||||
{
|
{
|
||||||
@ -98,8 +108,8 @@ class StaticPHPDriver implements Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
$iterator = new \RecursiveIteratorIterator(
|
||||||
new \RecursiveDirectoryIterator($path),
|
new \RecursiveDirectoryIterator($path),
|
||||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
\RecursiveIteratorIterator::LEAVES_ONLY
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($iterator as $file) {
|
foreach ($iterator as $file) {
|
||||||
@ -129,7 +139,7 @@ class StaticPHPDriver implements Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function isTransient($className)
|
public function isTransient($className)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use SimpleXMLElement,
|
use SimpleXMLElement,
|
||||||
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
Doctrine\Common\Persistence\Mapping\Driver\FileDriver,
|
||||||
|
Doctrine\Common\Persistence\Mapping\ClassMetadata,
|
||||||
Doctrine\ORM\Mapping\MappingException;
|
Doctrine\ORM\Mapping\MappingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,18 +35,25 @@ use SimpleXMLElement,
|
|||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
* @author Roman Borschel <roman@code-factory.org>
|
||||||
*/
|
*/
|
||||||
class XmlDriver extends AbstractFileDriver
|
class XmlDriver extends FileDriver
|
||||||
{
|
{
|
||||||
/**
|
const DEFAULT_FILE_EXTENSION = '.dcm.xml';
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $_fileExtension = '.dcm.xml';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION)
|
||||||
{
|
{
|
||||||
|
parent::__construct($locator, $fileExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||||
|
{
|
||||||
|
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
|
||||||
|
/* @var $xmlRoot SimpleXMLElement */
|
||||||
$xmlRoot = $this->getElement($className);
|
$xmlRoot = $this->getElement($className);
|
||||||
|
|
||||||
if ($xmlRoot->getName() == 'entity') {
|
if ($xmlRoot->getName() == 'entity') {
|
||||||
@ -544,13 +552,14 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
/**
|
/**
|
||||||
* Parses (nested) option elements.
|
* Parses (nested) option elements.
|
||||||
*
|
*
|
||||||
* @param $options The XML element.
|
* @param SimpleXMLElement $options the XML element.
|
||||||
* @return array The options array.
|
* @return array The options array.
|
||||||
*/
|
*/
|
||||||
private function _parseOptions(SimpleXMLElement $options)
|
private function _parseOptions(SimpleXMLElement $options)
|
||||||
{
|
{
|
||||||
$array = array();
|
$array = array();
|
||||||
|
|
||||||
|
/* @var $option SimpleXMLElement */
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
if ($option->count()) {
|
if ($option->count()) {
|
||||||
$value = $this->_parseOptions($option->children());
|
$value = $this->_parseOptions($option->children());
|
||||||
@ -574,7 +583,7 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
* Constructs a joinColumn mapping array based on the information
|
* Constructs a joinColumn mapping array based on the information
|
||||||
* found in the given SimpleXMLElement.
|
* found in the given SimpleXMLElement.
|
||||||
*
|
*
|
||||||
* @param $joinColumnElement The XML element.
|
* @param SimpleXMLElement $joinColumnElement the XML element.
|
||||||
* @return array The mapping array.
|
* @return array The mapping array.
|
||||||
*/
|
*/
|
||||||
private function joinColumnToArray(SimpleXMLElement $joinColumnElement)
|
private function joinColumnToArray(SimpleXMLElement $joinColumnElement)
|
||||||
@ -612,43 +621,43 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
private function columnToArray(SimpleXMLElement $fieldMapping)
|
private function columnToArray(SimpleXMLElement $fieldMapping)
|
||||||
{
|
{
|
||||||
$mapping = array(
|
$mapping = array(
|
||||||
'fieldName' => (string)$fieldMapping['name'],
|
'fieldName' => (string) $fieldMapping['name'],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($fieldMapping['type'])) {
|
if (isset($fieldMapping['type'])) {
|
||||||
$mapping['type'] = (string)$fieldMapping['type'];
|
$mapping['type'] = (string) $fieldMapping['type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fieldMapping['column'])) {
|
if (isset($fieldMapping['column'])) {
|
||||||
$mapping['columnName'] = (string)$fieldMapping['column'];
|
$mapping['columnName'] = (string) $fieldMapping['column'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fieldMapping['length'])) {
|
if (isset($fieldMapping['length'])) {
|
||||||
$mapping['length'] = (int)$fieldMapping['length'];
|
$mapping['length'] = (int) $fieldMapping['length'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fieldMapping['precision'])) {
|
if (isset($fieldMapping['precision'])) {
|
||||||
$mapping['precision'] = (int)$fieldMapping['precision'];
|
$mapping['precision'] = (int) $fieldMapping['precision'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fieldMapping['scale'])) {
|
if (isset($fieldMapping['scale'])) {
|
||||||
$mapping['scale'] = (int)$fieldMapping['scale'];
|
$mapping['scale'] = (int) $fieldMapping['scale'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fieldMapping['unique'])) {
|
if (isset($fieldMapping['unique'])) {
|
||||||
$mapping['unique'] = ((string)$fieldMapping['unique'] == "false") ? false : true;
|
$mapping['unique'] = ((string) $fieldMapping['unique'] == "false") ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fieldMapping['nullable'])) {
|
if (isset($fieldMapping['nullable'])) {
|
||||||
$mapping['nullable'] = ((string)$fieldMapping['nullable'] == "false") ? false : true;
|
$mapping['nullable'] = ((string) $fieldMapping['nullable'] == "false") ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
|
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
|
||||||
$metadata->setVersionMapping($mapping);
|
$mapping['version'] = $fieldMapping['version'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fieldMapping['column-definition'])) {
|
if (isset($fieldMapping['column-definition'])) {
|
||||||
$mapping['columnDefinition'] = (string)$fieldMapping['column-definition'];
|
$mapping['columnDefinition'] = (string) $fieldMapping['column-definition'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fieldMapping->options)) {
|
if (isset($fieldMapping->options)) {
|
||||||
@ -661,12 +670,13 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
/**
|
/**
|
||||||
* Gathers a list of cascade options found in the given cascade element.
|
* Gathers a list of cascade options found in the given cascade element.
|
||||||
*
|
*
|
||||||
* @param $cascadeElement The cascade element.
|
* @param SimpleXMLElement $cascadeElement the cascade element.
|
||||||
* @return array The list of cascade options.
|
* @return array The list of cascade options.
|
||||||
*/
|
*/
|
||||||
private function _getCascadeMappings($cascadeElement)
|
private function _getCascadeMappings($cascadeElement)
|
||||||
{
|
{
|
||||||
$cascades = array();
|
$cascades = array();
|
||||||
|
/* @var $action SimpleXmlElement */
|
||||||
foreach ($cascadeElement->children() as $action) {
|
foreach ($cascadeElement->children() as $action) {
|
||||||
// According to the JPA specifications, XML uses "cascade-persist"
|
// According to the JPA specifications, XML uses "cascade-persist"
|
||||||
// instead of "persist". Here, both variations
|
// instead of "persist". Here, both variations
|
||||||
@ -679,9 +689,9 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
protected function _loadMappingFile($file)
|
protected function loadMappingFile($file)
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
$xmlElement = simplexml_load_file($file);
|
$xmlElement = simplexml_load_file($file);
|
||||||
|
@ -19,8 +19,10 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata,
|
||||||
Doctrine\ORM\Mapping\MappingException;
|
Doctrine\Common\Persistence\Mapping\Driver\FileDriver,
|
||||||
|
Doctrine\ORM\Mapping\MappingException,
|
||||||
|
Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The YamlDriver reads the mapping metadata from yaml schema files.
|
* The YamlDriver reads the mapping metadata from yaml schema files.
|
||||||
@ -31,18 +33,24 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
|||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
* @author Roman Borschel <roman@code-factory.org>
|
||||||
*/
|
*/
|
||||||
class YamlDriver extends AbstractFileDriver
|
class YamlDriver extends FileDriver
|
||||||
{
|
{
|
||||||
/**
|
const DEFAULT_FILE_EXTENSION = '.dcm.yml';
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $_fileExtension = '.dcm.yml';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION)
|
||||||
{
|
{
|
||||||
|
parent::__construct($locator, $fileExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||||
|
{
|
||||||
|
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
|
||||||
$element = $this->getElement($className);
|
$element = $this->getElement($className);
|
||||||
|
|
||||||
if ($element['type'] == 'entity') {
|
if ($element['type'] == 'entity') {
|
||||||
@ -319,9 +327,9 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
if (isset($oneToOneElement['joinColumn'])) {
|
if (isset($oneToOneElement['joinColumn'])) {
|
||||||
$joinColumns[] = $this->joinColumnToArray($oneToOneElement['joinColumn']);
|
$joinColumns[] = $this->joinColumnToArray($oneToOneElement['joinColumn']);
|
||||||
} else if (isset($oneToOneElement['joinColumns'])) {
|
} else if (isset($oneToOneElement['joinColumns'])) {
|
||||||
foreach ($oneToOneElement['joinColumns'] as $name => $joinColumnElement) {
|
foreach ($oneToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) {
|
||||||
if ( ! isset($joinColumnElement['name'])) {
|
if ( ! isset($joinColumnElement['name'])) {
|
||||||
$joinColumnElement['name'] = $name;
|
$joinColumnElement['name'] = $joinColumnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
$joinColumns[] = $this->joinColumnToArray($joinColumnElement);
|
$joinColumns[] = $this->joinColumnToArray($joinColumnElement);
|
||||||
@ -401,9 +409,9 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
if (isset($manyToOneElement['joinColumn'])) {
|
if (isset($manyToOneElement['joinColumn'])) {
|
||||||
$joinColumns[] = $this->joinColumnToArray($manyToOneElement['joinColumn']);
|
$joinColumns[] = $this->joinColumnToArray($manyToOneElement['joinColumn']);
|
||||||
} else if (isset($manyToOneElement['joinColumns'])) {
|
} else if (isset($manyToOneElement['joinColumns'])) {
|
||||||
foreach ($manyToOneElement['joinColumns'] as $name => $joinColumnElement) {
|
foreach ($manyToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) {
|
||||||
if ( ! isset($joinColumnElement['name'])) {
|
if ( ! isset($joinColumnElement['name'])) {
|
||||||
$joinColumnElement['name'] = $name;
|
$joinColumnElement['name'] = $joinColumnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
$joinColumns[] = $this->joinColumnToArray($joinColumnElement);
|
$joinColumns[] = $this->joinColumnToArray($joinColumnElement);
|
||||||
@ -445,17 +453,17 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
$joinTable['schema'] = $joinTableElement['schema'];
|
$joinTable['schema'] = $joinTableElement['schema'];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($joinTableElement['joinColumns'] as $name => $joinColumnElement) {
|
foreach ($joinTableElement['joinColumns'] as $joinColumnName => $joinColumnElement) {
|
||||||
if ( ! isset($joinColumnElement['name'])) {
|
if ( ! isset($joinColumnElement['name'])) {
|
||||||
$joinColumnElement['name'] = $name;
|
$joinColumnElement['name'] = $joinColumnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
|
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($joinTableElement['inverseJoinColumns'] as $name => $joinColumnElement) {
|
foreach ($joinTableElement['inverseJoinColumns'] as $joinColumnName => $joinColumnElement) {
|
||||||
if ( ! isset($joinColumnElement['name'])) {
|
if ( ! isset($joinColumnElement['name'])) {
|
||||||
$joinColumnElement['name'] = $name;
|
$joinColumnElement['name'] = $joinColumnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
$joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
|
$joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
|
||||||
@ -564,7 +572,7 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
* Constructs a joinColumn mapping array based on the information
|
* Constructs a joinColumn mapping array based on the information
|
||||||
* found in the given join column element.
|
* found in the given join column element.
|
||||||
*
|
*
|
||||||
* @param $joinColumnElement The array join column element
|
* @param array $joinColumnElement The array join column element
|
||||||
* @return array The mapping array.
|
* @return array The mapping array.
|
||||||
*/
|
*/
|
||||||
private function joinColumnToArray($joinColumnElement)
|
private function joinColumnToArray($joinColumnElement)
|
||||||
@ -653,7 +661,7 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($column['version']) && $column['version']) {
|
if (isset($column['version']) && $column['version']) {
|
||||||
$metadata->setVersionMapping($mapping);
|
$mapping['version'] = $column['version'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($column['columnDefinition'])) {
|
if (isset($column['columnDefinition'])) {
|
||||||
@ -664,10 +672,10 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
protected function _loadMappingFile($file)
|
protected function loadMappingFile($file)
|
||||||
{
|
{
|
||||||
return \Symfony\Component\Yaml\Yaml::parse($file);
|
return Yaml::parse($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,11 +78,6 @@ class MappingException extends \Doctrine\ORM\ORMException
|
|||||||
return new self("No mapping file found named '$fileName' for class '$entityName'.");
|
return new self("No mapping file found named '$fileName' for class '$entityName'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function invalidMappingFile($entityName, $fileName)
|
|
||||||
{
|
|
||||||
return new self("Invalid mapping file '$fileName' for class '$entityName'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception for invalid property name override.
|
* Exception for invalid property name override.
|
||||||
*
|
*
|
||||||
|
@ -19,14 +19,10 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
|
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
|
||||||
|
|
||||||
use Symfony\Component\Console\Input\InputArgument,
|
use Symfony\Component\Console\Input\InputInterface,
|
||||||
Symfony\Component\Console\Input\InputOption,
|
|
||||||
Symfony\Component\Console\Input\InputInterface,
|
|
||||||
Symfony\Component\Console\Output\OutputInterface,
|
Symfony\Component\Console\Output\OutputInterface,
|
||||||
Symfony\Component\Console\Command\Command,
|
Symfony\Component\Console\Command\Command,
|
||||||
Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper,
|
Doctrine\ORM\Tools\SchemaTool;
|
||||||
Doctrine\ORM\Tools\SchemaTool,
|
|
||||||
Doctrine\ORM\Mapping\Driver\AbstractFileDriver;
|
|
||||||
|
|
||||||
abstract class AbstractCommand extends Command
|
abstract class AbstractCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\Mocks;
|
namespace Doctrine\Tests\Mocks;
|
||||||
|
|
||||||
class MetadataDriverMock implements \Doctrine\ORM\Mapping\Driver\Driver
|
class MetadataDriverMock implements \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver
|
||||||
{
|
{
|
||||||
public function loadMetadataForClass($className, \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
|
public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
public function testIsTransient()
|
public function testIsTransient()
|
||||||
{
|
{
|
||||||
$cmf = new ClassMetadataFactory();
|
$cmf = new ClassMetadataFactory();
|
||||||
$driver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
$driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||||
$driver->expects($this->at(0))
|
$driver->expects($this->at(0))
|
||||||
->method('isTransient')
|
->method('isTransient')
|
||||||
->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser'))
|
->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser'))
|
||||||
@ -136,7 +136,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
public function testIsTransientEntityNamespace()
|
public function testIsTransientEntityNamespace()
|
||||||
{
|
{
|
||||||
$cmf = new ClassMetadataFactory();
|
$cmf = new ClassMetadataFactory();
|
||||||
$driver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
$driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||||
$driver->expects($this->at(0))
|
$driver->expects($this->at(0))
|
||||||
->method('isTransient')
|
->method('isTransient')
|
||||||
->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser'))
|
->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser'))
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\ORM\Mapping;
|
namespace Doctrine\Tests\ORM\Mapping;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\Driver\Driver;
|
|
||||||
use Doctrine\ORM\Mapping\Driver\DriverChain;
|
use Doctrine\ORM\Mapping\Driver\DriverChain;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../TestInit.php';
|
require_once __DIR__ . '/../../TestInit.php';
|
||||||
@ -16,13 +15,13 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
|
|
||||||
$chain = new DriverChain();
|
$chain = new DriverChain();
|
||||||
|
|
||||||
$driver1 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
$driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||||
$driver1->expects($this->never())
|
$driver1->expects($this->never())
|
||||||
->method('loadMetadataForClass');
|
->method('loadMetadataForClass');
|
||||||
$driver1->expectS($this->never())
|
$driver1->expectS($this->never())
|
||||||
->method('isTransient');
|
->method('isTransient');
|
||||||
|
|
||||||
$driver2 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
$driver2 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||||
$driver2->expects($this->at(0))
|
$driver2->expects($this->at(0))
|
||||||
->method('loadMetadataForClass')
|
->method('loadMetadataForClass')
|
||||||
->with($this->equalTo($className), $this->equalTo($classMetadata));
|
->with($this->equalTo($className), $this->equalTo($classMetadata));
|
||||||
@ -57,12 +56,12 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
|
|
||||||
$chain = new DriverChain();
|
$chain = new DriverChain();
|
||||||
|
|
||||||
$driver1 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
$driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||||
$driver1->expects($this->once())
|
$driver1->expects($this->once())
|
||||||
->method('getAllClassNames')
|
->method('getAllClassNames')
|
||||||
->will($this->returnValue(array('Doctrine\Tests\Models\Company\Foo')));
|
->will($this->returnValue(array('Doctrine\Tests\Models\Company\Foo')));
|
||||||
|
|
||||||
$driver2 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
$driver2 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||||
$driver2->expects($this->once())
|
$driver2->expects($this->once())
|
||||||
->method('getAllClassNames')
|
->method('getAllClassNames')
|
||||||
->will($this->returnValue(array('Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz')));
|
->will($this->returnValue(array('Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz')));
|
||||||
@ -94,8 +93,8 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
*/
|
*/
|
||||||
public function testDefaultDriver()
|
public function testDefaultDriver()
|
||||||
{
|
{
|
||||||
$companyDriver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
$companyDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||||
$dafaultDriver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
$dafaultDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||||
$entityClassName = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
|
$entityClassName = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
|
||||||
$managerClassName = 'Doctrine\Tests\Models\Company\CompanyManager';
|
$managerClassName = 'Doctrine\Tests\Models\Company\CompanyManager';
|
||||||
$chain = new DriverChain();
|
$chain = new DriverChain();
|
||||||
|
@ -32,7 +32,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
|
|||||||
));
|
));
|
||||||
|
|
||||||
touch($filename = $this->dir.'/Foo'.$this->getFileExtension());
|
touch($filename = $this->dir.'/Foo'.$this->getFileExtension());
|
||||||
$this->assertEquals($filename, $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo')));
|
$this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFindMappingFileInSubnamespace()
|
public function testFindMappingFileInSubnamespace()
|
||||||
@ -42,13 +42,13 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
|
|||||||
));
|
));
|
||||||
|
|
||||||
touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension());
|
touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension());
|
||||||
$this->assertEquals($filename, $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo\Bar')));
|
$this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo\Bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFindMappingFileNamespacedFoundFileNotFound()
|
public function testFindMappingFileNamespacedFoundFileNotFound()
|
||||||
{
|
{
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
'Doctrine\ORM\Mapping\MappingException',
|
'Doctrine\Common\Persistence\Mapping\MappingException',
|
||||||
"No mapping file found named '".$this->dir."/Foo".$this->getFileExtension()."' for class 'MyNamespace\MySubnamespace\Entity\Foo'."
|
"No mapping file found named '".$this->dir."/Foo".$this->getFileExtension()."' for class 'MyNamespace\MySubnamespace\Entity\Foo'."
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -56,13 +56,13 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
|
|||||||
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo'));
|
$driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFindMappingNamespaceNotFound()
|
public function testFindMappingNamespaceNotFound()
|
||||||
{
|
{
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
'Doctrine\ORM\Mapping\MappingException',
|
'Doctrine\Common\Persistence\Mapping\MappingException',
|
||||||
"No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'."
|
"No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'."
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
|
|||||||
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->invoke($driver, '_findMappingFile', array('MyOtherNamespace\MySubnamespace\Entity\Foo'));
|
$driver->getLocator()->findMappingFile('MyOtherNamespace\MySubnamespace\Entity\Foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
@ -55,7 +55,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest
|
|||||||
/**
|
/**
|
||||||
* @group DDC-1468
|
* @group DDC-1468
|
||||||
*
|
*
|
||||||
* @expectedException Doctrine\ORM\Mapping\MappingException
|
* @expectedException Doctrine\Common\Persistence\Mapping\MappingException
|
||||||
* @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'.
|
* @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'.
|
||||||
*/
|
*/
|
||||||
public function testInvalidMappingFileException()
|
public function testInvalidMappingFileException()
|
||||||
@ -87,7 +87,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group DDC-889
|
* @group DDC-889
|
||||||
* @expectedException Doctrine\ORM\Mapping\MappingException
|
* @expectedException Doctrine\Common\Persistence\Mapping\MappingException
|
||||||
* @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml' for class 'Doctrine\Tests\Models\DDC889\DDC889Class'.
|
* @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml' for class 'Doctrine\Tests\Models\DDC889\DDC889Class'.
|
||||||
*/
|
*/
|
||||||
public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses()
|
public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses()
|
||||||
|
@ -27,7 +27,7 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest
|
|||||||
public function testJoinTablesWithMappedSuperclassForYamlDriver()
|
public function testJoinTablesWithMappedSuperclassForYamlDriver()
|
||||||
{
|
{
|
||||||
$yamlDriver = $this->_loadDriver();
|
$yamlDriver = $this->_loadDriver();
|
||||||
$yamlDriver->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'));
|
$yamlDriver->getLocator()->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'));
|
||||||
|
|
||||||
$em = $this->_getTestEntityManager();
|
$em = $this->_getTestEntityManager();
|
||||||
$em->getConfiguration()->setMetadataDriverImpl($yamlDriver);
|
$em->getConfiguration()->setMetadataDriverImpl($yamlDriver);
|
||||||
@ -46,7 +46,7 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest
|
|||||||
/**
|
/**
|
||||||
* @group DDC-1468
|
* @group DDC-1468
|
||||||
*
|
*
|
||||||
* @expectedException Doctrine\ORM\Mapping\MappingException
|
* @expectedException Doctrine\Common\Persistence\Mapping\MappingException
|
||||||
* @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'.
|
* @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'.
|
||||||
*/
|
*/
|
||||||
public function testInvalidMappingFileException()
|
public function testInvalidMappingFileException()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user