/** * (non-PHPdoc) * @see Gedmo\Mapping.Driver::readExtendedMetadata() */ public function readExtendedMetadata(ClassMetadataInfo $meta, array &$config) { $yaml = $this->_loadMappingFile($this->_findMappingFile($meta->name)); $mapping = $yaml[$meta->name]; if (isset($mapping['gedmo'])) { $classMapping = $mapping['gedmo']; if (isset($classMapping['translatable']['entity'])) { $translationEntity = $classMapping['translatable']['entity']; if (!class_exists($translationEntity)) { throw MappingException::translationClassNotFound($translationEntity); } $config['translationClass'] = $translationEntity; } if (isset($classMapping['translatable']['locale'])) { $config['locale'] = $classMapping['translatable']['locale']; } elseif (isset($classMapping['translatable']['language'])) { $config['locale'] = $classMapping['translatable']['language']; } } if (isset($mapping['fields'])) { foreach ($mapping['fields'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { if (in_array('translatable', $fieldMapping['gedmo'])) { if (!$this->_isValidField($meta, $field)) { throw MappingException::notValidFieldType($field, $meta->name); } // fields cannot be overrided and throws mapping exception $config['fields'][] = $field; } } } } }
/** * (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; } } }