Initial Drupal 11 with DDEV setup
This commit is contained in:
460
vendor/doctrine/persistence/src/Persistence/Mapping/AbstractClassMetadataFactory.php
vendored
Normal file
460
vendor/doctrine/persistence/src/Persistence/Mapping/AbstractClassMetadataFactory.php
vendored
Normal file
@ -0,0 +1,460 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\Persistence\Proxy;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
|
||||
use function array_combine;
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function array_reverse;
|
||||
use function array_unshift;
|
||||
use function assert;
|
||||
use function class_exists;
|
||||
use function ltrim;
|
||||
use function str_contains;
|
||||
use function str_replace;
|
||||
use function strrpos;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @template CMTemplate of ClassMetadata
|
||||
* @template-implements ClassMetadataFactory<CMTemplate>
|
||||
*/
|
||||
abstract class AbstractClassMetadataFactory implements ClassMetadataFactory
|
||||
{
|
||||
/** Salt used by specific Object Manager implementation. */
|
||||
protected string $cacheSalt = '__CLASSMETADATA__';
|
||||
|
||||
private CacheItemPoolInterface|null $cache = null;
|
||||
|
||||
/**
|
||||
* @var array<string, ClassMetadata>
|
||||
* @phpstan-var CMTemplate[]
|
||||
*/
|
||||
private array $loadedMetadata = [];
|
||||
|
||||
protected bool $initialized = false;
|
||||
|
||||
private ReflectionService|null $reflectionService = null;
|
||||
|
||||
private ProxyClassNameResolver|null $proxyClassNameResolver = null;
|
||||
|
||||
public function setCache(CacheItemPoolInterface $cache): void
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
final protected function getCache(): CacheItemPoolInterface|null
|
||||
{
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the loaded metadata currently in memory.
|
||||
*
|
||||
* @return ClassMetadata[]
|
||||
* @phpstan-return CMTemplate[]
|
||||
*/
|
||||
public function getLoadedMetadata(): array
|
||||
{
|
||||
return $this->loadedMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getAllMetadata(): array
|
||||
{
|
||||
if (! $this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
$driver = $this->getDriver();
|
||||
$metadata = [];
|
||||
foreach ($driver->getAllClassNames() as $className) {
|
||||
$metadata[] = $this->getMetadataFor($className);
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
public function setProxyClassNameResolver(ProxyClassNameResolver $resolver): void
|
||||
{
|
||||
$this->proxyClassNameResolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy initialization of this stuff, especially the metadata driver,
|
||||
* since these are not needed at all when a metadata cache is active.
|
||||
*/
|
||||
abstract protected function initialize(): void;
|
||||
|
||||
/** Returns the mapping driver implementation. */
|
||||
abstract protected function getDriver(): MappingDriver;
|
||||
|
||||
/**
|
||||
* Wakes up reflection after ClassMetadata gets unserialized from cache.
|
||||
*
|
||||
* @phpstan-param CMTemplate $class
|
||||
*/
|
||||
abstract protected function wakeupReflection(
|
||||
ClassMetadata $class,
|
||||
ReflectionService $reflService,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Initializes Reflection after ClassMetadata was constructed.
|
||||
*
|
||||
* @phpstan-param CMTemplate $class
|
||||
*/
|
||||
abstract protected function initializeReflection(
|
||||
ClassMetadata $class,
|
||||
ReflectionService $reflService,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Checks whether the class metadata is an entity.
|
||||
*
|
||||
* This method should return false for mapped superclasses or embedded classes.
|
||||
*
|
||||
* @phpstan-param CMTemplate $class
|
||||
*/
|
||||
abstract protected function isEntity(ClassMetadata $class): bool;
|
||||
|
||||
/**
|
||||
* Removes the prepended backslash of a class string to conform with how php outputs class names
|
||||
*
|
||||
* @phpstan-param class-string $className
|
||||
*
|
||||
* @phpstan-return class-string
|
||||
*/
|
||||
private function normalizeClassName(string $className): string
|
||||
{
|
||||
return ltrim($className, '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @throws MappingException
|
||||
*/
|
||||
public function getMetadataFor(string $className): ClassMetadata
|
||||
{
|
||||
$className = $this->normalizeClassName($className);
|
||||
|
||||
if (isset($this->loadedMetadata[$className])) {
|
||||
return $this->loadedMetadata[$className];
|
||||
}
|
||||
|
||||
if (class_exists($className, false) && (new ReflectionClass($className))->isAnonymous()) {
|
||||
throw MappingException::classIsAnonymous($className);
|
||||
}
|
||||
|
||||
if (! class_exists($className, false) && str_contains($className, ':')) {
|
||||
throw MappingException::nonExistingClass($className);
|
||||
}
|
||||
|
||||
$realClassName = $this->getRealClass($className);
|
||||
|
||||
if (isset($this->loadedMetadata[$realClassName])) {
|
||||
// We do not have the alias name in the map, include it
|
||||
return $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
|
||||
}
|
||||
|
||||
try {
|
||||
if ($this->cache !== null) {
|
||||
$cached = $this->cache->getItem($this->getCacheKey($realClassName))->get();
|
||||
if ($cached instanceof ClassMetadata) {
|
||||
/** @phpstan-var CMTemplate $cached */
|
||||
$this->loadedMetadata[$realClassName] = $cached;
|
||||
|
||||
$this->wakeupReflection($cached, $this->getReflectionService());
|
||||
} else {
|
||||
$loadedMetadata = $this->loadMetadata($realClassName);
|
||||
$classNames = array_combine(
|
||||
array_map($this->getCacheKey(...), $loadedMetadata),
|
||||
$loadedMetadata,
|
||||
);
|
||||
|
||||
foreach ($this->cache->getItems(array_keys($classNames)) as $item) {
|
||||
if (! isset($classNames[$item->getKey()])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item->set($this->loadedMetadata[$classNames[$item->getKey()]]);
|
||||
$this->cache->saveDeferred($item);
|
||||
}
|
||||
|
||||
$this->cache->commit();
|
||||
}
|
||||
} else {
|
||||
$this->loadMetadata($realClassName);
|
||||
}
|
||||
} catch (MappingException $loadingException) {
|
||||
$fallbackMetadataResponse = $this->onNotFoundMetadata($realClassName);
|
||||
|
||||
if ($fallbackMetadataResponse === null) {
|
||||
throw $loadingException;
|
||||
}
|
||||
|
||||
$this->loadedMetadata[$realClassName] = $fallbackMetadataResponse;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
public function hasMetadataFor(string $className): bool
|
||||
{
|
||||
$className = $this->normalizeClassName($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.
|
||||
*
|
||||
* @phpstan-param class-string $className
|
||||
* @phpstan-param CMTemplate $class
|
||||
*/
|
||||
public function setMetadataFor(string $className, ClassMetadata $class): void
|
||||
{
|
||||
$this->loadedMetadata[$this->normalizeClassName($className)] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of parent classes for the given entity class.
|
||||
*
|
||||
* @phpstan-param class-string $name
|
||||
*
|
||||
* @return string[]
|
||||
* @phpstan-return list<class-string>
|
||||
*/
|
||||
protected function getParentClasses(string $name): array
|
||||
{
|
||||
// Collect parent classes, ignoring transient (not-mapped) classes.
|
||||
$parentClasses = [];
|
||||
|
||||
foreach (array_reverse($this->getReflectionService()->getParentClasses($name)) as $parentClass) {
|
||||
if ($this->getDriver()->isTransient($parentClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$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 necessarily 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\Persistence\Mapping\ReflectionService} interface
|
||||
* should be used for reflection.
|
||||
*
|
||||
* @param string $name The name of the class for which the metadata should get loaded.
|
||||
* @phpstan-param class-string $name
|
||||
*
|
||||
* @return array<int, string>
|
||||
* @phpstan-return list<string>
|
||||
*/
|
||||
protected function loadMetadata(string $name): array
|
||||
{
|
||||
if (! $this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
$loaded = [];
|
||||
|
||||
$parentClasses = $this->getParentClasses($name);
|
||||
$parentClasses[] = $name;
|
||||
|
||||
// Move down the hierarchy of parent classes, starting from the topmost class
|
||||
$parent = null;
|
||||
$rootEntityFound = false;
|
||||
$visited = [];
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a fallback hook for loading metadata when loading failed due to reflection/mapping exceptions
|
||||
*
|
||||
* Override this method to implement a fallback strategy for failed metadata loading
|
||||
*
|
||||
* @phpstan-return CMTemplate|null
|
||||
*/
|
||||
protected function onNotFoundMetadata(string $className): ClassMetadata|null
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually loads the metadata from the underlying metadata.
|
||||
*
|
||||
* @param bool $rootEntityFound True when there is another entity (non-mapped superclass) class above the current class in the PHP class hierarchy.
|
||||
* @param list<class-string> $nonSuperclassParents All parent class names that are not marked as mapped superclasses, with the direct parent class being the first and the root entity class the last element.
|
||||
* @phpstan-param CMTemplate $class
|
||||
* @phpstan-param CMTemplate|null $parent
|
||||
*/
|
||||
abstract protected function doLoadMetadata(
|
||||
ClassMetadata $class,
|
||||
ClassMetadata|null $parent,
|
||||
bool $rootEntityFound,
|
||||
array $nonSuperclassParents,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Creates a new ClassMetadata instance for the given class name.
|
||||
*
|
||||
* @phpstan-param class-string<T> $className
|
||||
*
|
||||
* @return ClassMetadata<T>
|
||||
* @phpstan-return CMTemplate
|
||||
*
|
||||
* @template T of object
|
||||
*/
|
||||
abstract protected function newClassMetadataInstance(string $className): ClassMetadata;
|
||||
|
||||
public function isTransient(string $className): bool
|
||||
{
|
||||
if (! $this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
if (class_exists($className, false) && (new ReflectionClass($className))->isAnonymous()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! class_exists($className, false) && str_contains($className, ':')) {
|
||||
throw MappingException::nonExistingClass($className);
|
||||
}
|
||||
|
||||
/** @phpstan-var class-string $className */
|
||||
return $this->getDriver()->isTransient($className);
|
||||
}
|
||||
|
||||
/** Sets the reflectionService. */
|
||||
public function setReflectionService(ReflectionService $reflectionService): void
|
||||
{
|
||||
$this->reflectionService = $reflectionService;
|
||||
}
|
||||
|
||||
/** Gets the reflection service associated with this metadata factory. */
|
||||
public function getReflectionService(): ReflectionService
|
||||
{
|
||||
if ($this->reflectionService === null) {
|
||||
$this->reflectionService = new RuntimeReflectionService();
|
||||
}
|
||||
|
||||
return $this->reflectionService;
|
||||
}
|
||||
|
||||
protected function getCacheKey(string $realClassName): string
|
||||
{
|
||||
return str_replace('\\', '__', $realClassName) . $this->cacheSalt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the real class name of a class name that could be a proxy.
|
||||
*
|
||||
* @phpstan-param class-string<Proxy<T>>|class-string<T> $class
|
||||
*
|
||||
* @phpstan-return class-string<T>
|
||||
*
|
||||
* @template T of object
|
||||
*/
|
||||
private function getRealClass(string $class): string
|
||||
{
|
||||
if ($this->proxyClassNameResolver === null) {
|
||||
$this->createDefaultProxyClassNameResolver();
|
||||
}
|
||||
|
||||
assert($this->proxyClassNameResolver !== null);
|
||||
|
||||
return $this->proxyClassNameResolver->resolveClassName($class);
|
||||
}
|
||||
|
||||
private function createDefaultProxyClassNameResolver(): void
|
||||
{
|
||||
$this->proxyClassNameResolver = new class implements ProxyClassNameResolver {
|
||||
/**
|
||||
* @phpstan-param class-string<Proxy<T>>|class-string<T> $className
|
||||
*
|
||||
* @phpstan-return class-string<T>
|
||||
*
|
||||
* @template T of object
|
||||
*/
|
||||
public function resolveClassName(string $className): string
|
||||
{
|
||||
$pos = strrpos($className, '\\' . Proxy::MARKER . '\\');
|
||||
|
||||
if ($pos === false) {
|
||||
/** @phpstan-var class-string<T> */
|
||||
return $className;
|
||||
}
|
||||
|
||||
/** @phpstan-var class-string<T> */
|
||||
return substr($className, $pos + Proxy::MARKER_LENGTH + 2);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
109
vendor/doctrine/persistence/src/Persistence/Mapping/ClassMetadata.php
vendored
Normal file
109
vendor/doctrine/persistence/src/Persistence/Mapping/ClassMetadata.php
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Contract for a Doctrine persistence layer ClassMetadata class to implement.
|
||||
*
|
||||
* @template-covariant T of object
|
||||
*/
|
||||
interface ClassMetadata
|
||||
{
|
||||
/**
|
||||
* Gets the fully-qualified class name of this persistent class.
|
||||
*
|
||||
* @phpstan-return class-string<T>
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* Gets the mapped identifier field name.
|
||||
*
|
||||
* The returned structure is an array of the identifier field names.
|
||||
*
|
||||
* @return array<int, string>
|
||||
* @phpstan-return list<string>
|
||||
*/
|
||||
public function getIdentifier(): array;
|
||||
|
||||
/**
|
||||
* Gets the ReflectionClass instance for this mapped class.
|
||||
*
|
||||
* @return ReflectionClass<T>
|
||||
*/
|
||||
public function getReflectionClass(): ReflectionClass;
|
||||
|
||||
/** Checks if the given field name is a mapped identifier for this class. */
|
||||
public function isIdentifier(string $fieldName): bool;
|
||||
|
||||
/** Checks if the given field is a mapped property for this class. */
|
||||
public function hasField(string $fieldName): bool;
|
||||
|
||||
/** Checks if the given field is a mapped association for this class. */
|
||||
public function hasAssociation(string $fieldName): bool;
|
||||
|
||||
/** Checks if the given field is a mapped single valued association for this class. */
|
||||
public function isSingleValuedAssociation(string $fieldName): bool;
|
||||
|
||||
/** Checks if the given field is a mapped collection valued association for this class. */
|
||||
public function isCollectionValuedAssociation(string $fieldName): bool;
|
||||
|
||||
/**
|
||||
* A numerically indexed list of field names of this persistent class.
|
||||
*
|
||||
* This array includes identifier fields if present on this class.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getFieldNames(): array;
|
||||
|
||||
/**
|
||||
* Returns an array of identifier field names numerically indexed.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getIdentifierFieldNames(): array;
|
||||
|
||||
/**
|
||||
* Returns a numerically indexed list of association names of this persistent class.
|
||||
*
|
||||
* This array includes identifier associations if present on this class.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getAssociationNames(): array;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function getTypeOfField(string $fieldName): string|null;
|
||||
|
||||
/**
|
||||
* Returns the target class name of the given association.
|
||||
*
|
||||
* @phpstan-return class-string|null
|
||||
*/
|
||||
public function getAssociationTargetClass(string $assocName): string|null;
|
||||
|
||||
/** Checks if the association is the inverse side of a bidirectional association. */
|
||||
public function isAssociationInverseSide(string $assocName): bool;
|
||||
|
||||
/** Returns the target field of the owning side of the association. */
|
||||
public function getAssociationMappedByTargetField(string $assocName): string;
|
||||
|
||||
/**
|
||||
* Returns the identifier of this object as an array with field name as key.
|
||||
*
|
||||
* Has to return an empty array if no identifier isset.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getIdentifierValues(object $object): array;
|
||||
}
|
||||
56
vendor/doctrine/persistence/src/Persistence/Mapping/ClassMetadataFactory.php
vendored
Normal file
56
vendor/doctrine/persistence/src/Persistence/Mapping/ClassMetadataFactory.php
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping;
|
||||
|
||||
/**
|
||||
* Contract for a Doctrine persistence layer ClassMetadata class to implement.
|
||||
*
|
||||
* @template T of ClassMetadata
|
||||
*/
|
||||
interface ClassMetadataFactory
|
||||
{
|
||||
/**
|
||||
* Forces the factory to load the metadata of all classes known to the underlying
|
||||
* mapping driver.
|
||||
*
|
||||
* @return ClassMetadata[] The ClassMetadata instances of all mapped classes.
|
||||
* @phpstan-return list<T>
|
||||
*/
|
||||
public function getAllMetadata(): array;
|
||||
|
||||
/**
|
||||
* Gets the class metadata descriptor for a class.
|
||||
*
|
||||
* @param class-string $className The name of the class.
|
||||
*
|
||||
* @phpstan-return T
|
||||
*/
|
||||
public function getMetadataFor(string $className): ClassMetadata;
|
||||
|
||||
/**
|
||||
* Checks whether the factory has the metadata for a class loaded already.
|
||||
*
|
||||
* @param class-string $className
|
||||
*
|
||||
* @return bool TRUE if the metadata of the class in question is already loaded, FALSE otherwise.
|
||||
*/
|
||||
public function hasMetadataFor(string $className): bool;
|
||||
|
||||
/**
|
||||
* Sets the metadata descriptor for a specific class.
|
||||
*
|
||||
* @param class-string $className
|
||||
* @phpstan-param T $class
|
||||
*/
|
||||
public function setMetadataFor(string $className, ClassMetadata $class): void;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @phpstan-param class-string $className
|
||||
*/
|
||||
public function isTransient(string $className): bool;
|
||||
}
|
||||
14
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/ClassLocator.php
vendored
Normal file
14
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/ClassLocator.php
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
/**
|
||||
* ClassLocator is an interface for classes that can provide a list of class names.
|
||||
*/
|
||||
interface ClassLocator
|
||||
{
|
||||
/** @return list<class-string> */
|
||||
public function getClassNames(): array;
|
||||
}
|
||||
23
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/ClassNames.php
vendored
Normal file
23
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/ClassNames.php
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
/**
|
||||
* Basic implementation of ClassLocator that passes a list of class names.
|
||||
*/
|
||||
final class ClassNames implements ClassLocator
|
||||
{
|
||||
/** @param list<class-string> $classNames */
|
||||
public function __construct(
|
||||
private array $classNames,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return list<class-string> */
|
||||
public function getClassNames(): array
|
||||
{
|
||||
return $this->classNames;
|
||||
}
|
||||
}
|
||||
138
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/ColocatedMappingDriver.php
vendored
Normal file
138
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/ColocatedMappingDriver.php
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
use Doctrine\Persistence\Mapping\MappingException;
|
||||
|
||||
use function array_filter;
|
||||
use function array_merge;
|
||||
use function array_unique;
|
||||
use function array_values;
|
||||
|
||||
/**
|
||||
* The ColocatedMappingDriver reads the mapping metadata located near the code.
|
||||
*/
|
||||
trait ColocatedMappingDriver
|
||||
{
|
||||
private ClassLocator|null $classLocator = null;
|
||||
|
||||
/**
|
||||
* The directory paths where to look for mapping files.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected array $paths = [];
|
||||
|
||||
/**
|
||||
* The paths excluded from path where to look for mapping files.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected array $excludePaths = [];
|
||||
|
||||
/** The file extension of mapping documents. */
|
||||
protected string $fileExtension = '.php';
|
||||
|
||||
/**
|
||||
* Cache for {@see getAllClassNames()}.
|
||||
*
|
||||
* @var array<int, string>|null
|
||||
* @phpstan-var list<class-string>|null
|
||||
*/
|
||||
protected array|null $classNames = null;
|
||||
|
||||
/**
|
||||
* Appends lookup paths to metadata driver.
|
||||
*
|
||||
* @param array<int, string> $paths
|
||||
*/
|
||||
public function addPaths(array $paths): void
|
||||
{
|
||||
$this->paths = array_unique(array_merge($this->paths, $paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the defined metadata lookup paths.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getPaths(): array
|
||||
{
|
||||
return $this->paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append exclude lookup paths to a metadata driver.
|
||||
*
|
||||
* @param string[] $paths
|
||||
*/
|
||||
public function addExcludePaths(array $paths): void
|
||||
{
|
||||
$this->excludePaths = array_unique(array_merge($this->excludePaths, $paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the defined metadata lookup exclude paths.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getExcludePaths(): array
|
||||
{
|
||||
return $this->excludePaths;
|
||||
}
|
||||
|
||||
/** Gets the file extension used to look for mapping files under. */
|
||||
public function getFileExtension(): string
|
||||
{
|
||||
return $this->fileExtension;
|
||||
}
|
||||
|
||||
/** Sets the file extension used to look for mapping files under. */
|
||||
public function setFileExtension(string $fileExtension): void
|
||||
{
|
||||
$this->fileExtension = $fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @phpstan-param class-string $className
|
||||
*/
|
||||
abstract public function isTransient(string $className): bool;
|
||||
|
||||
/**
|
||||
* Gets the names of all mapped classes known to this driver.
|
||||
*
|
||||
* @return string[] The names of all mapped classes known to this driver.
|
||||
* @phpstan-return list<class-string>
|
||||
*/
|
||||
public function getAllClassNames(): array
|
||||
{
|
||||
if ($this->classNames !== null) {
|
||||
return $this->classNames;
|
||||
}
|
||||
|
||||
if ($this->paths === [] && $this->classLocator === null) {
|
||||
throw MappingException::pathRequiredForDriver(static::class);
|
||||
}
|
||||
|
||||
$classNames = $this->classLocator?->getClassNames() ?? [];
|
||||
|
||||
if ($this->paths !== []) {
|
||||
$classNames = array_unique([
|
||||
...FileClassLocator::createFromDirectories($this->paths, $this->excludePaths, $this->fileExtension)->getClassNames(),
|
||||
...$classNames,
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->classNames = array_values(array_filter(
|
||||
$classNames,
|
||||
fn (string $className): bool => ! $this->isTransient($className),
|
||||
));
|
||||
}
|
||||
}
|
||||
156
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/DefaultFileLocator.php
vendored
Normal file
156
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/DefaultFileLocator.php
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
use Doctrine\Persistence\Mapping\MappingException;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
use function array_unique;
|
||||
use function assert;
|
||||
use function is_dir;
|
||||
use function is_file;
|
||||
use function is_string;
|
||||
use function str_replace;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* 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 array<int, string>
|
||||
*/
|
||||
protected array $paths = [];
|
||||
|
||||
/** The file extension of mapping documents. */
|
||||
protected string|null $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<int, 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(string|array $paths, string|null $fileExtension = null)
|
||||
{
|
||||
$this->addPaths((array) $paths);
|
||||
$this->fileExtension = $fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends lookup paths to metadata driver.
|
||||
*
|
||||
* @param array<int, string> $paths
|
||||
*/
|
||||
public function addPaths(array $paths): void
|
||||
{
|
||||
$this->paths = array_unique([...$this->paths, ...$paths]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the defined metadata lookup paths.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getPaths(): array
|
||||
{
|
||||
return $this->paths;
|
||||
}
|
||||
|
||||
/** Gets the file extension used to look for mapping files under. */
|
||||
public function getFileExtension(): string|null
|
||||
{
|
||||
return $this->fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file extension used to look for mapping files under.
|
||||
*
|
||||
* @param string|null $fileExtension The file extension to set.
|
||||
*/
|
||||
public function setFileExtension(string|null $fileExtension): void
|
||||
{
|
||||
$this->fileExtension = $fileExtension;
|
||||
}
|
||||
|
||||
public function findMappingFile(string $className): string
|
||||
{
|
||||
$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(string $globalBasename): array
|
||||
{
|
||||
if ($this->paths === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$classes = [];
|
||||
|
||||
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!
|
||||
|
||||
assert(is_string($fileName));
|
||||
/** @phpstan-var class-string */
|
||||
$class = str_replace('.', '\\', $fileName);
|
||||
$classes[] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
public function fileExists(string $className): bool
|
||||
{
|
||||
$fileName = str_replace('\\', '.', $className) . $this->fileExtension;
|
||||
|
||||
// Check whether file exists
|
||||
foreach ($this->paths as $path) {
|
||||
if (is_file($path . DIRECTORY_SEPARATOR . $fileName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
143
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/FileClassLocator.php
vendored
Normal file
143
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/FileClassLocator.php
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
use AppendIterator;
|
||||
use CallbackFilterIterator;
|
||||
use Doctrine\Persistence\Mapping\MappingException;
|
||||
use FilesystemIterator;
|
||||
use InvalidArgumentException;
|
||||
use Iterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use ReflectionClass;
|
||||
use RegexIterator;
|
||||
use SplFileInfo;
|
||||
|
||||
use function array_key_exists;
|
||||
use function array_map;
|
||||
use function assert;
|
||||
use function get_debug_type;
|
||||
use function get_declared_classes;
|
||||
use function is_dir;
|
||||
use function preg_quote;
|
||||
use function realpath;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function str_starts_with;
|
||||
|
||||
/**
|
||||
* ClassLocator implementation that uses a list of file names to locate PHP files
|
||||
* and extract class names from them.
|
||||
*
|
||||
* It is compatible with the Symfony Finder component, but does not require it.
|
||||
*/
|
||||
final class FileClassLocator implements ClassLocator
|
||||
{
|
||||
/** @param iterable<SplFileInfo> $files An iterable of files to include. */
|
||||
public function __construct(
|
||||
private iterable $files,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return list<class-string> */
|
||||
public function getClassNames(): array
|
||||
{
|
||||
$includedFiles = [];
|
||||
|
||||
foreach ($this->files as $file) {
|
||||
// @phpstan-ignore function.alreadyNarrowedType, instanceof.alwaysTrue
|
||||
assert($file instanceof SplFileInfo, new InvalidArgumentException(sprintf('Expected an iterable of SplFileInfo, got %s', get_debug_type($file))));
|
||||
|
||||
// Skip non-files
|
||||
if (! $file->isFile()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// getRealPath() returns false if the file is in a phar archive
|
||||
// @phpstan-ignore ternary.shortNotAllowed (false is the only falsy value getRealPath() may return)
|
||||
$fileName = $file->getRealPath() ?: $file->getPathname();
|
||||
|
||||
$includedFiles[$fileName] = true;
|
||||
require_once $fileName;
|
||||
}
|
||||
|
||||
$classes = [];
|
||||
foreach (get_declared_classes() as $className) {
|
||||
$fileName = (new ReflectionClass($className))->getFileName();
|
||||
|
||||
if ($fileName === false || ! array_key_exists($fileName, $includedFiles)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classes[] = $className;
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a FileClassLocator from an array of directories.
|
||||
*
|
||||
* @param list<string> $directories
|
||||
* @param list<string> $excludedDirectories Directories to exclude from the search.
|
||||
* @param string $fileExtension The file extension to look for (default is '.php').
|
||||
*
|
||||
* @throws MappingException if any of the directories are not valid.
|
||||
*/
|
||||
public static function createFromDirectories(
|
||||
array $directories,
|
||||
array $excludedDirectories = [],
|
||||
string $fileExtension = '.php',
|
||||
): self {
|
||||
$filesIterator = new AppendIterator();
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
if (! is_dir($directory)) {
|
||||
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($directory);
|
||||
}
|
||||
|
||||
/** @var Iterator<array-key,SplFileInfo> $iterator */
|
||||
$iterator = new RegexIterator(
|
||||
new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY,
|
||||
),
|
||||
sprintf('/%s$/', preg_quote($fileExtension, '/')),
|
||||
RegexIterator::MATCH,
|
||||
);
|
||||
|
||||
$filesIterator->append($iterator);
|
||||
}
|
||||
|
||||
if ($excludedDirectories !== []) {
|
||||
$excludedDirectories = array_map(
|
||||
// realpath() returns false if the file is in a phar archive
|
||||
// @phpstan-ignore ternary.shortNotAllowed (false is the only falsy value realpath() may return)
|
||||
static fn (string $dir): string => str_replace('\\', '/', realpath($dir) ?: $dir),
|
||||
$excludedDirectories,
|
||||
);
|
||||
|
||||
$filesIterator = new CallbackFilterIterator(
|
||||
$filesIterator,
|
||||
static function (SplFileInfo $file) use ($excludedDirectories): bool {
|
||||
// getRealPath() returns false if the file is in a phar archive
|
||||
// @phpstan-ignore ternary.shortNotAllowed (false is the only falsy value getRealPath() may return)
|
||||
$sourceFile = str_replace('\\', '/', $file->getRealPath() ?: $file->getPathname());
|
||||
|
||||
foreach ($excludedDirectories as $excludedDirectory) {
|
||||
if (str_starts_with($sourceFile, $excludedDirectory)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return new self($filesIterator);
|
||||
}
|
||||
}
|
||||
182
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/FileDriver.php
vendored
Normal file
182
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/FileDriver.php
vendored
Normal file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Persistence\Mapping\MappingException;
|
||||
|
||||
use function array_keys;
|
||||
use function array_unique;
|
||||
use function array_values;
|
||||
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 '.'.
|
||||
*
|
||||
* @template T
|
||||
*/
|
||||
abstract class FileDriver implements MappingDriver
|
||||
{
|
||||
protected FileLocator $locator;
|
||||
|
||||
/**
|
||||
* @var mixed[]|null
|
||||
* @phpstan-var array<class-string, T>|null
|
||||
*/
|
||||
protected array|null $classCache = null;
|
||||
protected string $globalBasename = '';
|
||||
|
||||
/**
|
||||
* Initializes a new FileDriver that looks in the given path(s) for mapping
|
||||
* documents and operates in the specified operating mode.
|
||||
*
|
||||
* @param string|array<int, string>|FileLocator $locator A FileLocator or one/multiple paths
|
||||
* where mapping documents can be found.
|
||||
*/
|
||||
public function __construct(string|array|FileLocator $locator, string|null $fileExtension = null)
|
||||
{
|
||||
if ($locator instanceof FileLocator) {
|
||||
$this->locator = $locator;
|
||||
} else {
|
||||
$this->locator = new DefaultFileLocator((array) $locator, $fileExtension);
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the global basename. */
|
||||
public function setGlobalBasename(string $file): void
|
||||
{
|
||||
$this->globalBasename = $file;
|
||||
}
|
||||
|
||||
/** Retrieves the global basename. */
|
||||
public function getGlobalBasename(): string
|
||||
{
|
||||
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.
|
||||
*
|
||||
* @phpstan-param class-string $className
|
||||
*
|
||||
* @return T The element of schema meta data.
|
||||
*
|
||||
* @throws MappingException
|
||||
*/
|
||||
public function getElement(string $className): mixed
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
public function isTransient(string $className): bool
|
||||
{
|
||||
if ($this->classCache === null) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
if (isset($this->classCache[$className])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! $this->locator->fileExists($className);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getAllClassNames(): array
|
||||
{
|
||||
if ($this->classCache === null) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
if ($this->classCache === []) {
|
||||
return $this->locator->getAllClassNames($this->globalBasename);
|
||||
}
|
||||
|
||||
/** @phpstan-var array<class-string, ClassMetadata<object>> $classCache */
|
||||
$classCache = $this->classCache;
|
||||
|
||||
/** @var list<class-string> $keys */
|
||||
$keys = array_keys($classCache);
|
||||
|
||||
return array_values(array_unique([...$keys, ...$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 mixed[]
|
||||
* @phpstan-return array<class-string, T>
|
||||
*/
|
||||
abstract protected function loadMappingFile(string $file): array;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
protected function initialize(): void
|
||||
{
|
||||
$this->classCache = [];
|
||||
if ($this->globalBasename === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->locator->getPaths() as $path) {
|
||||
$file = $path . '/' . $this->globalBasename . $this->locator->getFileExtension();
|
||||
if (! is_file($file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->classCache = [...$this->classCache, ...$this->loadMappingFile($file)];
|
||||
}
|
||||
}
|
||||
|
||||
/** Retrieves the locator used to discover mapping files by className. */
|
||||
public function getLocator(): FileLocator
|
||||
{
|
||||
return $this->locator;
|
||||
}
|
||||
|
||||
/** Sets the locator used to discover mapping files by className. */
|
||||
public function setLocator(FileLocator $locator): void
|
||||
{
|
||||
$this->locator = $locator;
|
||||
}
|
||||
}
|
||||
40
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/FileLocator.php
vendored
Normal file
40
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/FileLocator.php
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
/**
|
||||
* 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. */
|
||||
public function findMappingFile(string $className): string;
|
||||
|
||||
/**
|
||||
* Gets all class names that are found with this file locator.
|
||||
*
|
||||
* @param string $globalBasename Passed to allow excluding the basename.
|
||||
*
|
||||
* @return array<int, string>
|
||||
* @phpstan-return list<class-string>
|
||||
*/
|
||||
public function getAllClassNames(string $globalBasename): array;
|
||||
|
||||
/** Checks if a file can be found for this class name. */
|
||||
public function fileExists(string $className): bool;
|
||||
|
||||
/**
|
||||
* Gets all the paths that this file locator looks for mapping files.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getPaths(): array;
|
||||
|
||||
/** Gets the file extension that mapping files are suffixed with. */
|
||||
public function getFileExtension(): string|null;
|
||||
}
|
||||
39
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/MappingDriver.php
vendored
Normal file
39
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/MappingDriver.php
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* Contract for metadata drivers.
|
||||
*/
|
||||
interface MappingDriver
|
||||
{
|
||||
/**
|
||||
* Loads the metadata for the specified class into the provided container.
|
||||
*
|
||||
* @phpstan-param class-string<T> $className
|
||||
* @phpstan-param ClassMetadata<T> $metadata
|
||||
*
|
||||
* @template T of object
|
||||
*/
|
||||
public function loadMetadataForClass(string $className, ClassMetadata $metadata): void;
|
||||
|
||||
/**
|
||||
* Gets the names of all mapped classes known to this driver.
|
||||
*
|
||||
* @return array<int, string> The names of all mapped classes known to this driver.
|
||||
* @phpstan-return list<class-string>
|
||||
*/
|
||||
public function getAllClassNames(): array;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @phpstan-param class-string $className
|
||||
*/
|
||||
public function isTransient(string $className): bool;
|
||||
}
|
||||
122
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/MappingDriverChain.php
vendored
Normal file
122
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/MappingDriverChain.php
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Persistence\Mapping\MappingException;
|
||||
|
||||
use function array_keys;
|
||||
use function spl_object_id;
|
||||
use function str_starts_with;
|
||||
|
||||
/**
|
||||
* The DriverChain allows you to add multiple other mapping drivers for
|
||||
* certain namespaces.
|
||||
*/
|
||||
class MappingDriverChain implements MappingDriver
|
||||
{
|
||||
/**
|
||||
* The default driver.
|
||||
*/
|
||||
private MappingDriver|null $defaultDriver = null;
|
||||
|
||||
/** @var array<string, MappingDriver> */
|
||||
private array $drivers = [];
|
||||
|
||||
/** Gets the default driver. */
|
||||
public function getDefaultDriver(): MappingDriver|null
|
||||
{
|
||||
return $this->defaultDriver;
|
||||
}
|
||||
|
||||
/** Set the default driver. */
|
||||
public function setDefaultDriver(MappingDriver $driver): void
|
||||
{
|
||||
$this->defaultDriver = $driver;
|
||||
}
|
||||
|
||||
/** Adds a nested driver. */
|
||||
public function addDriver(MappingDriver $nestedDriver, string $namespace): void
|
||||
{
|
||||
$this->drivers[$namespace] = $nestedDriver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of nested drivers.
|
||||
*
|
||||
* @return array<string, MappingDriver> $drivers
|
||||
*/
|
||||
public function getDrivers(): array
|
||||
{
|
||||
return $this->drivers;
|
||||
}
|
||||
|
||||
public function loadMetadataForClass(string $className, ClassMetadata $metadata): void
|
||||
{
|
||||
foreach ($this->drivers as $namespace => $driver) {
|
||||
if (str_starts_with($className, $namespace)) {
|
||||
$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(): array
|
||||
{
|
||||
$classNames = [];
|
||||
$driverClasses = [];
|
||||
|
||||
foreach ($this->drivers as $namespace => $driver) {
|
||||
$oid = spl_object_id($driver);
|
||||
|
||||
if (! isset($driverClasses[$oid])) {
|
||||
$driverClasses[$oid] = $driver->getAllClassNames();
|
||||
}
|
||||
|
||||
foreach ($driverClasses[$oid] as $className) {
|
||||
if (! str_starts_with($className, $namespace)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classNames[$className] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->defaultDriver !== null) {
|
||||
foreach ($this->defaultDriver->getAllClassNames() as $className) {
|
||||
$classNames[$className] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return array_keys($classNames);
|
||||
}
|
||||
|
||||
public function isTransient(string $className): bool
|
||||
{
|
||||
foreach ($this->drivers as $namespace => $driver) {
|
||||
if (str_starts_with($className, $namespace)) {
|
||||
return $driver->isTransient($className);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->defaultDriver !== null) {
|
||||
return $this->defaultDriver->isTransient($className);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
43
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/PHPDriver.php
vendored
Normal file
43
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/PHPDriver.php
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* The PHPDriver includes php files which just populate ClassMetadataInfo
|
||||
* instances with plain PHP code.
|
||||
*
|
||||
* @template-extends FileDriver<ClassMetadata<object>>
|
||||
*/
|
||||
class PHPDriver extends FileDriver
|
||||
{
|
||||
/** @phpstan-var ClassMetadata<object> */
|
||||
protected ClassMetadata $metadata;
|
||||
|
||||
/** @param string|array<int, string>|FileLocator $locator */
|
||||
public function __construct(string|array|FileLocator $locator)
|
||||
{
|
||||
parent::__construct($locator, '.php');
|
||||
}
|
||||
|
||||
public function loadMetadataForClass(string $className, ClassMetadata $metadata): void
|
||||
{
|
||||
$this->metadata = $metadata;
|
||||
|
||||
$this->loadMappingFile($this->locator->findMappingFile($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function loadMappingFile(string $file): array
|
||||
{
|
||||
$metadata = $this->metadata;
|
||||
include $file;
|
||||
|
||||
return [$metadata->getName() => $metadata];
|
||||
}
|
||||
}
|
||||
121
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/StaticPHPDriver.php
vendored
Normal file
121
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/StaticPHPDriver.php
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Persistence\Mapping\MappingException;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use ReflectionClass;
|
||||
|
||||
use function array_unique;
|
||||
use function get_declared_classes;
|
||||
use function in_array;
|
||||
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 array<int, string>
|
||||
*/
|
||||
private array $paths = [];
|
||||
|
||||
/**
|
||||
* Map of all class names.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @phpstan-var list<class-string>
|
||||
*/
|
||||
private array|null $classNames = null;
|
||||
|
||||
/** @param array<int, string>|string $paths */
|
||||
public function __construct(array|string $paths)
|
||||
{
|
||||
$this->addPaths((array) $paths);
|
||||
}
|
||||
|
||||
/** @param array<int, string> $paths */
|
||||
public function addPaths(array $paths): void
|
||||
{
|
||||
$this->paths = array_unique([...$this->paths, ...$paths]);
|
||||
}
|
||||
|
||||
public function loadMetadataForClass(string $className, ClassMetadata $metadata): void
|
||||
{
|
||||
$className::loadMetadata($metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @todo Same code exists in ColocatedMappingDriver, should we re-use it
|
||||
* somehow or not worry about it?
|
||||
*/
|
||||
public function getAllClassNames(): array
|
||||
{
|
||||
if ($this->classNames !== null) {
|
||||
return $this->classNames;
|
||||
}
|
||||
|
||||
if ($this->paths === []) {
|
||||
throw MappingException::pathRequiredForDriver(static::class);
|
||||
}
|
||||
|
||||
$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, true) || $this->isTransient($className)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classes[] = $className;
|
||||
}
|
||||
|
||||
$this->classNames = $classes;
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
public function isTransient(string $className): bool
|
||||
{
|
||||
return ! method_exists($className, 'loadMetadata');
|
||||
}
|
||||
}
|
||||
245
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/SymfonyFileLocator.php
vendored
Normal file
245
vendor/doctrine/persistence/src/Persistence/Mapping/Driver/SymfonyFileLocator.php
vendored
Normal file
@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping\Driver;
|
||||
|
||||
use Doctrine\Persistence\Mapping\MappingException;
|
||||
use InvalidArgumentException;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use RuntimeException;
|
||||
|
||||
use function array_keys;
|
||||
use function assert;
|
||||
use function is_dir;
|
||||
use function is_file;
|
||||
use function is_int;
|
||||
use function realpath;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function str_starts_with;
|
||||
use function strlen;
|
||||
use function strrpos;
|
||||
use function strtr;
|
||||
use function substr;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* 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 array<int, string>
|
||||
*/
|
||||
protected array $paths = [];
|
||||
|
||||
/**
|
||||
* A map of mapping directory path to namespace prefix used to expand class shortnames.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected array $prefixes = [];
|
||||
|
||||
/** File extension that is searched for. */
|
||||
protected string|null $fileExtension;
|
||||
|
||||
/**
|
||||
* Represents PHP namespace delimiters when looking for files
|
||||
*/
|
||||
private readonly string $nsSeparator;
|
||||
|
||||
/**
|
||||
* @param array<string, string> $prefixes
|
||||
* @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,
|
||||
string $fileExtension = '',
|
||||
string $nsSeparator = '.',
|
||||
) {
|
||||
$this->addNamespacePrefixes($prefixes);
|
||||
$this->fileExtension = $fileExtension;
|
||||
|
||||
if ($nsSeparator === '') {
|
||||
throw new InvalidArgumentException('Namespace separator should not be empty');
|
||||
}
|
||||
|
||||
$this->nsSeparator = $nsSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Namespace Prefixes.
|
||||
*
|
||||
* @param array<string, string> $prefixes
|
||||
*/
|
||||
public function addNamespacePrefixes(array $prefixes): void
|
||||
{
|
||||
$this->prefixes = [...$this->prefixes, ...$prefixes];
|
||||
$this->paths = [...$this->paths, ...array_keys($prefixes)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Namespace Prefixes.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNamespacePrefixes(): array
|
||||
{
|
||||
return $this->prefixes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPaths(): array
|
||||
{
|
||||
return $this->paths;
|
||||
}
|
||||
|
||||
public function getFileExtension(): string|null
|
||||
{
|
||||
return $this->fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file extension used to look for mapping files under.
|
||||
*
|
||||
* @param string $fileExtension The file extension to set.
|
||||
*/
|
||||
public function setFileExtension(string $fileExtension): void
|
||||
{
|
||||
$this->fileExtension = $fileExtension;
|
||||
}
|
||||
|
||||
public function fileExists(string $className): bool
|
||||
{
|
||||
$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 (! str_starts_with($className, $prefix . '\\')) {
|
||||
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(string|null $globalBasename = null): array
|
||||
{
|
||||
if ($this->paths === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$classes = [];
|
||||
|
||||
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!
|
||||
if (isset($this->prefixes[$path])) {
|
||||
// Calculate namespace suffix for given prefix as a relative path from basepath to file path
|
||||
$nsSuffix = strtr(
|
||||
substr($this->realpath($file->getPath()), strlen($this->realpath($path))),
|
||||
$this->nsSeparator,
|
||||
'\\',
|
||||
);
|
||||
|
||||
/** @phpstan-var class-string */
|
||||
$class = $this->prefixes[$path] . str_replace(DIRECTORY_SEPARATOR, '\\', $nsSuffix) . '\\' . str_replace($this->nsSeparator, '\\', $fileName);
|
||||
} else {
|
||||
/** @phpstan-var class-string */
|
||||
$class = str_replace($this->nsSeparator, '\\', $fileName);
|
||||
}
|
||||
|
||||
$classes[] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
public function findMappingFile(string $className): string
|
||||
{
|
||||
$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 (! str_starts_with($className, $prefix . '\\')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filename = $path . '/' . strtr(substr($className, strlen($prefix) + 1), '\\', $this->nsSeparator) . $this->fileExtension;
|
||||
if (is_file($filename)) {
|
||||
return $filename;
|
||||
}
|
||||
}
|
||||
|
||||
$pos = strrpos($className, '\\');
|
||||
assert(is_int($pos));
|
||||
|
||||
throw MappingException::mappingFileNotFound(
|
||||
$className,
|
||||
substr($className, $pos + 1) . $this->fileExtension,
|
||||
);
|
||||
}
|
||||
|
||||
private function realpath(string $path): string
|
||||
{
|
||||
$realpath = realpath($path);
|
||||
|
||||
if ($realpath === false) {
|
||||
throw new RuntimeException(sprintf('Could not get realpath for %s', $path));
|
||||
}
|
||||
|
||||
return $realpath;
|
||||
}
|
||||
}
|
||||
80
vendor/doctrine/persistence/src/Persistence/Mapping/MappingException.php
vendored
Normal file
80
vendor/doctrine/persistence/src/Persistence/Mapping/MappingException.php
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping;
|
||||
|
||||
use Exception;
|
||||
|
||||
use function implode;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* A MappingException indicates that something is wrong with the mapping setup.
|
||||
*/
|
||||
class MappingException extends Exception
|
||||
{
|
||||
/** @param array<int, string> $namespaces */
|
||||
public static function classNotFoundInNamespaces(
|
||||
string $className,
|
||||
array $namespaces,
|
||||
): self {
|
||||
return new self(sprintf(
|
||||
"The class '%s' was not found in the chain configured namespaces %s",
|
||||
$className,
|
||||
implode(', ', $namespaces),
|
||||
));
|
||||
}
|
||||
|
||||
/** @param class-string $driverClassName */
|
||||
public static function pathRequiredForDriver(string $driverClassName): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
'Specifying source file paths to your entities is required when using %s to retrieve all class names.',
|
||||
$driverClassName,
|
||||
));
|
||||
}
|
||||
|
||||
public static function fileMappingDriversRequireConfiguredDirectoryPath(
|
||||
string|null $path = null,
|
||||
): self {
|
||||
if ($path !== null) {
|
||||
$path = '[' . $path . ']';
|
||||
}
|
||||
|
||||
return new self(sprintf(
|
||||
'File mapping drivers must have a valid directory path, ' .
|
||||
'however the given path %s seems to be incorrect!',
|
||||
(string) $path,
|
||||
));
|
||||
}
|
||||
|
||||
public static function mappingFileNotFound(string $entityName, string $fileName): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
"No mapping file found named '%s' for class '%s'.",
|
||||
$fileName,
|
||||
$entityName,
|
||||
));
|
||||
}
|
||||
|
||||
public static function invalidMappingFile(string $entityName, string $fileName): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
"Invalid mapping file '%s' for class '%s'.",
|
||||
$fileName,
|
||||
$entityName,
|
||||
));
|
||||
}
|
||||
|
||||
public static function nonExistingClass(string $className): self
|
||||
{
|
||||
return new self(sprintf("Class '%s' does not exist", $className));
|
||||
}
|
||||
|
||||
/** @param class-string $className */
|
||||
public static function classIsAnonymous(string $className): self
|
||||
{
|
||||
return new self(sprintf('Class "%s" is anonymous', $className));
|
||||
}
|
||||
}
|
||||
19
vendor/doctrine/persistence/src/Persistence/Mapping/ProxyClassNameResolver.php
vendored
Normal file
19
vendor/doctrine/persistence/src/Persistence/Mapping/ProxyClassNameResolver.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Persistence\Proxy;
|
||||
|
||||
interface ProxyClassNameResolver
|
||||
{
|
||||
/**
|
||||
* @phpstan-param class-string<Proxy<T>>|class-string<T> $className
|
||||
*
|
||||
* @phpstan-return class-string<T>
|
||||
*
|
||||
* @template T of object
|
||||
*/
|
||||
public function resolveClassName(string $className): string;
|
||||
}
|
||||
64
vendor/doctrine/persistence/src/Persistence/Mapping/ReflectionService.php
vendored
Normal file
64
vendor/doctrine/persistence/src/Persistence/Mapping/ReflectionService.php
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Very simple reflection service abstraction.
|
||||
*
|
||||
* This is required inside metadata layers that may require either
|
||||
* static or runtime reflection.
|
||||
*/
|
||||
interface ReflectionService
|
||||
{
|
||||
/**
|
||||
* Returns an array of the parent classes (not interfaces) for the given class.
|
||||
*
|
||||
* @phpstan-param class-string $class
|
||||
*
|
||||
* @return string[]
|
||||
* @phpstan-return class-string[]
|
||||
*
|
||||
* @throws MappingException
|
||||
*/
|
||||
public function getParentClasses(string $class): array;
|
||||
|
||||
/**
|
||||
* Returns the shortname of a class.
|
||||
*
|
||||
* @phpstan-param class-string $class
|
||||
*/
|
||||
public function getClassShortName(string $class): string;
|
||||
|
||||
/** @phpstan-param class-string $class */
|
||||
public function getClassNamespace(string $class): string;
|
||||
|
||||
/**
|
||||
* Returns a reflection class instance or null.
|
||||
*
|
||||
* @phpstan-param class-string<T> $class
|
||||
*
|
||||
* @phpstan-return ReflectionClass<T>
|
||||
*
|
||||
* @template T of object
|
||||
*/
|
||||
public function getClass(string $class): ReflectionClass;
|
||||
|
||||
/**
|
||||
* Returns an accessible property or null.
|
||||
*
|
||||
* @phpstan-param class-string $class
|
||||
*/
|
||||
public function getAccessibleProperty(string $class, string $property): ReflectionProperty|null;
|
||||
|
||||
/**
|
||||
* Checks if the class have a public method with the given name.
|
||||
*
|
||||
* @phpstan-param class-string $class
|
||||
*/
|
||||
public function hasPublicMethod(string $class, string $method): bool;
|
||||
}
|
||||
95
vendor/doctrine/persistence/src/Persistence/Mapping/RuntimeReflectionService.php
vendored
Normal file
95
vendor/doctrine/persistence/src/Persistence/Mapping/RuntimeReflectionService.php
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
|
||||
use Doctrine\Persistence\Reflection\TypedNoDefaultReflectionProperty;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use ReflectionMethod;
|
||||
|
||||
use function array_key_exists;
|
||||
use function assert;
|
||||
use function class_exists;
|
||||
use function class_parents;
|
||||
use function phpversion;
|
||||
use function version_compare;
|
||||
|
||||
/**
|
||||
* PHP Runtime Reflection Service.
|
||||
*/
|
||||
class RuntimeReflectionService implements ReflectionService
|
||||
{
|
||||
private readonly bool $supportsTypedPropertiesWorkaround;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->supportsTypedPropertiesWorkaround = version_compare(phpversion(), '7.4.0') >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getParentClasses(string $class): array
|
||||
{
|
||||
if (! class_exists($class)) {
|
||||
throw MappingException::nonExistingClass($class);
|
||||
}
|
||||
|
||||
$parents = class_parents($class);
|
||||
|
||||
assert($parents !== false);
|
||||
|
||||
return $parents;
|
||||
}
|
||||
|
||||
public function getClassShortName(string $class): string
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($class);
|
||||
|
||||
return $reflectionClass->getShortName();
|
||||
}
|
||||
|
||||
public function getClassNamespace(string $class): string
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($class);
|
||||
|
||||
return $reflectionClass->getNamespaceName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param class-string<T> $class
|
||||
*
|
||||
* @phpstan-return ReflectionClass<T>
|
||||
*
|
||||
* @template T of object
|
||||
*/
|
||||
public function getClass(string $class): ReflectionClass
|
||||
{
|
||||
return new ReflectionClass($class);
|
||||
}
|
||||
|
||||
public function getAccessibleProperty(string $class, string $property): RuntimeReflectionProperty
|
||||
{
|
||||
$reflectionProperty = new RuntimeReflectionProperty($class, $property);
|
||||
|
||||
if ($this->supportsTypedPropertiesWorkaround && ! array_key_exists($property, $this->getClass($class)->getDefaultProperties())) {
|
||||
$reflectionProperty = new TypedNoDefaultReflectionProperty($class, $property);
|
||||
}
|
||||
|
||||
return $reflectionProperty;
|
||||
}
|
||||
|
||||
public function hasPublicMethod(string $class, string $method): bool
|
||||
{
|
||||
try {
|
||||
$reflectionMethod = new ReflectionMethod($class, $method);
|
||||
} catch (ReflectionException) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $reflectionMethod->isPublic();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user