Annotation.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Gedmo\SoftDeleteable\Mapping\Driver;
  3. use Gedmo\Mapping\Driver\AbstractAnnotationDriver,
  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. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. class Annotation extends AbstractAnnotationDriver
  18. {
  19. /**
  20. * Annotation to define that this object is loggable
  21. */
  22. const SOFT_DELETEABLE = 'Gedmo\\Mapping\\Annotation\\SoftDeleteable';
  23. /**
  24. * {@inheritDoc}
  25. */
  26. public function readExtendedMetadata($meta, array &$config)
  27. {
  28. $class = $this->getMetaReflectionClass($meta);
  29. // class annotations
  30. if ($class !== null && $annot = $this->reader->getClassAnnotation($class, self::SOFT_DELETEABLE)) {
  31. $config['softDeleteable'] = true;
  32. Validator::validateField($meta, $annot->fieldName);
  33. $config['fieldName'] = $annot->fieldName;
  34. $config['timeAware'] = false;
  35. if(isset($annot->timeAware)){
  36. if (!is_bool($annot->timeAware)) {
  37. throw new InvalidMappingException("timeAware must be boolean. ".gettype($annot->timeAware)." provided.");
  38. }
  39. $config['timeAware'] = $annot->timeAware;
  40. }
  41. }
  42. $this->validateFullMetadata($meta, $config);
  43. }
  44. }