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


PHP ClassMetadata::getAssociationTargetClass方法代码示例

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


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

示例1: applyFilter

 /**
  * @param Request         $request
  * @param FilterInterface $filter
  * @param Criteria        $criteria
  * @param ClassMetadata   $embedClassMeta
  *
  * @return null
  */
 protected function applyFilter(Request $request, FilterInterface $filter, Criteria $criteria, ClassMetadata $embedClassMeta)
 {
     $properties = $filter->getRequestProperties($request);
     if ($filter instanceof OrderFilter && !empty($properties)) {
         $criteria->orderBy($properties);
         return null;
     }
     if ($filter instanceof SearchFilter) {
         foreach ($properties as $name => $propertie) {
             if (in_array($name, $embedClassMeta->getIdentifier())) {
                 continue;
             }
             $expCriterial = Criteria::expr();
             if ($embedClassMeta->hasAssociation($name)) {
                 $associationTargetClass = $embedClassMeta->getAssociationTargetClass($name);
                 $propertyResource = $this->resourceResolver->getResourceForEntity($associationTargetClass);
                 $propertyObj = $this->dataProviderChain->getItem($propertyResource, (int) $propertie['value'], true);
                 if ($propertyObj && $propertyResource instanceof ResourceInterface) {
                     $whereCriteria = $expCriterial->in($name, [$propertyObj]);
                     $criteria->where($whereCriteria);
                 }
             } else {
                 if ($embedClassMeta->hasField($name)) {
                     $fieldMapping = $embedClassMeta->getFieldMapping($name);
                     $type = isset($fieldMapping['type']) ? $fieldMapping['type'] : null;
                     $value = isset($this->mappingFilterVar[$type]) ? filter_var($propertie['value'], $this->mappingFilterVar[$type]) : $propertie['value'];
                     $whereCriteria = isset($propertie['precision']) && $propertie['precision'] === 'exact' ? $expCriterial->eq($name, $value) : $expCriterial->contains($name, $propertie['value']);
                     $criteria->where($whereCriteria);
                 }
             }
         }
     }
 }
开发者ID:eliberty,项目名称:api-bundle,代码行数:41,代码来源:ApplyCriteriaEmbed.php

示例2: guessColumnFormatters

 public function guessColumnFormatters(\Faker\Generator $generator)
 {
     $formatters = array();
     $class = $this->class;
     $nameGuesser = new \Faker\Guesser\Name($generator);
     $columnTypeGuesser = new ColumnTypeGuesser($generator);
     foreach ($this->class->getFieldNames() as $fieldName) {
         if ($this->class->isIdentifier($fieldName) || !$this->class->hasField($fieldName)) {
             continue;
         }
         if ($formatter = $nameGuesser->guessFormat($fieldName)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($fieldName, $this->class)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     foreach ($this->class->getAssociationNames() as $assocName) {
         if (!$this->class->isIdentifier($assocName) || !$this->class->isCollectionValuedAssociation($assocName)) {
             continue;
         }
         $relatedClass = $this->class->getAssociationTargetClass($assocName);
         $formatters[$assocName] = function ($inserted) use($relatedClass) {
             return isset($inserted[$relatedClass]) ? $inserted[$relatedClass][mt_rand(0, count($inserted[$relatedClass]) - 1)] : null;
         };
     }
     return $formatters;
 }
开发者ID:nbremont,项目名称:Faker,代码行数:30,代码来源:EntityPopulator.php

示例3: 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

示例4: getAssociationString

 private function getAssociationString(ClassMetadata $class1, $association)
 {
     $targetClassName = $class1->getAssociationTargetClass($association);
     $class2 = $this->getClassByName($targetClassName);
     $isInverse = $class1->isAssociationInverseSide($association);
     $class1Count = $class1->isCollectionValuedAssociation($association) ? 2 : 1;
     if (null === $class2) {
         return $this->getClassString($class1) . ($isInverse ? '<' : '<>') . '-' . $association . ' ' . ($class1Count > 1 ? '*' : ($class1Count ? '1' : '')) . ($isInverse ? '<>' : '>') . '[' . str_replace('\\', '.', $targetClassName) . ']';
     }
     $class1SideName = $association;
     $class2SideName = '';
     $class2Count = 0;
     $bidirectional = false;
     if ($isInverse) {
         $class2SideName = (string) $class1->getAssociationMappedByTargetField($association);
         if ($class2SideName) {
             $class2Count = $class2->isCollectionValuedAssociation($class2SideName) ? 2 : 1;
             $bidirectional = true;
         }
     } else {
         foreach ($class2->getAssociationNames() as $class2Side) {
             if ($class2->isAssociationInverseSide($class2Side) && $class2->getAssociationMappedByTargetField($class2Side) === $association) {
                 $class2SideName = $class2Side;
                 $class2Count = $class2->isCollectionValuedAssociation($class2SideName) ? 2 : 1;
                 $bidirectional = true;
                 break;
             }
         }
     }
     $this->visitAssociation($targetClassName, $class2SideName);
     return $this->getClassString($class1) . ($bidirectional ? $isInverse ? '<' : '<>' : '') . ($class2SideName ? $class2SideName . ' ' : '') . ($class2Count > 1 ? '*' : ($class2Count ? '1' : '')) . '-' . $class1SideName . ' ' . ($class1Count > 1 ? '*' : ($class1Count ? '1' : '')) . ($bidirectional && $isInverse ? '<>' : '>') . $this->getClassString($class2);
 }
开发者ID:antoinealej,项目名称:TibetWebsite,代码行数:32,代码来源:MetadataGrapher.php

示例5: 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

示例6: 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

示例7: 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

示例8: __construct

 public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
 {
     $ids = $classMetadata->getIdentifierFieldNames();
     $idType = $classMetadata->getTypeOfField(current($ids));
     $this->om = $om;
     $this->classMetadata = $classMetadata;
     $this->singleId = 1 === count($ids);
     $this->intId = $this->singleId && in_array($idType, array('integer', 'smallint', 'bigint'));
     $this->idField = current($ids);
     // single field association are resolved, since the schema column could be an int
     if ($this->singleId && $classMetadata->hasAssociation($this->idField)) {
         $this->associationIdReader = new self($om, $om->getClassMetadata($classMetadata->getAssociationTargetClass($this->idField)));
         $this->singleId = $this->associationIdReader->isSingleId();
         $this->intId = $this->associationIdReader->isIntId();
     }
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:16,代码来源:IdReader.php

示例9: 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

示例10: add

 /**
  * Adds an object to a collection.
  *
  * @param string $field
  * @param array  $args
  *
  * @return void
  *
  * @throws \BadMethodCallException
  * @throws \InvalidArgumentException
  */
 private function add($field, $args)
 {
     $this->initializeDoctrine();
     if ($this->cm->hasAssociation($field) && $this->cm->isCollectionValuedAssociation($field)) {
         $targetClass = $this->cm->getAssociationTargetClass($field);
         if (!$args[0] instanceof $targetClass) {
             throw new \InvalidArgumentException("Expected persistent object of type '" . $targetClass . "'");
         }
         if (!$this->{$field} instanceof Collection) {
             $this->{$field} = new ArrayCollection($this->{$field} ?: []);
         }
         $this->{$field}->add($args[0]);
         $this->completeOwningSide($field, $targetClass, $args[0]);
     } else {
         throw new \BadMethodCallException("There is no method add" . $field . "() on " . $this->cm->getName());
     }
 }
开发者ID:alvarobfdev,项目名称:applog,代码行数:28,代码来源:PersistentObject.php

示例11: __construct

 /**
  * Creates a new entity choice list.
  *
  * @param ObjectManager             $manager           An EntityManager instance
  * @param string                    $class             The class name
  * @param string                    $labelPath         The property path used for the label
  * @param EntityLoaderInterface     $entityLoader      An optional query builder
  * @param array|\Traversable|null   $entities          An array of choices or null to lazy load
  * @param array                     $preferredEntities An array of preferred choices
  * @param string                    $groupPath         A property path pointing to the property used
  *                                                     to group the choices. Only allowed if
  *                                                     the choices are given as flat array.
  * @param PropertyAccessorInterface $propertyAccessor  The reflection graph for reading property paths.
  */
 public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, array $preferredEntities = array(), $groupPath = null, PropertyAccessorInterface $propertyAccessor = null)
 {
     $this->em = $manager;
     $this->entityLoader = $entityLoader;
     $this->classMetadata = $manager->getClassMetadata($class);
     $this->class = $this->classMetadata->getName();
     $this->loaded = is_array($entities) || $entities instanceof \Traversable;
     $this->preferredEntities = $preferredEntities;
     list($this->idAsIndex, $this->idAsValue, $this->idField) = $this->getIdentifierInfoForClass($this->classMetadata);
     if (null !== $this->idField && $this->classMetadata->hasAssociation($this->idField)) {
         $this->idClassMetadata = $this->em->getClassMetadata($this->classMetadata->getAssociationTargetClass($this->idField));
         list($this->idAsIndex, $this->idAsValue) = $this->getIdentifierInfoForClass($this->idClassMetadata);
     }
     if (!$this->loaded) {
         // Make sure the constraints of the parent constructor are
         // fulfilled
         $entities = array();
     }
     parent::__construct($entities, $labelPath, $preferredEntities, $groupPath, null, $propertyAccessor);
 }
开发者ID:d3ancole1995,项目名称:symfony,代码行数:34,代码来源:EntityChoiceList.php

示例12: 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

示例13: getClassReverseAssociationName

 /**
  * @param ClassMetadata $class1
  * @param ClassMetadata $class2
  * @return string|null
  */
 private function getClassReverseAssociationName(ClassMetadata $class1, ClassMetadata $class2)
 {
     foreach ($class2->getAssociationNames() as $class2Side) {
         $targetClass = $this->getClassByName($class2->getAssociationTargetClass($class2Side));
         if ($class1->getName() === $targetClass->getName()) {
             return $class2Side;
         }
     }
     return null;
 }
开发者ID:KBO-Techo-Dev,项目名称:MagazinePro-zf25,代码行数:15,代码来源:MetadataGrapher.php

示例14: getTranslationMetadata

 /**
  * @return ClassMetadata
  */
 public function getTranslationMetadata()
 {
     $associationName = $this->associationMetadata->getAssociationName();
     $translationClass = $this->classMetadata->getAssociationTargetClass($associationName);
     return $this->objectManager->getClassMetadata($translationClass);
 }
开发者ID:norzechowicz,项目名称:doctrine-extensions,代码行数:9,代码来源:ClassTranslationContext.php

示例15: addAssociationsTargetClasses

 protected function addAssociationsTargetClasses(ClassMetadata $metadata, array &$classes)
 {
     $associationNames = $metadata->getAssociationNames();
     foreach ($associationNames as $associationName) {
         $associationClass = $metadata->getAssociationTargetClass($associationName);
         $classes[$associationClass] = $associationClass;
     }
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:8,代码来源:DoctrineHelper.php


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