Annotation.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Gedmo\SoftDeleteable\Mapping\Driver;
  3. use Gedmo\Mapping\Driver\AbstractAnnotationDriver;
  4. use Gedmo\Exception\InvalidMappingException;
  5. use Gedmo\SoftDeleteable\Mapping\Validator;
  6. /**
  7. * This is an annotation mapping driver for SoftDeleteable
  8. * behavioral extension. Used for extraction of extended
  9. * metadata from Annotations specifically for SoftDeleteable
  10. * extension.
  11. *
  12. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  13. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  14. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  15. */
  16. class Annotation extends AbstractAnnotationDriver
  17. {
  18. /**
  19. * Annotation to define that this object is loggable
  20. */
  21. const SOFT_DELETEABLE = 'Gedmo\\Mapping\\Annotation\\SoftDeleteable';
  22. /**
  23. * {@inheritDoc}
  24. */
  25. public function readExtendedMetadata($meta, array &$config)
  26. {
  27. $class = $this->getMetaReflectionClass($meta);
  28. // class annotations
  29. if ($class !== null && $annot = $this->reader->getClassAnnotation($class, self::SOFT_DELETEABLE)) {
  30. $config['softDeleteable'] = true;
  31. Validator::validateField($meta, $annot->fieldName);
  32. $config['fieldName'] = $annot->fieldName;
  33. $config['timeAware'] = false;
  34. if (isset($annot->timeAware)) {
  35. if (!is_bool($annot->timeAware)) {
  36. throw new InvalidMappingException("timeAware must be boolean. ".gettype($annot->timeAware)." provided.");
  37. }
  38. $config['timeAware'] = $annot->timeAware;
  39. }
  40. $config['hardDelete'] = true;
  41. if (isset($annot->hardDelete)) {
  42. if (!is_bool($annot->hardDelete)) {
  43. throw new InvalidMappingException("hardDelete must be boolean. ".gettype($annot->hardDelete)." provided.");
  44. }
  45. $config['hardDelete'] = $annot->hardDelete;
  46. }
  47. }
  48. $this->validateFullMetadata($meta, $config);
  49. }
  50. }