AbstractAnnotationDriver.php 2.2 KB

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