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


PHP ClassMetadata::hasAssociation方法代码示例

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


在下文中一共展示了ClassMetadata::hasAssociation方法的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: buildWhereClause

 /**
  * @param QueryBuilder $qb
  * @param Criteria $criteria
  */
 protected function buildWhereClause(Builder $qb, Criteria $criteria)
 {
     foreach ($criteria as $key => $value) {
         if ($this->metadata->hasField($key) || $this->metadata->hasAssociation($key)) {
             $qb->field($key)->equals($value);
         }
     }
 }
开发者ID:stanlemon,项目名称:rest-bundle,代码行数:12,代码来源:MongoRepositoryWrapper.php

示例3: buildWhereClause

 /**
  * @param QueryBuilder $qb
  * @param Criteria $criteria
  */
 protected function buildWhereClause(QueryBuilder $qb, Criteria $criteria)
 {
     $values = array();
     foreach ($criteria as $key => $value) {
         if ($this->metadata->hasField($key) || $this->metadata->hasAssociation($key)) {
             $qb->andWhere('e.' . $key . ' = :' . $key);
             $values[$key] = $value;
         }
     }
     $qb->setParameters($values);
 }
开发者ID:stanlemon,项目名称:rest-bundle,代码行数:15,代码来源:OrmRepositoryWrapper.php

示例4: mapHierarchy

 /**
  * {@inheritDoc}
  */
 public function mapHierarchy(ClassMetadata $meta)
 {
     if ($meta->isMappedSuperclass || !$meta->isRootEntity()) {
         return;
     }
     $rc = $meta->getReflectionClass();
     if ($rc->hasProperty('parent') && !$meta->hasAssociation('parent')) {
         $meta->mapManyToOne(['targetEntity' => $meta->getName(), 'fieldName' => 'parent', 'inversedBy' => 'children', 'cascade' => ['persist']]);
     }
     if ($rc->hasProperty('children') && !$meta->hasAssociation('children')) {
         $meta->mapOneToMany(['targetEntity' => $meta->getName(), 'fieldName' => 'children', 'mappedBy' => 'parent', 'cascade' => ['persist', 'remove'], 'fetch' => 'EXTRA_LAZY']);
     }
 }
开发者ID:coolms,项目名称:doctrine,代码行数:16,代码来源:ORM.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));
     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

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

示例8: getTransformerInfo

 /**
  * {@inheritdoc}
  */
 public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
 {
     if (!$columnInfo->getLocale() && !count($columnInfo->getSuffixes()) || !$metadata->hasAssociation('translations')) {
         return;
     }
     return array($this->transformer, array());
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:10,代码来源:TranslationGuesser.php

示例9: getTransformerInfo

 /**
  * {@inheritdoc}
  */
 public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
 {
     $mapping = $this->getMapping();
     if (!$metadata->hasAssociation('translations') || !isset($mapping[$columnInfo->getName()])) {
         return null;
     }
     return array($this->transformer, array('propertyPath' => $mapping[$columnInfo->getName()]));
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:11,代码来源:NestedTranslationGuesser.php

示例10: mapTranslation

 /**
  * {@inheritDoc}
  */
 public function mapTranslation(ClassMetadata $meta, $translatableClassName)
 {
     $rc = $meta->getReflectionClass();
     if (!$rc->hasProperty('object') || $meta->hasAssociation('object') || !$rc->isSubclassOf($this->personalTranslation)) {
         return;
     }
     $namingStrategy = $this->getObjectManager()->getConfiguration()->getNamingStrategy();
     $meta->mapManyToOne(['targetEntity' => $translatableClassName, 'fieldName' => 'object', 'inversedBy' => 'translations', 'isOwningSide' => true, 'joinColumns' => [['name' => $namingStrategy->joinColumnName('object'), 'referencedColumnName' => $namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']]]);
 }
开发者ID:coolms,项目名称:doctrine,代码行数:12,代码来源:ORM.php

示例11: testLoadClassMetadata

 public function testLoadClassMetadata()
 {
     $this->loadClassMetadataEvent->getClassMetadata()->willReturn($this->classMetadata->reveal());
     $this->classMetadata->getReflectionClass()->willReturn($this->refl->reveal());
     $this->refl->implementsInterface('Sulu\\Component\\Persistence\\Model\\UserBlameInterface')->willReturn(true);
     $this->classMetadata->hasAssociation('creator')->shouldBeCalled();
     $this->classMetadata->hasAssociation('changer')->shouldBeCalled();
     $this->classMetadata->mapManyToOne(Argument::any())->shouldBeCalled();
     $this->subscriber->loadClassMetadata($this->loadClassMetadataEvent->reveal());
 }
开发者ID:Silwereth,项目名称:sulu,代码行数:10,代码来源:UserBlameSubscriberTest.php

示例12: addStrategy

 /**
  * {@inheritDoc}
  * @throws InvalidArgumentException If a strategy added to a collection does not extend AbstractCollectionStrategy
  */
 public function addStrategy($name, StrategyInterface $strategy)
 {
     if ($this->metadata->hasAssociation($name)) {
         if (!$strategy instanceof Strategy\AbstractCollectionStrategy) {
             throw new InvalidArgumentException(sprintf('Strategies used for collections valued associations must inherit from ' . 'Strategy\\AbstractCollectionStrategy, %s given', get_class($strategy)));
         }
         $strategy->setCollectionName($name)->setClassMetadata($this->metadata);
     }
     return parent::addStrategy($name, $strategy);
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:14,代码来源:DoctrineObject.php

示例13: validateExtendedMetadata

 /**
  * {@inheritDoc}
  */
 protected function validateExtendedMetadata(ClassMetadata $baseClassMetadata, ClassMetadataInterface $extendedClassMetadata)
 {
     if ($extendedClassMetadata->hasTranslatableProperties()) {
         if (!isset($extendedClassMetadata->localeProperty)) {
             throw new Exception\MappingException('Entity \'' . $baseClassMetadata->name . '\' has translatable properties so it must have property marked with @Translatable\\Language annotation');
         }
         $translatableProperties = $extendedClassMetadata->getTranslatableProperties();
         foreach ($translatableProperties as $translation => $properties) {
             if (!$baseClassMetadata->hasAssociation($translation) || !$baseClassMetadata->isCollectionValuedAssociation($translation)) {
                 throw new Exception\MappingException('Field \'' . $translation . '\' in entity \'' . $baseClassMetadata->name . '\' has to be a OneToMany association');
             }
         }
     }
     if (isset($extendedClassMetadata->localeProperty)) {
         if ($extendedClassMetadata->hasTranslatableProperties() && ($baseClassMetadata->hasField($extendedClassMetadata->localeProperty) || $baseClassMetadata->hasAssociation($extendedClassMetadata->localeProperty))) {
             throw new Exception\MappingException('Entity \'' . $baseClassMetadata->name . '\' seems to be a translatable entity so its \'' . $extendedClassMetadata->localeProperty . '\' field must not be persistent');
         } else {
             if (!$extendedClassMetadata->hasTranslatableProperties() && !$baseClassMetadata->hasField($extendedClassMetadata->localeProperty) && !$baseClassMetadata->hasAssociation($extendedClassMetadata->localeProperty)) {
                 throw new Exception\MappingException('Entity \'' . $baseClassMetadata->name . '\' seems to be a translation entity so its \'' . $extendedClassMetadata->localeProperty . '\' field must be persistent');
             }
         }
     }
 }
开发者ID:byteincoffee,项目名称:doctrine-extensions,代码行数:26,代码来源:TranslatableListener.php

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

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


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