123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
-
-
- namespace Doctrine\ORM\Mapping\Driver;
-
- use Doctrine\ORM\Mapping\ClassMetadataInfo,
- Doctrine\ORM\Mapping\MappingException;
-
-
- class StaticPHPDriver implements Driver
- {
-
-
- private $_paths = array();
-
-
-
- private $_classNames;
-
-
-
- private $_fileExtension = '.php';
-
- public function __construct($paths)
- {
- $this->addPaths((array) $paths);
- }
-
- public function addPaths(array $paths)
- {
- $this->_paths = array_unique(array_merge($this->_paths, $paths));
- }
-
-
-
- public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
- {
- call_user_func_array(array($className, 'loadMetadata'), array($metadata));
- }
-
-
-
- public function getAllClassNames()
- {
- if ($this->_classNames !== null) {
- return $this->_classNames;
- }
-
- if (!$this->_paths) {
- throw MappingException::pathRequired();
- }
-
- $classes = array();
- $includedFiles = array();
-
- foreach ($this->_paths as $path) {
- if (!is_dir($path)) {
- throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
- }
-
- $iterator = new \RecursiveIteratorIterator(
- new \RecursiveDirectoryIterator($path),
- \RecursiveIteratorIterator::LEAVES_ONLY
- );
-
- foreach ($iterator as $file) {
- if (($fileName = $file->getBasename($this->_fileExtension)) == $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)) {
- $classes[] = $className;
- }
- }
-
- $this->_classNames = $classes;
-
- return $classes;
- }
-
-
-
- public function isTransient($className)
- {
- return method_exists($className, 'loadMetadata') ? false : true;
- }
- }
|