AbstractAnnotationDriver.php 2.1 KB

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