From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Persistence/Mapping/Driver/StaticPHPDriver.php | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 vendor/doctrine/persistence/src/Persistence/Mapping/Driver/StaticPHPDriver.php (limited to 'vendor/doctrine/persistence/src/Persistence/Mapping/Driver/StaticPHPDriver.php') diff --git a/vendor/doctrine/persistence/src/Persistence/Mapping/Driver/StaticPHPDriver.php b/vendor/doctrine/persistence/src/Persistence/Mapping/Driver/StaticPHPDriver.php new file mode 100644 index 0000000..bbcff75 --- /dev/null +++ b/vendor/doctrine/persistence/src/Persistence/Mapping/Driver/StaticPHPDriver.php @@ -0,0 +1,132 @@ + + */ + private $paths = []; + + /** + * Map of all class names. + * + * @var array + * @psalm-var list + */ + private $classNames; + + /** @param array|string $paths */ + public function __construct($paths) + { + $this->addPaths((array) $paths); + } + + /** + * @param array $paths + * + * @return void + */ + public function addPaths(array $paths) + { + $this->paths = array_unique(array_merge($this->paths, $paths)); + } + + /** + * {@inheritDoc} + */ + public function loadMetadataForClass(string $className, ClassMetadata $metadata) + { + $className::loadMetadata($metadata); + } + + /** + * {@inheritDoc} + * + * @todo Same code exists in ColocatedMappingDriver, 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::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; + } + + /** + * {@inheritDoc} + */ + public function isTransient(string $className) + { + return ! method_exists($className, 'loadMetadata'); + } +} -- cgit v1.2.3