Annotation.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Gedmo\Loggable\Mapping\Driver;
  3. use Gedmo\Mapping\Driver,
  4. Doctrine\Common\Annotations\AnnotationReader,
  5. Doctrine\Common\Persistence\Mapping\ClassMetadata,
  6. Gedmo\Exception\InvalidMappingException;
  7. /**
  8. * This is an annotation mapping driver for Loggable
  9. * behavioral extension. Used for extraction of extended
  10. * metadata from Annotations specificaly for Loggable
  11. * extension.
  12. *
  13. * @author Boussekeyt Jules <jules.boussekeyt@gmail.com>
  14. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  15. * @package Gedmo.Loggable.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 Driver
  21. {
  22. /**
  23. * Annotation to define that this object is loggable
  24. */
  25. const ANNOTATION_LOGGABLE = 'Gedmo\Loggable\Mapping\Loggable';
  26. /**
  27. * {@inheritDoc}
  28. */
  29. public function validateFullMetadata(ClassMetadata $meta, array $config)
  30. {
  31. }
  32. /**
  33. * {@inheritDoc}
  34. */
  35. public function readExtendedMetadata(ClassMetadata $meta, array &$config)
  36. {
  37. require_once __DIR__ . '/../Annotations.php';
  38. $reader = new AnnotationReader();
  39. $reader->setAnnotationNamespaceAlias('Gedmo\Loggable\Mapping\\', 'gedmo');
  40. $class = $meta->getReflectionClass();
  41. // class annotations
  42. $classAnnotations = $reader->getClassAnnotations($class);
  43. if (isset($classAnnotations[self::ANNOTATION_LOGGABLE])) {
  44. $config['loggable'] = true;
  45. $annot = $classAnnotations[self::ANNOTATION_LOGGABLE];
  46. if ($annot->logEntryClass) {
  47. if (!class_exists($annot->logEntryClass)) {
  48. throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist.");
  49. }
  50. $config['logEntryClass'] = $annot->logEntryClass;
  51. }
  52. }
  53. }
  54. }