This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,258 @@
<?php
namespace Doctrine\Persistence\Mapping\Driver;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Persistence\Mapping\MappingException;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RecursiveRegexIterator;
use ReflectionClass;
use RegexIterator;
use function array_merge;
use function array_unique;
use function class_exists;
use function get_class;
use function get_declared_classes;
use function in_array;
use function is_dir;
use function preg_match;
use function preg_quote;
use function realpath;
use function str_replace;
use function strpos;
/**
* The AnnotationDriver reads the mapping metadata from docblock annotations.
*/
abstract class AnnotationDriver implements MappingDriver
{
/**
* The annotation reader.
*
* @var Reader
*/
protected $reader;
/**
* The paths where to look for mapping files.
*
* @var string[]
*/
protected $paths = [];
/**
* The paths excluded from path where to look for mapping files.
*
* @var string[]
*/
protected $excludePaths = [];
/**
* The file extension of mapping documents.
*
* @var string
*/
protected $fileExtension = '.php';
/**
* Cache for AnnotationDriver#getAllClassNames().
*
* @var string[]|null
*/
protected $classNames;
/**
* Name of the entity annotations as keys.
*
* @var string[]
*/
protected $entityAnnotationClasses = [];
/**
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
* docblock annotations.
*
* @param Reader $reader The AnnotationReader to use, duck-typed.
* @param string|string[]|null $paths One or multiple paths where mapping classes can be found.
*/
public function __construct($reader, $paths = null)
{
$this->reader = $reader;
if (! $paths) {
return;
}
$this->addPaths((array) $paths);
}
/**
* Appends lookup paths to metadata driver.
*
* @param string[] $paths
*
* @return void
*/
public function addPaths(array $paths)
{
$this->paths = array_unique(array_merge($this->paths, $paths));
}
/**
* Retrieves the defined metadata lookup paths.
*
* @return string[]
*/
public function getPaths()
{
return $this->paths;
}
/**
* Append exclude lookup paths to metadata driver.
*
* @param string[] $paths
*/
public function addExcludePaths(array $paths)
{
$this->excludePaths = array_unique(array_merge($this->excludePaths, $paths));
}
/**
* Retrieve the defined metadata lookup exclude paths.
*
* @return string[]
*/
public function getExcludePaths()
{
return $this->excludePaths;
}
/**
* Retrieve the current annotation reader
*
* @return Reader
*/
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 bool
*/
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 = [];
$includedFiles = [];
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)) {
continue;
}
$classes[] = $className;
}
$this->classNames = $classes;
return $classes;
}
}
class_exists(\Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver::class);

View File

@@ -0,0 +1,164 @@
<?php
namespace Doctrine\Persistence\Mapping\Driver;
use Doctrine\Persistence\Mapping\MappingException;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use const DIRECTORY_SEPARATOR;
use function array_merge;
use function array_unique;
use function class_exists;
use function is_dir;
use function is_file;
use function str_replace;
/**
* Locates the file that contains the metadata information for a given class name.
*
* This behavior is independent of the actual content of the file. It just detects
* the file which is responsible for the given class name.
*/
class DefaultFileLocator implements FileLocator
{
/**
* The paths where to look for mapping files.
*
* @var string[]
*/
protected $paths = [];
/**
* The file extension of mapping documents.
*
* @var string|null
*/
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|string[] $paths One or multiple paths where mapping documents can be found.
* @param string|null $fileExtension The file extension of mapping documents, usually prefixed with a dot.
*/
public function __construct($paths, $fileExtension = null)
{
$this->addPaths((array) $paths);
$this->fileExtension = $fileExtension;
}
/**
* Appends lookup paths to metadata driver.
*
* @param string[] $paths
*
* @return void
*/
public function addPaths(array $paths)
{
$this->paths = array_unique(array_merge($this->paths, $paths));
}
/**
* Retrieves the defined metadata lookup paths.
*
* @return string[]
*/
public function getPaths()
{
return $this->paths;
}
/**
* Gets the file extension used to look for mapping files under.
*
* @return string|null
*/
public function getFileExtension()
{
return $this->fileExtension;
}
/**
* Sets the file extension used to look for mapping files under.
*
* @param string|null $fileExtension The file extension to set.
*
* @return void
*/
public function setFileExtension($fileExtension)
{
$this->fileExtension = $fileExtension;
}
/**
* {@inheritDoc}
*/
public function findMappingFile($className)
{
$fileName = str_replace('\\', '.', $className) . $this->fileExtension;
// Check whether file exists
foreach ($this->paths as $path) {
if (is_file($path . DIRECTORY_SEPARATOR . $fileName)) {
return $path . DIRECTORY_SEPARATOR . $fileName;
}
}
throw MappingException::mappingFileNotFound($className, $fileName);
}
/**
* {@inheritDoc}
*/
public function getAllClassNames($globalBasename)
{
$classes = [];
if ($this->paths) {
foreach ($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!
$classes[] = str_replace('.', '\\', $fileName);
}
}
}
return $classes;
}
/**
* {@inheritDoc}
*/
public function fileExists($className)
{
$fileName = str_replace('\\', '.', $className) . $this->fileExtension;
// Check whether file exists
foreach ((array) $this->paths as $path) {
if (is_file($path . DIRECTORY_SEPARATOR . $fileName)) {
return true;
}
}
return false;
}
}
class_exists(\Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator::class);

View File

@@ -0,0 +1,199 @@
<?php
namespace Doctrine\Persistence\Mapping\Driver;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\MappingException;
use function array_keys;
use function array_merge;
use function array_unique;
use function class_exists;
use function interface_exists;
use function is_file;
use function str_replace;
/**
* 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 '.'.
*/
abstract class FileDriver implements MappingDriver
{
/** @var FileLocator */
protected $locator;
/** @var ClassMetadata[]|null */
protected $classCache;
/** @var string|null */
protected $globalBasename;
/**
* Initializes a new FileDriver that looks in the given path(s) for mapping
* documents and operates in the specified operating mode.
*
* @param string|string[]|FileLocator $locator A FileLocator or one/multiple paths
* where mapping documents can be found.
* @param string|null $fileExtension
*/
public function __construct($locator, $fileExtension = null)
{
if ($locator instanceof FileLocator) {
$this->locator = $locator;
} else {
$this->locator = new DefaultFileLocator((array) $locator, $fileExtension);
}
}
/**
* Sets the global basename.
*
* @param string $file
*
* @return void
*/
public function setGlobalBasename($file)
{
$this->globalBasename = $file;
}
/**
* Retrieves the global basename.
*
* @return string|null
*/
public function getGlobalBasename()
{
return $this->globalBasename;
}
/**
* Gets 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.
*
* @param string $className
*
* @return ClassMetadata The element of schema meta data.
*
* @throws MappingException
*/
public function getElement($className)
{
if ($this->classCache === null) {
$this->initialize();
}
if (isset($this->classCache[$className])) {
return $this->classCache[$className];
}
$result = $this->loadMappingFile($this->locator->findMappingFile($className));
if (! isset($result[$className])) {
throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->locator->getFileExtension());
}
$this->classCache[$className] = $result[$className];
return $result[$className];
}
/**
* {@inheritDoc}
*/
public function isTransient($className)
{
if ($this->classCache === null) {
$this->initialize();
}
if (isset($this->classCache[$className])) {
return false;
}
return ! $this->locator->fileExists($className);
}
/**
* {@inheritDoc}
*/
public function getAllClassNames()
{
if ($this->classCache === null) {
$this->initialize();
}
if (! $this->classCache) {
return (array) $this->locator->getAllClassNames($this->globalBasename);
}
return array_unique(array_merge(
array_keys($this->classCache),
(array) $this->locator->getAllClassNames($this->globalBasename)
));
}
/**
* Loads a mapping file with the given name and returns a map
* from class/entity names to their corresponding file driver elements.
*
* @param string $file The mapping file to load.
*
* @return ClassMetadata[]
*/
abstract protected function loadMappingFile($file);
/**
* Initializes the class cache from all the global files.
*
* Using this feature adds a substantial performance hit to file drivers as
* more metadata has to be loaded into memory than might actually be
* necessary. This may not be relevant to scenarios where caching of
* metadata is in place, however hits very hard in scenarios where no
* caching is used.
*
* @return void
*/
protected function initialize()
{
$this->classCache = [];
if ($this->globalBasename === null) {
return;
}
foreach ($this->locator->getPaths() as $path) {
$file = $path . '/' . $this->globalBasename . $this->locator->getFileExtension();
if (! is_file($file)) {
continue;
}
$this->classCache = array_merge(
$this->classCache,
$this->loadMappingFile($file)
);
}
}
/**
* Retrieves the locator used to discover mapping files by className.
*
* @return FileLocator
*/
public function getLocator()
{
return $this->locator;
}
/**
* Sets the locator used to discover mapping files by className.
*/
public function setLocator(FileLocator $locator)
{
$this->locator = $locator;
}
}
class_exists(\Doctrine\Common\Persistence\Mapping\Driver\FileDriver::class);
interface_exists(FileLocator::class);

View File

@@ -0,0 +1,57 @@
<?php
namespace Doctrine\Persistence\Mapping\Driver;
use function interface_exists;
/**
* Locates the file that contains the metadata information for a given class name.
*
* This behavior is independent of the actual content of the file. It just detects
* the file which is responsible for the given class name.
*/
interface FileLocator
{
/**
* Locates mapping file for the given class name.
*
* @param string $className
*
* @return string
*/
public function findMappingFile($className);
/**
* Gets all class names that are found with this file locator.
*
* @param string|null $globalBasename Passed to allow excluding the basename.
*
* @return string[]
*/
public function getAllClassNames($globalBasename);
/**
* Checks if a file can be found for this class name.
*
* @param string $className
*
* @return bool
*/
public function fileExists($className);
/**
* Gets all the paths that this file locator looks for mapping files.
*
* @return string[]
*/
public function getPaths();
/**
* Gets the file extension that mapping files are suffixed with.
*
* @return string|null
*/
public function getFileExtension();
}
interface_exists(\Doctrine\Common\Persistence\Mapping\Driver\FileLocator::class);

View File

@@ -0,0 +1,41 @@
<?php
namespace Doctrine\Persistence\Mapping\Driver;
use Doctrine\Persistence\Mapping\ClassMetadata;
use function interface_exists;
/**
* Contract for metadata drivers.
*/
interface MappingDriver
{
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
*
* @return void
*/
public function loadMetadataForClass($className, ClassMetadata $metadata);
/**
* Gets the names of all mapped classes known to this driver.
*
* @return string[] The names of all mapped classes known to this driver.
*/
public function getAllClassNames();
/**
* Returns 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 bool
*/
public function isTransient($className);
}
interface_exists(\Doctrine\Common\Persistence\Mapping\Driver\MappingDriver::class);
interface_exists(ClassMetadata::class);

View File

@@ -0,0 +1,149 @@
<?php
namespace Doctrine\Persistence\Mapping\Driver;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\MappingException;
use function array_keys;
use function class_exists;
use function interface_exists;
use function spl_object_hash;
use function strpos;
/**
* The DriverChain allows you to add multiple other mapping drivers for
* certain namespaces.
*/
class MappingDriverChain implements MappingDriver
{
/**
* The default driver.
*
* @var MappingDriver|null
*/
private $defaultDriver;
/** @var MappingDriver[] */
private $drivers = [];
/**
* Gets the default driver.
*
* @return MappingDriver|null
*/
public function getDefaultDriver()
{
return $this->defaultDriver;
}
/**
* Set the default driver.
*
* @return void
*/
public function setDefaultDriver(MappingDriver $driver)
{
$this->defaultDriver = $driver;
}
/**
* Adds a nested driver.
*
* @param string $namespace
*
* @return void
*/
public function addDriver(MappingDriver $nestedDriver, $namespace)
{
$this->drivers[$namespace] = $nestedDriver;
}
/**
* Gets the array of nested drivers.
*
* @return MappingDriver[] $drivers
*/
public function getDrivers()
{
return $this->drivers;
}
/**
* {@inheritDoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/** @var MappingDriver $driver */
foreach ($this->drivers as $namespace => $driver) {
if (strpos($className, $namespace) === 0) {
$driver->loadMetadataForClass($className, $metadata);
return;
}
}
if ($this->defaultDriver !== null) {
$this->defaultDriver->loadMetadataForClass($className, $metadata);
return;
}
throw MappingException::classNotFoundInNamespaces($className, array_keys($this->drivers));
}
/**
* {@inheritDoc}
*/
public function getAllClassNames()
{
$classNames = [];
$driverClasses = [];
/** @var MappingDriver $driver */
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) {
continue;
}
$classNames[$className] = true;
}
}
if ($this->defaultDriver !== null) {
foreach ($this->defaultDriver->getAllClassNames() as $className) {
$classNames[$className] = true;
}
}
return array_keys($classNames);
}
/**
* {@inheritDoc}
*/
public function isTransient($className)
{
/** @var MappingDriver $driver */
foreach ($this->drivers as $namespace => $driver) {
if (strpos($className, $namespace) === 0) {
return $driver->isTransient($className);
}
}
if ($this->defaultDriver !== null) {
return $this->defaultDriver->isTransient($className);
}
return true;
}
}
class_exists(\Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain::class);
interface_exists(ClassMetadata::class);

View File

@@ -0,0 +1,49 @@
<?php
namespace Doctrine\Persistence\Mapping\Driver;
use Doctrine\Persistence\Mapping\ClassMetadata;
use function class_exists;
use function interface_exists;
/**
* The PHPDriver includes php files which just populate ClassMetadataInfo
* instances with plain PHP code.
*/
class PHPDriver extends FileDriver
{
/** @var ClassMetadata */
protected $metadata;
/**
* {@inheritDoc}
*/
public function __construct($locator)
{
parent::__construct($locator, '.php');
}
/**
* {@inheritDoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$this->metadata = $metadata;
$this->loadMappingFile($this->locator->findMappingFile($className));
}
/**
* {@inheritDoc}
*/
protected function loadMappingFile($file)
{
$metadata = $this->metadata;
include $file;
return [$metadata->getName() => $metadata];
}
}
class_exists(\Doctrine\Common\Persistence\Mapping\Driver\PHPDriver::class);
interface_exists(ClassMetadata::class);

View File

@@ -0,0 +1,134 @@
<?php
namespace Doctrine\Persistence\Mapping\Driver;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\MappingException;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReflectionClass;
use function array_merge;
use function array_unique;
use function class_exists;
use function get_declared_classes;
use function in_array;
use function interface_exists;
use function is_dir;
use function method_exists;
use function realpath;
/**
* The StaticPHPDriver calls a static loadMetadata() method on your entity
* classes where you can manually populate the ClassMetadata instance.
*/
class StaticPHPDriver implements MappingDriver
{
/**
* Paths of entity directories.
*
* @var string[]
*/
private $paths = [];
/**
* Map of all class names.
*
* @var string[]
*/
private $classNames;
/**
* @param string[]|string $paths
*/
public function __construct($paths)
{
$this->addPaths((array) $paths);
}
/**
* Adds paths.
*
* @param string[] $paths
*
* @return void
*/
public function addPaths(array $paths)
{
$this->paths = array_unique(array_merge($this->paths, $paths));
}
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$className::loadMetadata($metadata);
}
/**
* {@inheritDoc}
*
* @todo Same code exists in AnnotationDriver, should we re-use it somehow or not worry about it?
*/
public function getAllClassNames()
{
if ($this->classNames !== null) {
return $this->classNames;
}
if (! $this->paths) {
throw MappingException::pathRequired();
}
$classes = [];
$includedFiles = [];
foreach ($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 ($file->getBasename('.php') === $file->getBasename()) {
continue;
}
$sourceFile = realpath($file->getPathName());
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)) {
continue;
}
$classes[] = $className;
}
$this->classNames = $classes;
return $classes;
}
/**
* {@inheritdoc}
*/
public function isTransient($className)
{
return ! method_exists($className, 'loadMetadata');
}
}
class_exists(\Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver::class);
interface_exists(ClassMetadata::class);

View File

@@ -0,0 +1,233 @@
<?php
namespace Doctrine\Persistence\Mapping\Driver;
use Doctrine\Persistence\Mapping\MappingException;
use InvalidArgumentException;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use const DIRECTORY_SEPARATOR;
use function array_keys;
use function array_merge;
use function class_exists;
use function is_dir;
use function is_file;
use function realpath;
use function str_replace;
use function strlen;
use function strpos;
use function strrpos;
use function strtr;
use function substr;
/**
* 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.
*/
class SymfonyFileLocator implements FileLocator
{
/**
* The paths where to look for mapping files.
*
* @var string[]
*/
protected $paths = [];
/**
* A map of mapping directory path to namespace prefix used to expand class shortnames.
*
* @var string[]
*/
protected $prefixes = [];
/**
* File extension that is searched for.
*
* @var string|null
*/
protected $fileExtension;
/**
* Represents PHP namespace delimiters when looking for files
*
* @var string
*/
private $nsSeparator;
/**
* @param string[] $prefixes
* @param string|null $fileExtension
* @param string $nsSeparator String which would be used when converting FQCN to filename and vice versa. Should not be empty
*/
public function __construct(array $prefixes, $fileExtension = null, $nsSeparator = '.')
{
$this->addNamespacePrefixes($prefixes);
$this->fileExtension = $fileExtension;
if (empty($nsSeparator)) {
throw new InvalidArgumentException('Namespace separator should not be empty');
}
$this->nsSeparator = (string) $nsSeparator;
}
/**
* Adds Namespace Prefixes.
*
* @param string[] $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 string[]
*/
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('\\', $this->nsSeparator, $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 (strpos($className, $prefix . '\\') !== 0) {
continue;
}
$filename = $path . '/' . strtr(substr($className, strlen($prefix) + 1), '\\', $this->nsSeparator) . $this->fileExtension;
if (is_file($filename)) {
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*/
public function getAllClassNames($globalBasename = null)
{
$classes = [];
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])) {
// Calculate namespace suffix for given prefix as a relative path from basepath to file path
$nsSuffix = strtr(
substr(realpath($file->getPath()), strlen(realpath($path))),
$this->nsSeparator,
'\\'
);
$classes[] = $this->prefixes[$path] . str_replace(DIRECTORY_SEPARATOR, '\\', $nsSuffix) . '\\' . str_replace($this->nsSeparator, '\\', $fileName);
} else {
$classes[] = str_replace($this->nsSeparator, '\\', $fileName);
}
}
}
}
return $classes;
}
/**
* {@inheritDoc}
*/
public function findMappingFile($className)
{
$defaultFileName = str_replace('\\', $this->nsSeparator, $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 (strpos($className, $prefix . '\\') !== 0) {
continue;
}
$filename = $path . '/' . strtr(substr($className, strlen($prefix) + 1), '\\', $this->nsSeparator) . $this->fileExtension;
if (is_file($filename)) {
return $filename;
}
}
throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\') + 1) . $this->fileExtension);
}
}
class_exists(\Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator::class);