composer package updates
[openemr.git] / vendor / doctrine / common / lib / Doctrine / Common / Persistence / Mapping / Driver / StaticPHPDriver.php
blob8e37e5a7a16fce8209770d727dc7d3f941063def
1 <?php
2 /*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\Common\Persistence\Mapping\Driver;
22 use Doctrine\Common\Persistence\Mapping\ClassMetadata;
23 use Doctrine\Common\Persistence\Mapping\MappingException;
25 /**
26 * The StaticPHPDriver calls a static loadMetadata() method on your entity
27 * classes where you can manually populate the ClassMetadata instance.
29 * @link www.doctrine-project.org
30 * @since 2.2
31 * @author Benjamin Eberlei <kontakt@beberlei.de>
32 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
33 * @author Jonathan H. Wage <jonwage@gmail.com>
34 * @author Roman Borschel <roman@code-factory.org>
36 class StaticPHPDriver implements MappingDriver
38 /**
39 * Paths of entity directories.
41 * @var array
43 private $paths = [];
45 /**
46 * Map of all class names.
48 * @var array
50 private $classNames;
52 /**
53 * Constructor.
55 * @param array|string $paths
57 public function __construct($paths)
59 $this->addPaths((array) $paths);
62 /**
63 * Adds paths.
65 * @param array $paths
67 * @return void
69 public function addPaths(array $paths)
71 $this->paths = array_unique(array_merge($this->paths, $paths));
74 /**
75 * {@inheritdoc}
77 public function loadMetadataForClass($className, ClassMetadata $metadata)
79 $className::loadMetadata($metadata);
82 /**
83 * {@inheritDoc}
84 * @todo Same code exists in AnnotationDriver, should we re-use it somehow or not worry about it?
86 public function getAllClassNames()
88 if ($this->classNames !== null) {
89 return $this->classNames;
92 if (!$this->paths) {
93 throw MappingException::pathRequired();
96 $classes = [];
97 $includedFiles = [];
99 foreach ($this->paths as $path) {
100 if (!is_dir($path)) {
101 throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
104 $iterator = new \RecursiveIteratorIterator(
105 new \RecursiveDirectoryIterator($path),
106 \RecursiveIteratorIterator::LEAVES_ONLY
109 foreach ($iterator as $file) {
110 if ($file->getBasename('.php') == $file->getBasename()) {
111 continue;
114 $sourceFile = realpath($file->getPathName());
115 require_once $sourceFile;
116 $includedFiles[] = $sourceFile;
120 $declared = get_declared_classes();
122 foreach ($declared as $className) {
123 $rc = new \ReflectionClass($className);
124 $sourceFile = $rc->getFileName();
125 if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
126 $classes[] = $className;
130 $this->classNames = $classes;
132 return $classes;
136 * {@inheritdoc}
138 public function isTransient($className)
140 return ! method_exists($className, 'loadMetadata');