当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassMetadata::isSingleValuedAssociation方法代码示例

本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::isSingleValuedAssociation方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::isSingleValuedAssociation方法的具体用法?PHP ClassMetadata::isSingleValuedAssociation怎么用?PHP ClassMetadata::isSingleValuedAssociation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Persistence\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::isSingleValuedAssociation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: hydrate

 /**
  * Hydrate $object with the provided $data.
  *
  * @param  array  $data
  * @param  object $object
  * @throws \Exception
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     $this->metadata = $this->objectManager->getClassMetadata(get_class($object));
     foreach ($data as $field => &$value) {
         if ($this->metadata->hasAssociation($field)) {
             $target = $this->metadata->getAssociationTargetClass($field);
             if ($this->metadata->isSingleValuedAssociation($field)) {
                 $value = $this->toOne($value, $target);
             } elseif ($this->metadata->isCollectionValuedAssociation($field)) {
                 $value = $this->toMany($value, $target);
             }
         }
     }
     return $this->hydrator->hydrate($data, $object);
 }
开发者ID:ashimidashajia,项目名称:zendstore,代码行数:23,代码来源:DoctrineEntity.php

示例2: isIgnoredInWorkflow

 /**
  * Checks if the given relation should be ignored in workflows
  *
  * @param ClassMetadata $metadata
  * @param string        $associationName
  *
  * @return bool
  */
 protected function isIgnoredInWorkflow(ClassMetadata $metadata, $associationName)
 {
     if ($this->isWorkflowField($associationName)) {
         return true;
     }
     return !$metadata->isSingleValuedAssociation($associationName);
 }
开发者ID:northdakota,项目名称:platform,代码行数:15,代码来源:FieldProvider.php

示例3: setPropertyType

 protected function setPropertyType(DoctrineClassMetadata $doctrineMetadata, PropertyMetadata $propertyMetadata)
 {
     /** @var \Doctrine\ODM\PHPCR\Mapping\ClassMetadata $doctrineMetadata */
     $propertyName = $propertyMetadata->name;
     if ($doctrineMetadata->hasField($propertyName) && ($fieldType = $this->normalizeFieldType($doctrineMetadata->getTypeOfField($propertyName)))) {
         $field = $doctrineMetadata->getFieldMapping($propertyName);
         if (!empty($field['multivalue'])) {
             $fieldType = 'array';
         }
         $propertyMetadata->setType($fieldType);
     } elseif ($doctrineMetadata->hasAssociation($propertyName)) {
         try {
             $targetEntity = $doctrineMetadata->getAssociationTargetClass($propertyName);
         } catch (\Exception $e) {
             return;
         }
         if (null === $this->tryLoadingDoctrineMetadata($targetEntity)) {
             return;
         }
         if (!$doctrineMetadata->isSingleValuedAssociation($propertyName)) {
             $targetEntity = "ArrayCollection<{$targetEntity}>";
         }
         $propertyMetadata->setType($targetEntity);
     }
 }
开发者ID:alekitto,项目名称:serializer,代码行数:25,代码来源:DoctrinePHPCRTypeLoader.php

示例4: hydrate

 /**
  * Hydrate $object with the provided $data.
  *
  * @param  array  $data
  * @param  object $object
  * @throws \Exception
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     $this->metadata = $this->objectManager->getClassMetadata(get_class($object));
     $object = $this->tryConvertArrayToObject($data, $object);
     foreach ($data as $field => &$value) {
         $value = $this->hydrateValue($field, $value);
         if ($value === null) {
             continue;
         }
         // @todo DateTime (and other types) conversion should be handled by doctrine itself in future
         if (in_array($this->metadata->getTypeOfField($field), array('datetime', 'time', 'date'))) {
             if (is_int($value)) {
                 $dt = new DateTime();
                 $dt->setTimestamp($value);
                 $value = $dt;
             } elseif (is_string($value)) {
                 $value = new DateTime($value);
             }
         }
         if ($this->metadata->hasAssociation($field)) {
             $target = $this->metadata->getAssociationTargetClass($field);
             if ($this->metadata->isSingleValuedAssociation($field)) {
                 $value = $this->toOne($value, $target);
             } elseif ($this->metadata->isCollectionValuedAssociation($field)) {
                 $value = $this->toMany($value, $target);
                 // Automatically merge collections using helper utility
                 $propertyRefl = $this->metadata->getReflectionClass()->getProperty($field);
                 $propertyRefl->setAccessible(true);
                 $previousValue = $propertyRefl->getValue($object);
                 $value = CollectionUtils::intersectUnion($previousValue, $value);
             }
         }
     }
     return $this->hydrator->hydrate($data, $object);
 }
开发者ID:rrmodi88,项目名称:DoctrineModule,代码行数:43,代码来源:DoctrineObject.php

示例5: updateEntityAssociation

 /**
  * Updates a single entity association
  *
  * @param string $propertyName
  * @param array  $propertyValue
  * @param object $resource
  */
 protected function updateEntityAssociation($propertyName, array $propertyValue, $resource, ClassMetadata $entityMetadata)
 {
     if ($entityMetadata->isSingleValuedAssociation($propertyName)) {
         $associationTargetClass = $entityMetadata->getAssociationTargetClass($propertyName);
         $repository = $this->getRepositoryByTargetClass($associationTargetClass);
         $associationResource = $repository->findOneBy($propertyValue);
         if (null !== $associationResource && $this->propertyAccessor->isWritable($resource, $propertyName)) {
             $this->propertyAccessor->setValue($resource, $propertyName, $associationResource);
         }
     }
 }
开发者ID:WellCommerce,项目名称:ApiBundle,代码行数:18,代码来源:EntityDenormalizer.php

示例6: getAssocsConfig

 /**
  * @param ClassMetadata $metadata
  * @param array         $assocNames
  *
  * @return array
  */
 private function getAssocsConfig(ClassMetadata $metadata, $assocNames)
 {
     $assocsConfigs = [];
     foreach ($assocNames as $assocName) {
         if (!$metadata->isAssociationInverseSide($assocName)) {
             continue;
         }
         $class = $metadata->getAssociationTargetClass($assocName);
         if ($metadata->isSingleValuedAssociation($assocName)) {
             $nullable = $metadata instanceof ClassMetadataInfo && isset($metadata->discriminatorColumn['nullable']) && $metadata->discriminatorColumn['nullable'];
             $assocsConfigs[$assocName] = ['field_type' => 'A2lix\\AutoFormBundle\\Form\\Type\\AutoFormType', 'data_class' => $class, 'required' => !$nullable];
             continue;
         }
         $assocsConfigs[$assocName] = ['field_type' => 'Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType', 'entry_type' => 'A2lix\\AutoFormBundle\\Form\\Type\\AutoFormType', 'entry_options' => ['data_class' => $class], 'allow_add' => true, 'by_reference' => false];
     }
     return $assocsConfigs;
 }
开发者ID:a2lix,项目名称:AutoFormBundle,代码行数:23,代码来源:DoctrineInfo.php

示例7: set

 /**
  * Sets a persistent fields value.
  *
  * @param string $field
  * @param array  $args
  *
  * @return void
  *
  * @throws \BadMethodCallException   When no persistent field exists by that name.
  * @throws \InvalidArgumentException When the wrong target object type is passed to an association.
  */
 private function set($field, $args)
 {
     $this->initializeDoctrine();
     if ($this->cm->hasField($field) && !$this->cm->isIdentifier($field)) {
         $this->{$field} = $args[0];
     } else {
         if ($this->cm->hasAssociation($field) && $this->cm->isSingleValuedAssociation($field)) {
             $targetClass = $this->cm->getAssociationTargetClass($field);
             if (!$args[0] instanceof $targetClass && $args[0] !== null) {
                 throw new \InvalidArgumentException("Expected persistent object of type '" . $targetClass . "'");
             }
             $this->{$field} = $args[0];
             $this->completeOwningSide($field, $targetClass, $args[0]);
         } else {
             throw new \BadMethodCallException("no field with name '" . $field . "' exists on '" . $this->cm->getName() . "'");
         }
     }
 }
开发者ID:alvarobfdev,项目名称:applog,代码行数:29,代码来源:PersistentObject.php

示例8: setPropertyType

 protected function setPropertyType(DoctrineClassMetadata $doctrineMetadata, PropertyMetadata $propertyMetadata)
 {
     $propertyName = $propertyMetadata->name;
     if ($doctrineMetadata->hasField($propertyName) && ($fieldType = $this->normalizeFieldType($doctrineMetadata->getTypeOfField($propertyName)))) {
         $propertyMetadata->setType($fieldType);
     } elseif ($doctrineMetadata->hasAssociation($propertyName)) {
         $targetEntity = $doctrineMetadata->getAssociationTargetClass($propertyName);
         if (null === ($targetMetadata = $this->tryLoadingDoctrineMetadata($targetEntity))) {
             return;
         }
         // For inheritance schemes, we cannot add any type as we would only add the super-type of the hierarchy.
         // On serialization, this would lead to only the supertype being serialized, and properties of subtypes
         // being ignored.
         if ($targetMetadata instanceof DoctrineClassMetadata && !$targetMetadata->isInheritanceTypeNone()) {
             return;
         }
         if (!$doctrineMetadata->isSingleValuedAssociation($propertyName)) {
             $targetEntity = "ArrayCollection<{$targetEntity}>";
         }
         $propertyMetadata->setType($targetEntity);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:22,代码来源:DoctrineTypeDriver.php

示例9: processAssociationNames

 /**
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata
  * @param                                                    $model
  *
  * @return array
  */
 protected function processAssociationNames(ClassMetadata $metadata, $model)
 {
     $data = array();
     foreach ($metadata->getAssociationNames() as $assocName) {
         $propertyValue = $this->readProperty($model, $assocName);
         if (null === $propertyValue || $metadata->isAssociationInverseSide($assocName)) {
             continue;
         }
         if ($metadata->isSingleValuedAssociation($assocName)) {
             $assocValue = $this->namingStrategy->modelName($propertyValue, $this->getManager()->getClassMetadata(get_class($propertyValue)));
             $assocValue = $this->navigator->accept($this->getVisitor(), $assocValue, 'reference');
             $data[$assocName] = $assocValue;
         } else {
             $data[$assocName] = array();
             foreach ($propertyValue as $value) {
                 $assocValue = $this->namingStrategy->modelName($value, $this->getManager()->getClassMetadata(get_class($value)));
                 $assocValue = $this->navigator->accept($this->getVisitor(), $assocValue, 'reference');
                 $data[$assocName][] = $assocValue;
             }
         }
     }
     return $data;
 }
开发者ID:xijia37,项目名称:fixture-dumper,代码行数:29,代码来源:AbstractGenerator.php

示例10: validate

 /**
  * {@inheritDoc}
  */
 public static function validate(array $options, ClassMetadata $meta)
 {
     if (!$meta->isSingleValuedAssociation($options['parentRelationField'])) {
         throw new InvalidMappingException("Unable to find tree parent slug relation through field - [{$options['parentRelationField']}] in class - {$meta->name}");
     }
 }
开发者ID:projectesIF,项目名称:Sirius,代码行数:9,代码来源:TreeSlugHandler.php

示例11: isFieldSearchable

 /**
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata
  * @param string $field
  * @return bool
  */
 private function isFieldSearchable(ClassMetadata $classMetadata, $field)
 {
     return $classMetadata->hasField($field) || $classMetadata->hasAssociation($field) && $classMetadata->isSingleValuedAssociation($field);
 }
开发者ID:norzechowicz,项目名称:doctrine-extensions-bundle,代码行数:9,代码来源:TranslatableParamConverter.php

示例12: unserializeField

 protected function unserializeField($data, ClassMetadata $metadata, $document, $field, $mode)
 {
     if ($metadata->hasAssociation($field) && $metadata->isSingleValuedAssociation($field)) {
         $value = $this->unserializeSingleModel($data, $metadata, $document, $field, $mode);
     } elseif ($metadata->hasAssociation($field)) {
         $value = $this->unserializeCollection($data, $metadata, $document, $field, $mode);
     } else {
         $value = $this->unserializeSingleValue($data, $metadata, $field);
     }
     if (isset($value)) {
         $metadata->setFieldValue($document, $field, $value);
     } elseif ($mode == self::UNSERIALIZE_UPDATE) {
         $metadata->setFieldValue($document, $field, null);
     }
 }
开发者ID:zoopcommerce,项目名称:shard,代码行数:15,代码来源:Unserializer.php

示例13: validate

 /**
  * {@inheritdoc}
  */
 public static function validate(array $options, ClassMetadata $meta)
 {
     // Since we cannot know, whether children of this mapped superclass
     // have or have not given association.
     if ($meta instanceof ClassMetadataInfo && $meta->isMappedSuperclass) {
         return;
     }
     if (!$meta->isSingleValuedAssociation($options['relationField'])) {
         throw new InvalidMappingException("Unable to find tree parent slug relation through field - [{$options['relationField']}] in class - {$meta->name}");
     }
     //      TODO Check parent relation in translatable entity is single valued
     //      (Note: don't know if that's possible here as we need the relationField class metadata)
 }
开发者ID:loic425,项目名称:Sylius,代码行数:16,代码来源:TranslationSlugHandler.php

示例14: serializeField

 protected function serializeField(ClassMetadata $metadata, $value, $field)
 {
     if ($metadata->hasAssociation($field) && $metadata->isSingleValuedAssociation($field)) {
         return $this->serializeSingleModel($metadata, $value, $field);
     } elseif ($metadata->hasAssociation($field)) {
         return $this->serializeCollection($metadata, $value, $field);
     } else {
         return $this->serializeSingleValue($metadata, $value, $field);
     }
 }
开发者ID:zoopcommerce,项目名称:shard,代码行数:10,代码来源:Serializer.php

示例15: buildAssociationValue

 /**
  * Builds the association value.
  *
  * @param ClassMetadata $metadata
  * @param string        $propertyPath
  * @param string        $value
  *
  * @return array|object
  * @throws \Exception
  */
 private function buildAssociationValue(ClassMetadata $metadata, $propertyPath, $value)
 {
     $childMetadata = $this->manager->getClassMetadata($metadata->getAssociationTargetClass($propertyPath));
     // Single association
     if ($metadata->isSingleValuedAssociation($propertyPath)) {
         if (is_string($value) && '#' === substr($value, 0, 1)) {
             return $this->getReference(substr($value, 1));
         } elseif (is_array($value)) {
             return $this->buildEntity($childMetadata, $value);
         }
         throw new \Exception("Unexpected value for single association '{$propertyPath}'.");
         // Collection association
     } elseif ($metadata->isCollectionValuedAssociation($propertyPath)) {
         if (!is_array($value)) {
             throw new \Exception('Expected array.');
         }
         $builtValue = [];
         foreach ($value as $childData) {
             if (is_string($childData) && '#' === substr($childData, 0, 1)) {
                 array_push($builtValue, $this->getReference(substr($childData, 1)));
             } elseif (is_array($value)) {
                 array_push($builtValue, $this->buildEntity($childMetadata, $childData));
             } else {
                 throw new \Exception("Unexpected value for association '{$propertyPath}'.");
             }
         }
         return $builtValue;
     }
     throw new \Exception("Unexpected association path '{$propertyPath}'.");
 }
开发者ID:ekyna,项目名称:commerce,代码行数:40,代码来源:AbstractFixture.php


注:本文中的Doctrine\Common\Persistence\Mapping\ClassMetadata::isSingleValuedAssociation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。