本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::isInheritedField方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::isInheritedField方法的具体用法?PHP ClassMetadata::isInheritedField怎么用?PHP ClassMetadata::isInheritedField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::isInheritedField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// class annotations
if ($annot = $this->reader->getClassAnnotation($class, self::LOGGABLE)) {
$config['loggable'] = true;
if ($annot->logEntryClass) {
if (!class_exists($annot->logEntryClass)) {
throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist.");
}
$config['logEntryClass'] = $annot->logEntryClass;
}
}
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// versioned property
if ($versioned = $this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
$field = $property->getName();
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
// fields cannot be overrided and throws mapping exception
$config['versioned'][] = $field;
}
}
}
示例2: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
if ($timestampable = $this->reader->getPropertyAnnotation($property, self::TIMESTAMPABLE)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->name}");
}
if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
throw new InvalidMappingException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->name}");
}
if ($timestampable->on == 'change') {
if (!isset($timestampable->field) || !isset($timestampable->value)) {
throw new InvalidMappingException("Missing parameters on property - {$field}, field and value must be set on [change] trigger in class - {$meta->name}");
}
$field = array('field' => $field, 'trackedField' => $timestampable->field, 'value' => $timestampable->value);
}
// properties are unique and mapper checks that, no risk here
$config[$timestampable->on][] = $field;
}
}
}
示例3: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// position
if ($position = $this->reader->getPropertyAnnotation($property, self::POSITION)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find 'position' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Sortable position field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
}
$config['position'] = $field;
}
// group
if ($group = $this->reader->getPropertyAnnotation($property, self::GROUP)) {
$field = $property->getName();
if (!$meta->hasField($field) && !$meta->hasAssociation($field)) {
throw new InvalidMappingException("Unable to find 'group' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!isset($config['groups'])) {
$config['groups'] = array();
}
$config['groups'][] = $field;
}
}
}
示例4: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
$config['fields'] = array();
$config['fields_delete'] = array();
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
$field = null;
if ($file = $this->reader->getPropertyAnnotation($property, self::FILE)) {
$field['name'] = $property->getName();
$field['dir'] = CMSCore::init()->getUploadsDir() . '/' . $file->dir;
if (!$meta->hasField($field['name'])) {
throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
}
}
// if ($fileDelete = $this->reader->getPropertyAnnotation($property, self::FILE_DELETE)) {
//
// $config['fields_delete'][] = $property->getName();
//
// }
if ($field) {
$config['fields'][] = $field;
}
}
}
示例5: readExtendedMetadata
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
// load our available annotations
require_once __DIR__ . '/../Annotations.php';
$reader = new AnnotationReader();
// set annotation namespace and alias
//$reader->setAnnotationNamespaceAlias('Gedmo\Mapping\Mock\Extension\Encoder\Mapping\\', 'ext');
$class = $meta->getReflectionClass();
// check only property annotations
foreach ($class->getProperties() as $property) {
// skip inherited properties
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// now lets check if property has our annotation
if ($encode = $reader->getPropertyAnnotation($property, 'Gedmo\\Mapping\\Mock\\Extension\\Encoder\\Mapping\\Encode')) {
$field = $property->getName();
// check if field is mapped
if (!$meta->hasField($field)) {
throw new \Exception("Field is not mapped as object property");
}
// allow encoding only strings
if (!in_array($encode->type, array('sha1', 'md5'))) {
throw new \Exception("Invalid encoding type supplied");
}
// validate encoding type
$mapping = $meta->getFieldMapping($field);
if ($mapping['type'] != 'string') {
throw new \Exception("Only strings can be encoded");
}
// store the metadata
$config['encode'][$field] = array('type' => $encode->type, 'secret' => $encode->secret);
}
}
}
示例6: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// slug property
if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
}
// process slug handlers
$handlers = array();
if (is_array($slug->handlers) && $slug->handlers) {
foreach ($slug->handlers as $handler) {
if (!$handler instanceof SlugHandler) {
throw new InvalidMappingException("SlugHandler: {$handler} should be instance of SlugHandler annotation in entity - {$meta->name}");
}
if (!strlen($handler->class)) {
throw new InvalidMappingException("SlugHandler class: {$handler->class} should be a valid class name in entity - {$meta->name}");
}
$class = $handler->class;
$handlers[$class] = array();
foreach ((array) $handler->options as $option) {
if (!$option instanceof SlugHandlerOption) {
throw new InvalidMappingException("SlugHandlerOption: {$option} should be instance of SlugHandlerOption annotation in entity - {$meta->name}");
}
if (!strlen($option->name)) {
throw new InvalidMappingException("SlugHandlerOption name: {$option->name} should be valid name in entity - {$meta->name}");
}
$handlers[$class][$option->name] = $option->value;
}
$class::validate($handlers[$class], $meta);
}
}
// process slug fields
if (empty($slug->fields) || !is_array($slug->fields)) {
throw new InvalidMappingException("Slug must contain at least one field for slug generation in class - {$meta->name}");
}
foreach ($slug->fields as $slugField) {
if (!$meta->hasField($slugField)) {
throw new InvalidMappingException("Unable to find slug [{$slugField}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $slugField)) {
throw new InvalidMappingException("Cannot use field - [{$slugField}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
}
}
// set all options
$config['slugs'][$field] = array('fields' => $slug->fields, 'slug' => $field, 'style' => $slug->style, 'updatable' => $slug->updatable, 'unique' => $slug->unique, 'separator' => $slug->separator, 'handlers' => $handlers);
}
}
}
示例7: loadExtendedClassMetadata
/**
* {@inheritdoc}
*/
protected function loadExtendedClassMetadata(ClassMetadata $baseClassMetadata, ClassMetadataInterface $extendedClassMetadata)
{
$classReflection = $extendedClassMetadata->getClassReflection();
foreach ($classReflection->getProperties() as $property) {
if ($baseClassMetadata->isMappedSuperclass && !$property->isPrivate() || $baseClassMetadata->isInheritedField($property->name) || isset($baseClassMetadata->associationMappings[$property->name]['inherited'])) {
continue;
}
if ($uploadableAnnotation = $this->getAnnotationReader()->getPropertyAnnotation($property, self::UPLOADABLE)) {
$extendedClassMetadata->addUploadableProperty($property->getName(), $uploadableAnnotation->targetField, $uploadableAnnotation->filesystem, $uploadableAnnotation->keymaker, $uploadableAnnotation->keyLength, $uploadableAnnotation->keyPattern);
}
}
}
示例8: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
if ($demo = $this->reader->getPropertyAnnotation($property, self::DEMO)) {
$field = $property->getName();
$value = $demo->text;
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
}
$config['text'][] = array('field' => $field, 'value' => $value);
}
}
}
示例9: loadExtendedClassMetadata
/**
* {@inheritDoc}
*/
protected function loadExtendedClassMetadata(ClassMetadata $baseClassMetadata, ClassMetadataInterface $extendedClassMetadata)
{
$classReflection = $extendedClassMetadata->getClassReflection();
foreach ($classReflection->getProperties() as $property) {
if ($baseClassMetadata->isMappedSuperclass && !$property->isPrivate() || $baseClassMetadata->isInheritedField($property->name) || isset($baseClassMetadata->associationMappings[$property->name]['inherited'])) {
continue;
}
if ($translatableAnnotation = $this->getAnnotationReader()->getPropertyAnnotation($property, self::TRANSLATABLE)) {
if (!isset($translatableAnnotation->mappedBy)) {
throw new AnnotationException('Annotation \'Translatable\' in property \'' . $property . '\' of class \'' . $baseClassMetadata->name . '\' does not have required \'mappedBy\' attribute');
}
$extendedClassMetadata->addTranslatableProperty($translatableAnnotation->mappedBy, $property->getName(), $translatableAnnotation->targetField);
}
if ($languageAnnotation = $this->getAnnotationReader()->getPropertyAnnotation($property, self::LOCALE)) {
$extendedClassMetadata->localeProperty = $property->getName();
}
}
}
示例10: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// class annotations
if ($annot = $this->reader->getClassAnnotation($class, self::ENTITY_CLASS)) {
if (!class_exists($annot->class)) {
throw new InvalidMappingException("Translation class: {$annot->class} does not exist.");
}
$config['translationClass'] = $annot->class;
}
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// translatable property
if ($translatable = $this->reader->getPropertyAnnotation($property, self::TRANSLATABLE)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find translatable [{$field}] as mapped property in entity - {$meta->name}");
}
// fields cannot be overrided and throws mapping exception
$config['fields'][] = $field;
}
// locale property
if ($locale = $this->reader->getPropertyAnnotation($property, self::LOCALE)) {
$field = $property->getName();
if ($meta->hasField($field)) {
throw new InvalidMappingException("Locale field [{$field}] should not be mapped as column property in entity - {$meta->name}, since it makes no sence");
}
$config['locale'] = $field;
} elseif ($language = $this->reader->getPropertyAnnotation($property, self::LANGUAGE)) {
$field = $property->getName();
if ($meta->hasField($field)) {
throw new InvalidMappingException("Language field [{$field}] should not be mapped as column property in entity - {$meta->name}, since it makes no sence");
}
$config['locale'] = $field;
}
}
}
示例11: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// sluggable property
if ($sluggable = $this->reader->getPropertyAnnotation($property, self::SLUGGABLE)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find sluggable [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Cannot slug field - [{$field}] type is not valid and must be 'string' in class - {$meta->name}");
}
if (!is_null($sluggable->slugField) and !$meta->hasField($sluggable->slugField)) {
throw new InvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
}
$config['fields'][$sluggable->slugField][] = array('field' => $field, 'position' => $sluggable->position, 'slugField' => $sluggable->slugField);
}
// slug property
if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' in class - {$meta->name}");
}
$config['slugFields'][$field]['slug'] = $field;
$config['slugFields'][$field]['style'] = $slug->style;
$config['slugFields'][$field]['updatable'] = $slug->updatable;
$config['slugFields'][$field]['unique'] = $slug->unique;
$config['slugFields'][$field]['separator'] = $slug->separator;
}
}
}
示例12: loadMetadataForClass
//.........这里部分代码省略.........
if (!$namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery) {
throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
}
$metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
}
}
// Evaluate InheritanceType annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
$inheritanceTypeAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
$metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
// Evaluate DiscriminatorColumn annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
$discrColumnAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
$metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type ?: 'string', 'length' => $discrColumnAnnot->length ?: 255, 'columnDefinition' => $discrColumnAnnot->columnDefinition));
} else {
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
}
// Evaluate DiscriminatorMap annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
$discrMapAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
$metadata->setDiscriminatorMap($discrMapAnnot->value);
}
}
}
// Evaluate DoctrineChangeTrackingPolicy annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
$changeTrackingAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
$metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value));
}
// Evaluate annotations on properties/fields
/* @var $property \ReflectionProperty */
foreach ($class->getProperties() as $property) {
if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) || $metadata->isInheritedAssociation($property->name) || $metadata->isInheritedEmbeddedClass($property->name)) {
continue;
}
$mapping = array();
$mapping['fieldName'] = $property->getName();
// Evaluate @Cache annotation
if (($cacheAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Cache')) !== null) {
$mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], array('usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage), 'region' => $cacheAnnot->region));
}
// Check for JoinColumn/JoinColumns annotations
$joinColumns = array();
if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumn')) {
$joinColumns[] = $this->joinColumnToArray($joinColumnAnnot);
} else {
if ($joinColumnsAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumns')) {
foreach ($joinColumnsAnnot->value as $joinColumn) {
$joinColumns[] = $this->joinColumnToArray($joinColumn);
}
}
}
// Field can only be annotated with one of:
// @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
if ($columnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
if ($columnAnnot->type == null) {
throw MappingException::propertyTypeIsRequired($className, $property->getName());
}
$mapping = $this->columnToArray($property->getName(), $columnAnnot);
if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
$mapping['id'] = true;
}
if ($generatedValueAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
$metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
}
示例13: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config) {
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() ||
$meta->isInheritedField($property->name) ||
isset($meta->associationMappings[$property->name]['inherited'])
) {
continue;
}
// sluggable property
if ($sluggable = $this->reader->getPropertyAnnotation($property, self::SLUGGABLE)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find sluggable [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Cannot slug field - [{$field}] type is not valid and must be 'string' in class - {$meta->name}");
}
if (!is_null($sluggable->slugField) and !$meta->hasField($sluggable->slugField)) {
throw new InvalidMappingException(sprintf('The "%s" property - which is defined as the "slugField" for the "%s" property - does not exist or is not mapped to Doctrine in "%s"', $sluggable->slugField, $field, $meta->name));
}
$config['fields'][$sluggable->slugField][] = array('field' => $field, 'position' => $sluggable->position, 'slugField' => $sluggable->slugField);
}
// slug property
if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' in class - {$meta->name}");
}
// process slug handlers
if (is_array($slug->handlers) && $slug->handlers) {
foreach ($slug->handlers as $handler) {
if (!$handler instanceof SlugHandler) {
throw new InvalidMappingException("SlugHandler: {$handler} should be instance of SlugHandler annotation in entity - {$meta->name}");
}
if (!strlen($handler->class)) {
throw new InvalidMappingException("SlugHandler class: {$handler->class} should be a valid class name in entity - {$meta->name}");
}
$class = $handler->class;
$config['handlers'][$class] = array();
foreach ((array)$handler->options as $option) {
if (!$option instanceof SlugHandlerOption) {
throw new InvalidMappingException("SlugHandlerOption: {$option} should be instance of SlugHandlerOption annotation in entity - {$meta->name}");
}
if (!strlen($option->name)) {
throw new InvalidMappingException("SlugHandlerOption name: {$option->name} should be valid name in entity - {$meta->name}");
}
$config['handlers'][$class][$option->name] = $option->value;
}
$class::validate($config['handlers'][$class], $meta);
}
}
$config['slugFields'][$field]['slug'] = $field;
$config['slugFields'][$field]['style'] = $slug->style;
$config['slugFields'][$field]['updatable'] = $slug->updatable;
$config['slugFields'][$field]['unique'] = $slug->unique;
$config['slugFields'][$field]['separator'] = $slug->separator;
}
}
}
示例14: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/** @var $metadata \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
$reflClass = $metadata->getReflectionClass();
$documentAnnots = array();
foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
foreach ($this->entityAnnotationClasses as $annotClass => $i) {
if ($annot instanceof $annotClass) {
$documentAnnots[$i] = $annot;
}
}
}
if (!$documentAnnots) {
throw MappingException::classIsNotAValidDocument($className);
}
// find the winning document annotation
ksort($documentAnnots);
$documentAnnot = reset($documentAnnots);
if ($documentAnnot instanceof ODM\MappedSuperclass) {
$metadata->isMappedSuperclass = true;
}
if (null !== $documentAnnot->referenceable) {
$metadata->setReferenceable($documentAnnot->referenceable);
}
if (null !== $documentAnnot->versionable) {
$metadata->setVersioned($documentAnnot->versionable);
}
if (null !== $documentAnnot->mixins) {
$metadata->setMixins($documentAnnot->mixins);
}
if (null !== $documentAnnot->inheritMixins) {
$metadata->setInheritMixins($documentAnnot->inheritMixins);
}
if (null !== $documentAnnot->nodeType) {
$metadata->setNodeType($documentAnnot->nodeType);
}
if (null !== $documentAnnot->repositoryClass) {
$metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass);
}
if (null !== $documentAnnot->translator) {
$metadata->setTranslator($documentAnnot->translator);
}
foreach ($reflClass->getProperties() as $property) {
if ($metadata->isInheritedField($property->name) && $metadata->name !== $property->getDeclaringClass()->getName()) {
continue;
}
$mapping = array();
$mapping['fieldName'] = $property->getName();
foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
if ($fieldAnnot instanceof ODM\Property) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapField($mapping);
} elseif ($fieldAnnot instanceof ODM\Id) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapId($mapping);
} elseif ($fieldAnnot instanceof ODM\Node) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapNode($mapping);
} elseif ($fieldAnnot instanceof ODM\Nodename) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapNodename($mapping);
} elseif ($fieldAnnot instanceof ODM\ParentDocument) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapParentDocument($mapping);
} elseif ($fieldAnnot instanceof ODM\Child) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapChild($mapping);
} elseif ($fieldAnnot instanceof ODM\Children) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapChildren($mapping);
} elseif ($fieldAnnot instanceof ODM\ReferenceOne) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapManyToOne($mapping);
} elseif ($fieldAnnot instanceof ODM\ReferenceMany) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapManyToMany($mapping);
} elseif ($fieldAnnot instanceof ODM\Referrers) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapReferrers($mapping);
} elseif ($fieldAnnot instanceof ODM\MixedReferrers) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapMixedReferrers($mapping);
} elseif ($fieldAnnot instanceof ODM\Locale) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapLocale($mapping);
} elseif ($fieldAnnot instanceof ODM\Depth) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapDepth($mapping);
} elseif ($fieldAnnot instanceof ODM\VersionName) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapVersionName($mapping);
//.........这里部分代码省略.........
示例15: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// class annotations
if ($annot = $this->reader->getClassAnnotation($class, self::TREE)) {
if (!in_array($annot->type, $this->strategies)) {
throw new InvalidMappingException("Tree type: {$annot->type} is not available.");
}
$config['strategy'] = $annot->type;
}
if ($annot = $this->reader->getClassAnnotation($class, self::CLOSURE)) {
if (!class_exists($annot->class)) {
throw new InvalidMappingException("Tree closure class: {$annot->class} does not exist.");
}
$config['closure'] = $annot->class;
}
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// left
if ($left = $this->reader->getPropertyAnnotation($property, self::LEFT)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find 'left' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Tree left field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
}
$config['left'] = $field;
}
// right
if ($right = $this->reader->getPropertyAnnotation($property, self::RIGHT)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find 'right' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Tree right field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
}
$config['right'] = $field;
}
// ancestor/parent
if ($parent = $this->reader->getPropertyAnnotation($property, self::PARENT)) {
$field = $property->getName();
if (!$meta->isSingleValuedAssociation($field)) {
throw new InvalidMappingException("Unable to find ancestor/parent child relation through ancestor field - [{$field}] in class - {$meta->name}");
}
$config['parent'] = $field;
}
// root
if ($root = $this->reader->getPropertyAnnotation($property, self::ROOT)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find 'root' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Tree root field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
}
$config['root'] = $field;
}
// level
if ($parent = $this->reader->getPropertyAnnotation($property, self::LEVEL)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find 'level' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Tree level field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
}
$config['level'] = $field;
}
}
}