XmlDriver.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\DoctrineBundle\Mapping\Driver;
  11. use Doctrine\ORM\Mapping\Driver\XmlDriver as BaseXmlDriver;
  12. /**
  13. * XmlDriver that additionnaly looks for mapping information in a global file.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. class XmlDriver extends BaseXmlDriver
  18. {
  19. protected $_globalFile = 'doctrine';
  20. protected $_classCache;
  21. protected $_fileExtension = '.orm.dcm.xml';
  22. public function isTransient($className)
  23. {
  24. return !in_array($className, $this->getAllClassNames());
  25. }
  26. public function getAllClassNames()
  27. {
  28. if (null === $this->_classCache) {
  29. $this->initialize();
  30. }
  31. return array_merge(parent::getAllClassNames(), array_keys($this->_classCache));
  32. }
  33. public function getElement($className)
  34. {
  35. if (null === $this->_classCache) {
  36. $this->initialize();
  37. }
  38. if (!isset($this->_classCache[$className])) {
  39. $this->_classCache[$className] = parent::getElement($className);
  40. }
  41. return $this->_classCache[$className];
  42. }
  43. protected function initialize()
  44. {
  45. $this->_classCache = array();
  46. foreach ($this->_paths as $path) {
  47. if (file_exists($file = $path.'/'.$this->_globalFile.$this->_fileExtension)) {
  48. $this->_classCache = array_merge($this->_classCache, $this->_loadMappingFile($file));
  49. }
  50. }
  51. }
  52. }