AbstractAnnotationDriver.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Gedmo\Mapping\Driver;
  3. use Gedmo\Mapping\Driver\AnnotationDriverInterface;
  4. use Doctrine\Common\Persistence\Mapping\ClassMetadata;
  5. /**
  6. * This is an abstract class to implement common functionality
  7. * for extension annotation mapping drivers.
  8. *
  9. * @package Gedmo.Mapping.Driver
  10. * @subpackage AnnotationDriverInterface
  11. * @author Derek J. Lambert <dlambert@dereklambert.com>
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. * @link http://www.gediminasm.org
  14. */
  15. abstract class AbstractAnnotationDriver implements AnnotationDriverInterface
  16. {
  17. /**
  18. * Annotation reader instance
  19. *
  20. * @var object
  21. */
  22. protected $reader;
  23. /**
  24. * Original driver if it is available
  25. */
  26. protected $_originalDriver = null;
  27. /**
  28. * List of types which are valid for extension
  29. *
  30. * @var array
  31. */
  32. protected $validTypes = array();
  33. /**
  34. * {@inheritDoc}
  35. */
  36. public function setAnnotationReader($reader)
  37. {
  38. $this->reader = $reader;
  39. }
  40. /**
  41. * Passes in the mapping read by original driver
  42. *
  43. * @param object $driver
  44. */
  45. public function setOriginalDriver($driver)
  46. {
  47. $this->_originalDriver = $driver;
  48. }
  49. /**
  50. * @param object $meta
  51. *
  52. * @return array
  53. */
  54. public function getMetaReflectionClass($meta)
  55. {
  56. $class = $meta->getReflectionClass();
  57. if (!$class) {
  58. // based on recent doctrine 2.3.0-DEV maybe will be fixed in some way
  59. // this happens when running annotation driver in combination with
  60. // static reflection services. This is not the nicest fix
  61. $class = new \ReflectionClass($meta->name);
  62. }
  63. return $class;
  64. }
  65. /**
  66. * Checks if $field type is valid
  67. *
  68. * @param object $meta
  69. * @param string $field
  70. *
  71. * @return boolean
  72. */
  73. protected function isValidField($meta, $field)
  74. {
  75. $mapping = $meta->getFieldMapping($field);
  76. return $mapping && in_array($mapping['type'], $this->validTypes);
  77. }
  78. /**
  79. * @param Doctrine\Common\Persistence\Mapping\ClassMetaData $meta
  80. * @param array $config
  81. */
  82. public function validateFullMetadata(ClassMetadata $meta, array $config)
  83. {
  84. }
  85. }