PK aCV兄2 2 phpunit.xml.distnu W+A
./tests/Doctrine/
./lib/Doctrine/
performance
PK aCVqs ' lib/Doctrine/Common/EventSubscriber.phpnu W+A .
*/
namespace Doctrine\Common;
/**
* An EventSubscriber knows himself what events he is interested in.
* If an EventSubscriber is added to an EventManager, the manager invokes
* {@link getSubscribedEvents} and registers the subscriber as a listener for all
* returned events.
*
* @link www.doctrine-project.org
* @since 2.0
* @author Guilherme Blanco
* @author Jonathan Wage
* @author Roman Borschel
*/
interface EventSubscriber
{
/**
* Returns an array of events this subscriber wants to listen to.
*
* @return array
*/
public function getSubscribedEvents();
}
PK aCV{{c c 3 lib/Doctrine/Common/Persistence/ManagerRegistry.phpnu W+A .
*/
namespace Doctrine\Common\Persistence;
/**
* Contract covering object managers for a Doctrine persistence layer ManagerRegistry class to implement.
*
* @link www.doctrine-project.org
* @since 2.2
* @author Fabien Potencier
* @author Benjamin Eberlei
* @author Lukas Kahwe Smith
*/
interface ManagerRegistry extends ConnectionRegistry
{
/**
* Gets the default object manager name.
*
* @return string The default object manager name.
*/
public function getDefaultManagerName();
/**
* Gets a named object manager.
*
* @param string $name The object manager name (null for the default one).
*
* @return \Doctrine\Common\Persistence\ObjectManager
*/
public function getManager($name = null);
/**
* Gets an array of all registered object managers.
*
* @return \Doctrine\Common\Persistence\ObjectManager[] An array of ObjectManager instances
*/
public function getManagers();
/**
* Resets a named object manager.
*
* This method is useful when an object manager has been closed
* because of a rollbacked transaction AND when you think that
* it makes sense to get a new one to replace the closed one.
*
* Be warned that you will get a brand new object manager as
* the existing one is not useable anymore. This means that any
* other object with a dependency on this object manager will
* hold an obsolete reference. You can inject the registry instead
* to avoid this problem.
*
* @param string|null $name The object manager name (null for the default one).
*
* @return \Doctrine\Common\Persistence\ObjectManager
*/
public function resetManager($name = null);
/**
* Resolves a registered namespace alias to the full namespace.
*
* This method looks for the alias in all registered object managers.
*
* @param string $alias The alias.
*
* @return string The full namespace.
*/
public function getAliasNamespace($alias);
/**
* Gets all connection names.
*
* @return array An array of connection names.
*/
public function getManagerNames();
/**
* Gets the ObjectRepository for an persistent object.
*
* @param string $persistentObject The name of the persistent object.
* @param string $persistentManagerName The object manager name (null for the default one).
*
* @return \Doctrine\Common\Persistence\ObjectRepository
*/
public function getRepository($persistentObject, $persistentManagerName = null);
/**
* Gets the object manager associated with a given class.
*
* @param string $class A persistent object class name.
*
* @return \Doctrine\Common\Persistence\ObjectManager|null
*/
public function getManagerForClass($class);
}
PK aCV҄s s 6 lib/Doctrine/Common/Persistence/ObjectManagerAware.phpnu W+A .
*/
namespace Doctrine\Common\Persistence;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
/**
* Makes a Persistent Objects aware of its own object-manager.
*
* Using this interface the managing object manager and class metadata instances
* are injected into the persistent object after construction. This allows
* you to implement ActiveRecord functionality on top of the persistence-ignorance
* that Doctrine propagates.
*
* Word of Warning: This is a very powerful hook to change how you can work with your domain models.
* Using this hook will break the Single Responsibility Principle inside your Domain Objects
* and increase the coupling of database and objects.
*
* Every ObjectManager has to implement this functionality itself.
*
* @author Benjamin Eberlei
*/
interface ObjectManagerAware
{
/**
* Injects responsible ObjectManager and the ClassMetadata into this persistent object.
*
* @param ObjectManager $objectManager
* @param ClassMetadata $classMetadata
*
* @return void
*/
public function injectObjectManager(ObjectManager $objectManager, ClassMetadata $classMetadata);
}
PK aCVH~0 ~0 H lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.phpnu W+A .
*/
namespace Doctrine\Common\Persistence\Mapping;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Util\ClassUtils;
/**
* 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
* to a relational database.
*
* This class was abstracted from the ORM ClassMetadataFactory.
*
* @since 2.2
* @author Benjamin Eberlei
* @author Guilherme Blanco
* @author Jonathan Wage
* @author Roman Borschel
*/
abstract class AbstractClassMetadataFactory implements ClassMetadataFactory
{
/**
* Salt used by specific Object Manager implementation.
*
* @var string
*/
protected $cacheSalt = '$CLASSMETADATA';
/**
* @var \Doctrine\Common\Cache\Cache|null
*/
private $cacheDriver;
/**
* @var array
*/
private $loadedMetadata = array();
/**
* @var bool
*/
protected $initialized = false;
/**
* @var ReflectionService|null
*/
private $reflectionService = null;
/**
* Sets the cache driver used by the factory to cache ClassMetadata instances.
*
* @param \Doctrine\Common\Cache\Cache $cacheDriver
*
* @return void
*/
public function setCacheDriver(Cache $cacheDriver = null)
{
$this->cacheDriver = $cacheDriver;
}
/**
* Gets the cache driver used by the factory to cache ClassMetadata instances.
*
* @return \Doctrine\Common\Cache\Cache|null
*/
public function getCacheDriver()
{
return $this->cacheDriver;
}
/**
* Returns an array of all the loaded metadata currently in memory.
*
* @return array
*/
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();
}
$driver = $this->getDriver();
$metadata = array();
foreach ($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.
*
* @return void
*/
abstract protected function initialize();
/**
* Gets the fully qualified class-name from the namespace alias.
*
* @param string $namespaceAlias
* @param string $simpleClassName
*
* @return string
*/
abstract protected function getFqcnFromAlias($namespaceAlias, $simpleClassName);
/**
* Returns the mapping driver implementation.
*
* @return \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver
*/
abstract protected function getDriver();
/**
* Wakes up reflection after ClassMetadata gets unserialized from cache.
*
* @param ClassMetadata $class
* @param ReflectionService $reflService
*
* @return void
*/
abstract protected function wakeupReflection(ClassMetadata $class, ReflectionService $reflService);
/**
* Initializes Reflection after ClassMetadata was constructed.
*
* @param ClassMetadata $class
* @param ReflectionService $reflService
*
* @return void
*/
abstract protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService);
/**
* Checks whether the class metadata is an entity.
*
* This method should return false for mapped superclasses or embedded classes.
*
* @param ClassMetadata $class
*
* @return boolean
*/
abstract protected function isEntity(ClassMetadata $class);
/**
* Gets the class metadata descriptor for a class.
*
* @param string $className The name of the class.
*
* @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
*/
public function getMetadataFor($className)
{
if (isset($this->loadedMetadata[$className])) {
return $this->loadedMetadata[$className];
}
$realClassName = $className;
// Check for namespace alias
if (strpos($className, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $className);
$realClassName = $this->getFqcnFromAlias($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 . $this->cacheSalt)) !== false) {
$this->loadedMetadata[$realClassName] = $cached;
$this->wakeupReflection($cached, $this->getReflectionService());
} else {
foreach ($this->loadMetadata($realClassName) as $loadedClassName) {
$this->cacheDriver->save(
$loadedClassName . $this->cacheSalt, $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
*
* @return void
*/
public function setMetadataFor($className, $class)
{
$this->loadedMetadata[$className] = $class;
}
/**
* Gets an array of parent classes for the given entity class.
*
* @param string $name
*
* @return array
*/
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->getDriver()->isTransient($parentClass)) {
$parentClasses[] = $parentClass;
}
}
return $parentClasses;
}
/**
* Loads the metadata of the class in question and all it's ancestors whose metadata
* is still not loaded.
*
* Important: The class $name does not necesarily exist at this point here.
* Scenarios in a code-generation setup might have access to XML/YAML
* Mapping files without the actual PHP code existing here. That is why the
* {@see Doctrine\Common\Persistence\Mapping\ReflectionService} interface
* should be used for reflection.
*
* @param string $name The name of the class for which the metadata should get loaded.
*
* @return array
*/
protected function loadMetadata($name)
{
if ( ! $this->initialized) {
$this->initialize();
}
$loaded = array();
$parentClasses = $this->getParentClasses($name);
$parentClasses[] = $name;
// Move down the hierarchy of parent classes, starting from the topmost class
$parent = null;
$rootEntityFound = false;
$visited = array();
$reflService = $this->getReflectionService();
foreach ($parentClasses as $className) {
if (isset($this->loadedMetadata[$className])) {
$parent = $this->loadedMetadata[$className];
if ($this->isEntity($parent)) {
$rootEntityFound = true;
array_unshift($visited, $className);
}
continue;
}
$class = $this->newClassMetadataInstance($className);
$this->initializeReflection($class, $reflService);
$this->doLoadMetadata($class, $parent, $rootEntityFound, $visited);
$this->loadedMetadata[$className] = $class;
$parent = $class;
if ($this->isEntity($class)) {
$rootEntityFound = true;
array_unshift($visited, $className);
}
$this->wakeupReflection($class, $reflService);
$loaded[] = $className;
}
return $loaded;
}
/**
* Actually loads the metadata from the underlying metadata.
*
* @param ClassMetadata $class
* @param ClassMetadata|null $parent
* @param bool $rootEntityFound
* @param array $nonSuperclassParents All parent class names
* that are not marked as mapped superclasses.
*
* @return void
*/
abstract protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents);
/**
* Creates a new ClassMetadata instance for the given class name.
*
* @param string $className
*
* @return ClassMetadata
*/
abstract protected function newClassMetadataInstance($className);
/**
* {@inheritDoc}
*/
public function isTransient($class)
{
if ( ! $this->initialized) {
$this->initialize();
}
// Check for namespace alias
if (strpos($class, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $class);
$class = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
}
return $this->getDriver()->isTransient($class);
}
/**
* Sets the reflectionService.
*
* @param ReflectionService $reflectionService
*
* @return void
*/
public function setReflectionService(ReflectionService $reflectionService)
{
$this->reflectionService = $reflectionService;
}
/**
* Gets the reflection service associated with this metadata factory.
*
* @return ReflectionService
*/
public function getReflectionService()
{
if ($this->reflectionService === null) {
$this->reflectionService = new RuntimeReflectionService();
}
return $this->reflectionService;
}
}
PK aCVC
@ lib/Doctrine/Common/Persistence/Mapping/ClassMetadataFactory.phpnu W+A .
*/
namespace Doctrine\Common\Persistence\Mapping;
/**
* Contract for a Doctrine persistence layer ClassMetadata class to implement.
*
* @link www.doctrine-project.org
* @since 2.1
* @author Benjamin Eberlei
* @author Jonathan Wage
*/
interface ClassMetadataFactory
{
/**
* 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();
/**
* Gets the class metadata descriptor for a class.
*
* @param string $className The name of the class.
*
* @return ClassMetadata
*/
public function getMetadataFor($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);
/**
* Sets the metadata descriptor for a specific class.
*
* @param string $className
*
* @param ClassMetadata $class
*/
public function setMetadataFor($className, $class);
/**
* Returns whether the class with the specified name should have its metadata loaded.
* This is only the case if it is either mapped directly or as a MappedSuperclass.
*
* @param string $className
*
* @return boolean
*/
public function isTransient($className);
}
PK aCVs 9 lib/Doctrine/Common/Persistence/Mapping/ClassMetadata.phpnu W+A .
*/
namespace Doctrine\Common\Persistence\Mapping;
/**
* Contract for a Doctrine persistence layer ClassMetadata class to implement.
*
* @link www.doctrine-project.org
* @since 2.1
* @author Benjamin Eberlei
* @author Jonathan Wage
*/
interface ClassMetadata
{
/**
* Gets the fully-qualified class name of this persistent class.
*
* @return string
*/
public function getName();
/**
* Gets the mapped identifier field name.
*
* The returned structure is an array of the identifier field names.
*
* @return array
*/
public function getIdentifier();
/**
* Gets the ReflectionClass instance for this mapped class.
*
* @return \ReflectionClass
*/
public function getReflectionClass();
/**
* Checks if the given field name is a mapped identifier for this class.
*
* @param string $fieldName
*
* @return boolean
*/
public function isIdentifier($fieldName);
/**
* Checks if the given field is a mapped property for this class.
*
* @param string $fieldName
*
* @return boolean
*/
public function hasField($fieldName);
/**
* Checks if the given field is a mapped association for this class.
*
* @param string $fieldName
*
* @return boolean
*/
public function hasAssociation($fieldName);
/**
* Checks if the given field is a mapped single valued association for this class.
*
* @param string $fieldName
*
* @return boolean
*/
public function isSingleValuedAssociation($fieldName);
/**
* Checks if the given field is a mapped collection valued association for this class.
*
* @param string $fieldName
*
* @return boolean
*/
public function isCollectionValuedAssociation($fieldName);
/**
* A numerically indexed list of field names of this persistent class.
*
* This array includes identifier fields if present on this class.
*
* @return array
*/
public function getFieldNames();
/**
* Returns an array of identifier field names numerically indexed.
*
* @return array
*/
public function getIdentifierFieldNames();
/**
* Returns a numerically indexed list of association names of this persistent class.
*
* This array includes identifier associations if present on this class.
*
* @return array
*/
public function getAssociationNames();
/**
* Returns a type name of this field.
*
* This type names can be implementation specific but should at least include the php types:
* integer, string, boolean, float/double, datetime.
*
* @param string $fieldName
*
* @return string
*/
public function getTypeOfField($fieldName);
/**
* Returns the target class name of the given association.
*
* @param string $assocName
*
* @return string
*/
public function getAssociationTargetClass($assocName);
/**
* Checks if the association is the inverse side of a bidirectional association.
*
* @param string $assocName
*
* @return boolean
*/
public function isAssociationInverseSide($assocName);
/**
* Returns the target field of the owning side of the association.
*
* @param string $assocName
*
* @return string
*/
public function getAssociationMappedByTargetField($assocName);
/**
* Returns the identifier of this object as an array with field name as key.
*
* Has to return an empty array if no identifier isset.
*
* @param object $object
*
* @return array
*/
public function getIdentifierValues($object);
}
PK aCVAlr r D lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.phpnu W+A .
*/
namespace Doctrine\Common\Persistence\Mapping;
use ReflectionClass;
use ReflectionProperty;
use ReflectionMethod;
use ReflectionException;
use Doctrine\Common\Reflection\RuntimePublicReflectionProperty;
use Doctrine\Common\Persistence\Mapping\MappingException;
/**
* PHP Runtime Reflection Service.
*
* @author Benjamin Eberlei
*/
class RuntimeReflectionService implements ReflectionService
{
/**
* {@inheritDoc}
*/
public function getParentClasses($class)
{
if ( ! class_exists($class)) {
throw MappingException::nonExistingClass($class);
}
return class_parents($class);
}
/**
* {@inheritDoc}
*/
public function getClassShortName($class)
{
$reflectionClass = new ReflectionClass($class);
return $reflectionClass->getShortName();
}
/**
* {@inheritDoc}
*/
public function getClassNamespace($class)
{
$reflectionClass = new ReflectionClass($class);
return $reflectionClass->getNamespaceName();
}
/**
* {@inheritDoc}
*/
public function getClass($class)
{
return new ReflectionClass($class);
}
/**
* {@inheritDoc}
*/
public function getAccessibleProperty($class, $property)
{
$reflectionProperty = new ReflectionProperty($class, $property);
if ($reflectionProperty->isPublic()) {
$reflectionProperty = new RuntimePublicReflectionProperty($class, $property);
}
$reflectionProperty->setAccessible(true);
return $reflectionProperty;
}
/**
* {@inheritDoc}
*/
public function hasPublicMethod($class, $method)
{
try {
$reflectionMethod = new ReflectionMethod($class, $method);
} catch (ReflectionException $e) {
return false;
}
return $reflectionMethod->isPublic();
}
}
PK aCVҁ E lib/Doctrine/Common/Persistence/Mapping/Driver/SymfonyFileLocator.phpnu W+A .
*/
namespace Doctrine\Common\Persistence\Mapping\Driver;
use Doctrine\Common\Persistence\Mapping\MappingException;
/**
* The Symfony File Locator makes a simplifying assumptions compared
* to the DefaultFileLocator. By assuming paths only contain entities of a certain
* namespace the mapping files consists of the short classname only.
*
* @author Fabien Potencier
* @author Benjamin Eberlei
* @license MIT
*/
class SymfonyFileLocator implements FileLocator
{
/**
* The paths where to look for mapping files.
*
* @var array
*/
protected $paths = array();
/**
* A map of mapping directory path to namespace prefix used to expand class shortnames.
*
* @var array
*/
protected $prefixes = array();
/**
* File extension that is searched for.
*
* @var string|null
*/
protected $fileExtension;
/**
* Constructor.
*
* @param array $prefixes
* @param string|null $fileExtension
*/
public function __construct(array $prefixes, $fileExtension = null)
{
$this->addNamespacePrefixes($prefixes);
$this->fileExtension = $fileExtension;
}
/**
* Adds Namespace Prefixes.
*
* @param array $prefixes
*
* @return void
*/
public function addNamespacePrefixes(array $prefixes)
{
$this->prefixes = array_merge($this->prefixes, $prefixes);
$this->paths = array_merge($this->paths, array_keys($prefixes));
}
/**
* Gets Namespace Prefixes.
*
* @return array
*/
public function getNamespacePrefixes()
{
return $this->prefixes;
}
/**
* {@inheritDoc}
*/
public function getPaths()
{
return $this->paths;
}
/**
* {@inheritDoc}
*/
public function getFileExtension()
{
return $this->fileExtension;
}
/**
* Sets 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 fileExists($className)
{
$defaultFileName = str_replace('\\', '.', $className).$this->fileExtension;
foreach ($this->paths as $path) {
if (!isset($this->prefixes[$path])) {
// global namespace class
if (is_file($path.DIRECTORY_SEPARATOR.$defaultFileName)) {
return true;
}
continue;
}
$prefix = $this->prefixes[$path];
if (0 !== strpos($className, $prefix.'\\')) {
continue;
}
$filename = $path.'/'.strtr(substr($className, strlen($prefix)+1), '\\', '.').$this->fileExtension;
return is_file($filename);
}
return false;
}
/**
* {@inheritDoc}
*/
public function getAllClassNames($globalBasename = null)
{
$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 == $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 $classes;
}
/**
* {@inheritDoc}
*/
public 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);
}
}
PK aCV C lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.phpnu W+A .
*/
namespace Doctrine\Common\Persistence\Mapping\Driver;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Persistence\Mapping\MappingException;
/**
* The AnnotationDriver reads the mapping metadata from docblock annotations.
*
* @since 2.2
* @author Benjamin Eberlei
* @author Guilherme Blanco
* @author Jonathan H. Wage
* @author Roman Borschel
*/
abstract class AnnotationDriver implements MappingDriver
{
/**
* The AnnotationReader.
*
* @var AnnotationReader
*/
protected $reader;
/**
* The paths where to look for mapping files.
*
* @var array
*/
protected $paths = array();
/**
* The paths excluded from path where to look for mapping files.
*
* @var array
*/
protected $excludePaths = array();
/**
* The file extension of mapping documents.
*
* @var string
*/
protected $fileExtension = '.php';
/**
* Cache for AnnotationDriver#getAllClassNames().
*
* @var array|null
*/
protected $classNames;
/**
* Name of the entity annotations as keys.
*
* @var array
*/
protected $entityAnnotationClasses = array();
/**
* 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|null $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);
}
}
/**
* Appends lookup paths to metadata driver.
*
* @param array $paths
*
* @return void
*/
public function addPaths(array $paths)
{
$this->paths = array_unique(array_merge($this->paths, $paths));
}
/**
* Retrieves the defined metadata lookup paths.
*
* @return array
*/
public function getPaths()
{
return $this->paths;
}
/**
* Append exclude lookup paths to metadata driver.
*
* @param array $paths
*/
public function addExcludePaths(array $paths)
{
$this->excludePaths = array_unique(array_merge($this->excludePaths, $paths));
}
/**
* Retrieve the defined metadata lookup exclude paths.
*
* @return array
*/
public function getExcludePaths()
{
return $this->excludePaths;
}
/**
* Retrieve the current annotation reader
*
* @return AnnotationReader
*/
public function getReader()
{
return $this->reader;
}
/**
* Gets the file extension used to look for mapping files under.
*
* @return string
*/
public function getFileExtension()
{
return $this->fileExtension;
}
/**
* Sets 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;
}
/**
* Returns 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 an annotation
* from the {@see AnnotationDriver::entityAnnotationClasses}.
*
* @param string $className
*
* @return boolean
*/
public function isTransient($className)
{
$classAnnotations = $this->reader->getClassAnnotations(new \ReflectionClass($className));
foreach ($classAnnotations as $annot) {
if (isset($this->entityAnnotationClasses[get_class($annot)])) {
return false;
}
}
return true;
}
/**
* {@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
),
'/^.+' . preg_quote($this->fileExtension) . '$/i',
\RecursiveRegexIterator::GET_MATCH
);
foreach ($iterator as $file) {
$sourceFile = $file[0];
if ( ! preg_match('(^phar:)i', $sourceFile)) {
$sourceFile = realpath($sourceFile);
}
foreach ($this->excludePaths as $excludePath) {
$exclude = str_replace('\\', '/', realpath($excludePath));
$current = str_replace('\\', '/', $sourceFile);
if (strpos($current, $exclude) !== false) {
continue 2;
}
}
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;
}
}
PK aCVQLw <