* @author Gediminas Morkevicius * @package Gedmo.Loggable.Mapping.Driver * @subpackage Annotation * @link http://www.gediminasm.org * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ class Annotation implements Driver { /** * Annotation to define that this object is loggable */ const ANNOTATION_LOGGABLE = 'Gedmo\Loggable\Mapping\Loggable'; /** * {@inheritDoc} */ public function validateFullMetadata(ClassMetadata $meta, array $config) { if (is_array($meta->identifier) && count($meta->identifier) > 1) { throw new InvalidMappingException("Loggable does not support composite identifiers in class - {$meta->name}"); } } /** * {@inheritDoc} */ public function readExtendedMetadata(ClassMetadata $meta, array &$config) { require_once __DIR__ . '/../Annotations.php'; $reader = new AnnotationReader(); $reader->setAnnotationNamespaceAlias('Gedmo\Loggable\Mapping\\', 'gedmo'); $class = $meta->getReflectionClass(); // class annotations $classAnnotations = $reader->getClassAnnotations($class); if (isset($classAnnotations[self::ANNOTATION_LOGGABLE])) { $config['loggable'] = true; $annot = $classAnnotations[self::ANNOTATION_LOGGABLE]; if ($annot->logEntryClass) { if (!class_exists($annot->logEntryClass)) { throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist."); } $config['logEntryClass'] = $annot->logEntryClass; } } } }