Annotation.php 2.0 KB

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