Annotation.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Gedmo\SoftDeleteable\Mapping\Driver;
  3. use Gedmo\Mapping\Driver\AnnotationDriverInterface,
  4. Doctrine\Common\Persistence\Mapping\ClassMetadata,
  5. Gedmo\Exception\InvalidMappingException,
  6. Gedmo\SoftDeleteable\Mapping\Validator;
  7. /**
  8. * This is an annotation mapping driver for SoftDeleteable
  9. * behavioral extension. Used for extraction of extended
  10. * metadata from Annotations specificaly for SoftDeleteable
  11. * extension.
  12. *
  13. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  14. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  15. * @package Gedmo.SoftDeleteable.Mapping.Driver
  16. * @subpackage Annotation
  17. * @link http://www.gediminasm.org
  18. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  19. */
  20. class Annotation implements AnnotationDriverInterface
  21. {
  22. /**
  23. * Annotation to define that this object is loggable
  24. */
  25. const SOFT_DELETEABLE = 'Gedmo\\Mapping\\Annotation\\SoftDeleteable';
  26. /**
  27. * Annotation reader instance
  28. *
  29. * @var object
  30. */
  31. private $reader;
  32. /**
  33. * original driver if it is available
  34. */
  35. protected $_originalDriver = null;
  36. /**
  37. * {@inheritDoc}
  38. */
  39. public function setAnnotationReader($reader)
  40. {
  41. $this->reader = $reader;
  42. }
  43. /**
  44. * {@inheritDoc}
  45. */
  46. public function validateFullMetadata(ClassMetadata $meta, array $config)
  47. {
  48. // Nothing here for now
  49. }
  50. /**
  51. * {@inheritDoc}
  52. */
  53. public function readExtendedMetadata($meta, array &$config)
  54. {
  55. $class = $meta->getReflectionClass();
  56. // class annotations
  57. if ($class !== null && $annot = $this->reader->getClassAnnotation($class, self::SOFT_DELETEABLE)) {
  58. $config['softDeleteable'] = true;
  59. Validator::validateField($meta, $annot->fieldName);
  60. $config['fieldName'] = $annot->fieldName;
  61. }
  62. $this->validateFullMetadata($meta, $config);
  63. }
  64. /**
  65. * Passes in the mapping read by original driver
  66. *
  67. * @param $driver
  68. * @return void
  69. */
  70. public function setOriginalDriver($driver)
  71. {
  72. $this->_originalDriver = $driver;
  73. }
  74. }