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;
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
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
39
* Paths of entity directories.
43
private $paths = array();
46
* Map of all class names.
55
* @param array|string $paths
57
public function __construct($paths)
59
$this->addPaths((array) $paths);
69
public function addPaths(array $paths)
71
$this->paths = array_unique(array_merge($this->paths, $paths));
77
public function loadMetadataForClass($className, ClassMetadata $metadata)
79
$className::loadMetadata($metadata);
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;
93
throw MappingException::pathRequired();
97
$includedFiles = array();
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()) {
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;
138
public function isTransient($className)
140
return ! method_exists($className, 'loadMetadata');