Example #1
0
 /**
  * (non-PHPdoc)
  * @see Gedmo\Mapping.Driver::readExtendedMetadata()
  */
 public function readExtendedMetadata(ClassMetadataInfo $meta, array &$config)
 {
     require_once __DIR__ . '/../Annotations.php';
     $reader = new AnnotationReader();
     $reader->setAnnotationNamespaceAlias('Gedmo\\Translatable\\Mapping\\', 'gedmo');
     $class = $meta->getReflectionClass();
     // class annotations
     $classAnnotations = $reader->getClassAnnotations($class);
     if (isset($classAnnotations[self::ANNOTATION_ENTITY_CLASS])) {
         $annot = $classAnnotations[self::ANNOTATION_ENTITY_CLASS];
         if (!class_exists($annot->class)) {
             throw MappingException::translationClassNotFound($annot->class);
         }
         $config['translationClass'] = $annot->class;
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || $meta->isInheritedAssociation($property->name)) {
             continue;
         }
         // translatable property
         if ($translatable = $reader->getPropertyAnnotation($property, self::ANNOTATION_TRANSLATABLE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw MappingException::fieldMustBeMapped($field, $meta->name);
             }
             if (!$this->_isValidField($meta, $field)) {
                 throw MappingException::notValidFieldType($field, $meta->name);
             }
             // fields cannot be overrided and throws mapping exception
             $config['fields'][] = $field;
         }
         // locale property
         if ($locale = $reader->getPropertyAnnotation($property, self::ANNOTATION_LOCALE)) {
             $field = $property->getName();
             if ($meta->hasField($field)) {
                 throw MappingException::fieldMustNotBeMapped($field, $meta->name);
             }
             $config['locale'] = $field;
         } elseif ($language = $reader->getPropertyAnnotation($property, self::ANNOTATION_LANGUAGE)) {
             $field = $property->getName();
             if ($meta->hasField($field)) {
                 throw MappingException::fieldMustNotBeMapped($field, $meta->name);
             }
             $config['locale'] = $field;
         }
     }
 }