AnnotationDriver.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the LGPL. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\ORM\Mapping\Driver;
  20. use Doctrine\Common\Cache\ArrayCache,
  21. Doctrine\Common\Annotations\AnnotationReader,
  22. Doctrine\Common\Annotations\AnnotationRegistry,
  23. Doctrine\ORM\Mapping\ClassMetadataInfo,
  24. Doctrine\ORM\Mapping\MappingException;
  25. /**
  26. * The AnnotationDriver reads the mapping metadata from docblock annotations.
  27. *
  28. * @since 2.0
  29. * @author Benjamin Eberlei <kontakt@beberlei.de>
  30. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  31. * @author Jonathan H. Wage <jonwage@gmail.com>
  32. * @author Roman Borschel <roman@code-factory.org>
  33. */
  34. class AnnotationDriver implements Driver
  35. {
  36. /**
  37. * The AnnotationReader.
  38. *
  39. * @var AnnotationReader
  40. */
  41. protected $_reader;
  42. /**
  43. * The paths where to look for mapping files.
  44. *
  45. * @var array
  46. */
  47. protected $_paths = array();
  48. /**
  49. * The file extension of mapping documents.
  50. *
  51. * @var string
  52. */
  53. protected $_fileExtension = '.php';
  54. /**
  55. * @param array
  56. */
  57. protected $_classNames;
  58. /**
  59. * Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
  60. * docblock annotations.
  61. *
  62. * @param AnnotationReader $reader The AnnotationReader to use, duck-typed.
  63. * @param string|array $paths One or multiple paths where mapping classes can be found.
  64. */
  65. public function __construct($reader, $paths = null)
  66. {
  67. $this->_reader = $reader;
  68. if ($paths) {
  69. $this->addPaths((array) $paths);
  70. }
  71. }
  72. /**
  73. * Append lookup paths to metadata driver.
  74. *
  75. * @param array $paths
  76. */
  77. public function addPaths(array $paths)
  78. {
  79. $this->_paths = array_unique(array_merge($this->_paths, $paths));
  80. }
  81. /**
  82. * Retrieve the defined metadata lookup paths.
  83. *
  84. * @return array
  85. */
  86. public function getPaths()
  87. {
  88. return $this->_paths;
  89. }
  90. /**
  91. * Get the file extension used to look for mapping files under
  92. *
  93. * @return void
  94. */
  95. public function getFileExtension()
  96. {
  97. return $this->_fileExtension;
  98. }
  99. /**
  100. * Set the file extension used to look for mapping files under
  101. *
  102. * @param string $fileExtension The file extension to set
  103. * @return void
  104. */
  105. public function setFileExtension($fileExtension)
  106. {
  107. $this->_fileExtension = $fileExtension;
  108. }
  109. /**
  110. * {@inheritdoc}
  111. */
  112. public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
  113. {
  114. $class = $metadata->getReflectionClass();
  115. $classAnnotations = $this->_reader->getClassAnnotations($class);
  116. // Compatibility with Doctrine Common 3.x
  117. if ($classAnnotations && is_int(key($classAnnotations))) {
  118. foreach ($classAnnotations as $annot) {
  119. $classAnnotations[get_class($annot)] = $annot;
  120. }
  121. }
  122. // Evaluate Entity annotation
  123. if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) {
  124. $entityAnnot = $classAnnotations['Doctrine\ORM\Mapping\Entity'];
  125. $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
  126. if ($entityAnnot->readOnly) {
  127. $metadata->markReadOnly();
  128. }
  129. } else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) {
  130. $metadata->isMappedSuperclass = true;
  131. } else {
  132. throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
  133. }
  134. // Evaluate Table annotation
  135. if (isset($classAnnotations['Doctrine\ORM\Mapping\Table'])) {
  136. $tableAnnot = $classAnnotations['Doctrine\ORM\Mapping\Table'];
  137. $primaryTable = array(
  138. 'name' => $tableAnnot->name,
  139. 'schema' => $tableAnnot->schema
  140. );
  141. if ($tableAnnot->indexes !== null) {
  142. foreach ($tableAnnot->indexes as $indexAnnot) {
  143. $primaryTable['indexes'][$indexAnnot->name] = array(
  144. 'columns' => $indexAnnot->columns
  145. );
  146. }
  147. }
  148. if ($tableAnnot->uniqueConstraints !== null) {
  149. foreach ($tableAnnot->uniqueConstraints as $uniqueConstraint) {
  150. $primaryTable['uniqueConstraints'][$uniqueConstraint->name] = array(
  151. 'columns' => $uniqueConstraint->columns
  152. );
  153. }
  154. }
  155. $metadata->setPrimaryTable($primaryTable);
  156. }
  157. // Evaluate NamedQueries annotation
  158. if (isset($classAnnotations['Doctrine\ORM\Mapping\NamedQueries'])) {
  159. $namedQueriesAnnot = $classAnnotations['Doctrine\ORM\Mapping\NamedQueries'];
  160. foreach ($namedQueriesAnnot->value as $namedQuery) {
  161. $metadata->addNamedQuery(array(
  162. 'name' => $namedQuery->name,
  163. 'query' => $namedQuery->query
  164. ));
  165. }
  166. }
  167. // Evaluate InheritanceType annotation
  168. if (isset($classAnnotations['Doctrine\ORM\Mapping\InheritanceType'])) {
  169. $inheritanceTypeAnnot = $classAnnotations['Doctrine\ORM\Mapping\InheritanceType'];
  170. $metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
  171. if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
  172. // Evaluate DiscriminatorColumn annotation
  173. if (isset($classAnnotations['Doctrine\ORM\Mapping\DiscriminatorColumn'])) {
  174. $discrColumnAnnot = $classAnnotations['Doctrine\ORM\Mapping\DiscriminatorColumn'];
  175. $metadata->setDiscriminatorColumn(array(
  176. 'name' => $discrColumnAnnot->name,
  177. 'type' => $discrColumnAnnot->type,
  178. 'length' => $discrColumnAnnot->length
  179. ));
  180. } else {
  181. $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
  182. }
  183. // Evaluate DiscriminatorMap annotation
  184. if (isset($classAnnotations['Doctrine\ORM\Mapping\DiscriminatorMap'])) {
  185. $discrMapAnnot = $classAnnotations['Doctrine\ORM\Mapping\DiscriminatorMap'];
  186. $metadata->setDiscriminatorMap($discrMapAnnot->value);
  187. }
  188. }
  189. }
  190. // Evaluate DoctrineChangeTrackingPolicy annotation
  191. if (isset($classAnnotations['Doctrine\ORM\Mapping\ChangeTrackingPolicy'])) {
  192. $changeTrackingAnnot = $classAnnotations['Doctrine\ORM\Mapping\ChangeTrackingPolicy'];
  193. $metadata->setChangeTrackingPolicy(constant('Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value));
  194. }
  195. // Evaluate annotations on properties/fields
  196. foreach ($class->getProperties() as $property) {
  197. if ($metadata->isMappedSuperclass && ! $property->isPrivate()
  198. ||
  199. $metadata->isInheritedField($property->name)
  200. ||
  201. $metadata->isInheritedAssociation($property->name)) {
  202. continue;
  203. }
  204. $mapping = array();
  205. $mapping['fieldName'] = $property->getName();
  206. // Check for JoinColummn/JoinColumns annotations
  207. $joinColumns = array();
  208. if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) {
  209. $joinColumns[] = array(
  210. 'name' => $joinColumnAnnot->name,
  211. 'referencedColumnName' => $joinColumnAnnot->referencedColumnName,
  212. 'unique' => $joinColumnAnnot->unique,
  213. 'nullable' => $joinColumnAnnot->nullable,
  214. 'onDelete' => $joinColumnAnnot->onDelete,
  215. 'onUpdate' => $joinColumnAnnot->onUpdate,
  216. 'columnDefinition' => $joinColumnAnnot->columnDefinition,
  217. );
  218. } else if ($joinColumnsAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumns')) {
  219. foreach ($joinColumnsAnnot->value as $joinColumn) {
  220. $joinColumns[] = array(
  221. 'name' => $joinColumn->name,
  222. 'referencedColumnName' => $joinColumn->referencedColumnName,
  223. 'unique' => $joinColumn->unique,
  224. 'nullable' => $joinColumn->nullable,
  225. 'onDelete' => $joinColumn->onDelete,
  226. 'onUpdate' => $joinColumn->onUpdate,
  227. 'columnDefinition' => $joinColumn->columnDefinition,
  228. );
  229. }
  230. }
  231. // Field can only be annotated with one of:
  232. // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
  233. if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) {
  234. if ($columnAnnot->type == null) {
  235. throw MappingException::propertyTypeIsRequired($className, $property->getName());
  236. }
  237. $mapping['type'] = $columnAnnot->type;
  238. $mapping['length'] = $columnAnnot->length;
  239. $mapping['precision'] = $columnAnnot->precision;
  240. $mapping['scale'] = $columnAnnot->scale;
  241. $mapping['nullable'] = $columnAnnot->nullable;
  242. $mapping['unique'] = $columnAnnot->unique;
  243. if ($columnAnnot->options) {
  244. $mapping['options'] = $columnAnnot->options;
  245. }
  246. if (isset($columnAnnot->name)) {
  247. $mapping['columnName'] = $columnAnnot->name;
  248. }
  249. if (isset($columnAnnot->columnDefinition)) {
  250. $mapping['columnDefinition'] = $columnAnnot->columnDefinition;
  251. }
  252. if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
  253. $mapping['id'] = true;
  254. }
  255. if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\GeneratedValue')) {
  256. $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
  257. }
  258. if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Version')) {
  259. $metadata->setVersionMapping($mapping);
  260. }
  261. $metadata->mapField($mapping);
  262. // Check for SequenceGenerator/TableGenerator definition
  263. if ($seqGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\SequenceGenerator')) {
  264. $metadata->setSequenceGeneratorDefinition(array(
  265. 'sequenceName' => $seqGeneratorAnnot->sequenceName,
  266. 'allocationSize' => $seqGeneratorAnnot->allocationSize,
  267. 'initialValue' => $seqGeneratorAnnot->initialValue
  268. ));
  269. } else if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) {
  270. throw MappingException::tableIdGeneratorNotImplemented($className);
  271. }
  272. } else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) {
  273. if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
  274. $mapping['id'] = true;
  275. }
  276. $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
  277. $mapping['joinColumns'] = $joinColumns;
  278. $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
  279. $mapping['inversedBy'] = $oneToOneAnnot->inversedBy;
  280. $mapping['cascade'] = $oneToOneAnnot->cascade;
  281. $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
  282. $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $oneToOneAnnot->fetch);
  283. $metadata->mapOneToOne($mapping);
  284. } else if ($oneToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToMany')) {
  285. $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
  286. $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
  287. $mapping['cascade'] = $oneToManyAnnot->cascade;
  288. $mapping['indexBy'] = $oneToManyAnnot->indexBy;
  289. $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
  290. $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $oneToManyAnnot->fetch);
  291. if ($orderByAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) {
  292. $mapping['orderBy'] = $orderByAnnot->value;
  293. }
  294. $metadata->mapOneToMany($mapping);
  295. } else if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToOne')) {
  296. if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
  297. $mapping['id'] = true;
  298. }
  299. $mapping['joinColumns'] = $joinColumns;
  300. $mapping['cascade'] = $manyToOneAnnot->cascade;
  301. $mapping['inversedBy'] = $manyToOneAnnot->inversedBy;
  302. $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
  303. $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $manyToOneAnnot->fetch);
  304. $metadata->mapManyToOne($mapping);
  305. } else if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) {
  306. $joinTable = array();
  307. if ($joinTableAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) {
  308. $joinTable = array(
  309. 'name' => $joinTableAnnot->name,
  310. 'schema' => $joinTableAnnot->schema
  311. );
  312. foreach ($joinTableAnnot->joinColumns as $joinColumn) {
  313. $joinTable['joinColumns'][] = array(
  314. 'name' => $joinColumn->name,
  315. 'referencedColumnName' => $joinColumn->referencedColumnName,
  316. 'unique' => $joinColumn->unique,
  317. 'nullable' => $joinColumn->nullable,
  318. 'onDelete' => $joinColumn->onDelete,
  319. 'onUpdate' => $joinColumn->onUpdate,
  320. 'columnDefinition' => $joinColumn->columnDefinition,
  321. );
  322. }
  323. foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
  324. $joinTable['inverseJoinColumns'][] = array(
  325. 'name' => $joinColumn->name,
  326. 'referencedColumnName' => $joinColumn->referencedColumnName,
  327. 'unique' => $joinColumn->unique,
  328. 'nullable' => $joinColumn->nullable,
  329. 'onDelete' => $joinColumn->onDelete,
  330. 'onUpdate' => $joinColumn->onUpdate,
  331. 'columnDefinition' => $joinColumn->columnDefinition,
  332. );
  333. }
  334. }
  335. $mapping['joinTable'] = $joinTable;
  336. $mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
  337. $mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
  338. $mapping['inversedBy'] = $manyToManyAnnot->inversedBy;
  339. $mapping['cascade'] = $manyToManyAnnot->cascade;
  340. $mapping['indexBy'] = $manyToManyAnnot->indexBy;
  341. $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $manyToManyAnnot->fetch);
  342. if ($orderByAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) {
  343. $mapping['orderBy'] = $orderByAnnot->value;
  344. }
  345. $metadata->mapManyToMany($mapping);
  346. }
  347. }
  348. // Evaluate @HasLifecycleCallbacks annotation
  349. if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
  350. foreach ($class->getMethods() as $method) {
  351. // filter for the declaring class only, callbacks from parents will already be registered.
  352. if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
  353. $annotations = $this->_reader->getMethodAnnotations($method);
  354. // Compatibility with Doctrine Common 3.x
  355. if ($annotations && is_int(key($annotations))) {
  356. foreach ($annotations as $annot) {
  357. $annotations[get_class($annot)] = $annot;
  358. }
  359. }
  360. if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) {
  361. $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist);
  362. }
  363. if (isset($annotations['Doctrine\ORM\Mapping\PostPersist'])) {
  364. $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postPersist);
  365. }
  366. if (isset($annotations['Doctrine\ORM\Mapping\PreUpdate'])) {
  367. $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preUpdate);
  368. }
  369. if (isset($annotations['Doctrine\ORM\Mapping\PostUpdate'])) {
  370. $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postUpdate);
  371. }
  372. if (isset($annotations['Doctrine\ORM\Mapping\PreRemove'])) {
  373. $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preRemove);
  374. }
  375. if (isset($annotations['Doctrine\ORM\Mapping\PostRemove'])) {
  376. $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postRemove);
  377. }
  378. if (isset($annotations['Doctrine\ORM\Mapping\PostLoad'])) {
  379. $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postLoad);
  380. }
  381. }
  382. }
  383. }
  384. }
  385. /**
  386. * Whether the class with the specified name is transient. Only non-transient
  387. * classes, that is entities and mapped superclasses, should have their metadata loaded.
  388. * A class is non-transient if it is annotated with either @Entity or
  389. * @MappedSuperclass in the class doc block.
  390. *
  391. * @param string $className
  392. * @return boolean
  393. */
  394. public function isTransient($className)
  395. {
  396. $classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className));
  397. // Compatibility with Doctrine Common 3.x
  398. if ($classAnnotations && is_int(key($classAnnotations))) {
  399. foreach ($classAnnotations as $annot) {
  400. if ($annot instanceof \Doctrine\ORM\Mapping\Entity) {
  401. return false;
  402. }
  403. if ($annot instanceof \Doctrine\ORM\Mapping\MappedSuperclass) {
  404. return false;
  405. }
  406. }
  407. return true;
  408. }
  409. return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) &&
  410. ! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']);
  411. }
  412. /**
  413. * {@inheritDoc}
  414. */
  415. public function getAllClassNames()
  416. {
  417. if ($this->_classNames !== null) {
  418. return $this->_classNames;
  419. }
  420. if (!$this->_paths) {
  421. throw MappingException::pathRequired();
  422. }
  423. $classes = array();
  424. $includedFiles = array();
  425. foreach ($this->_paths as $path) {
  426. if ( ! is_dir($path)) {
  427. throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
  428. }
  429. $iterator = new \RegexIterator(
  430. new \RecursiveIteratorIterator(
  431. new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS),
  432. \RecursiveIteratorIterator::LEAVES_ONLY
  433. ),
  434. '/^.+\\' . $this->_fileExtension . '$/i',
  435. \RecursiveRegexIterator::GET_MATCH
  436. );
  437. foreach ($iterator as $file) {
  438. $sourceFile = realpath($file[0]);
  439. require_once $sourceFile;
  440. $includedFiles[] = $sourceFile;
  441. }
  442. }
  443. $declared = get_declared_classes();
  444. foreach ($declared as $className) {
  445. $rc = new \ReflectionClass($className);
  446. $sourceFile = $rc->getFileName();
  447. if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) {
  448. $classes[] = $className;
  449. }
  450. }
  451. $this->_classNames = $classes;
  452. return $classes;
  453. }
  454. /**
  455. * Factory method for the Annotation Driver
  456. *
  457. * @param array|string $paths
  458. * @param AnnotationReader $reader
  459. * @return AnnotationDriver
  460. */
  461. static public function create($paths = array(), AnnotationReader $reader = null)
  462. {
  463. if ($reader == null) {
  464. $reader = new AnnotationReader();
  465. $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
  466. }
  467. return new self($reader, $paths);
  468. }
  469. }