* @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 LOGGABLE = 'Gedmo\\Mapping\\Annotation\\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) { $reader = new AnnotationReader(); $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo'); $reader->setAutoloadAnnotations(true); $class = $meta->getReflectionClass(); // class annotations $classAnnotations = $reader->getClassAnnotations($class); if (isset($classAnnotations[self::LOGGABLE])) { $config['loggable'] = true; $annot = $classAnnotations[self::LOGGABLE]; if ($annot->logEntryClass) { if (!class_exists($annot->logEntryClass)) { throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist."); } $config['logEntryClass'] = $annot->logEntryClass; } } } }