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


PHP ClassMetadata::getAssociationMapping方法代码示例

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


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

示例1: handleAssocProperty

 /**
  * Handle an associative property field
  * @param string                              $name             - name of the field
  * @param \Zend\Code\Generator\ClassGenerator $cg               - The class generator object to attach to
  * @param ORMClassMetadata $ormClassMetaData - The ORM class meta data
  */
 private function handleAssocProperty($name, Generator\ClassGenerator &$cg, ORMClassMetadata $ormClassMetaData)
 {
     /** @var \Doctrine\ORM\Mapping\ClassMetaData $ormClassMetaData */
     $assocMapping = $ormClassMetaData->getAssociationMapping($name);
     $property = $this->createProperty($name);
     if ($assocMapping['type'] & $ormClassMetaData::TO_MANY) {
         // This is a collection (should be an Array)
         $property->setDocBlock('@var array $' . $name);
         $property->setDefaultValue([]);
         $paramType = self::PARAM_TYPE_RELATION_COLLECTION;
     } else {
         // This is a single relation
         $property->setDocBlock('@var ' . $assocMapping['targetEntity'] . ' $' . $name);
         $paramType = self::PARAM_TYPE_RELATION_SINGLE;
     }
     if (!$cg->hasProperty($name)) {
         $cg->addProperties([$property]);
         $cg->addMethods($this->getSetterMethods($cg, $name, $paramType, $assocMapping['targetEntity']));
     }
 }
开发者ID:jdrich,项目名称:drest,代码行数:26,代码来源:ClassGenerator.php

示例2: getSqlForManyToOneAndOneToOneRelationsWithoutPropertyPath

 /**
  * @param DoctrineSqlFilter $sqlFilter
  * @param QuoteStrategy $quoteStrategy
  * @param ClassMetadata $targetEntity
  * @param string $targetTableAlias
  * @param string $targetEntityPropertyName
  * @return string
  * @throws InvalidQueryRewritingConstraintException
  * @throws \Exception
  */
 protected function getSqlForManyToOneAndOneToOneRelationsWithoutPropertyPath(DoctrineSqlFilter $sqlFilter, QuoteStrategy $quoteStrategy, ClassMetadata $targetEntity, $targetTableAlias, $targetEntityPropertyName)
 {
     $associationMapping = $targetEntity->getAssociationMapping($targetEntityPropertyName);
     $constraints = array();
     foreach ($associationMapping['joinColumns'] as $joinColumn) {
         $quotedColumnName = $quoteStrategy->getJoinColumnName($joinColumn, $targetEntity, $this->entityManager->getConnection()->getDatabasePlatform());
         $propertyPointer = $targetTableAlias . '.' . $quotedColumnName;
         $operandAlias = $this->operandDefinition;
         if (is_array($this->operandDefinition)) {
             $operandAlias = key($this->operandDefinition);
         }
         $currentReferencedOperandName = $operandAlias . $joinColumn['referencedColumnName'];
         if (is_object($this->operand)) {
             $operandMetadataInfo = $this->entityManager->getClassMetadata(TypeHandling::getTypeForValue($this->operand));
             $currentReferencedValueOfOperand = $operandMetadataInfo->getFieldValue($this->operand, $operandMetadataInfo->getFieldForColumn($joinColumn['referencedColumnName']));
             $this->setParameter($sqlFilter, $currentReferencedOperandName, $currentReferencedValueOfOperand, $associationMapping['type']);
         } elseif (is_array($this->operandDefinition)) {
             foreach ($this->operandDefinition as $operandIterator => $singleOperandValue) {
                 if (is_object($singleOperandValue)) {
                     $operandMetadataInfo = $this->entityManager->getClassMetadata(TypeHandling::getTypeForValue($singleOperandValue));
                     $currentReferencedValueOfOperand = $operandMetadataInfo->getFieldValue($singleOperandValue, $operandMetadataInfo->getFieldForColumn($joinColumn['referencedColumnName']));
                     $this->setParameter($sqlFilter, $operandIterator, $currentReferencedValueOfOperand, $associationMapping['type']);
                 } elseif ($singleOperandValue === NULL) {
                     $this->setParameter($sqlFilter, $operandIterator, NULL, $associationMapping['type']);
                 }
             }
         }
         $constraints[] = $this->getConstraintStringForSimpleProperty($sqlFilter, $propertyPointer, $currentReferencedOperandName);
     }
     return ' (' . implode(' ) AND ( ', $constraints) . ') ';
 }
开发者ID:nlx-sascha,项目名称:flow-development-collection,代码行数:41,代码来源:PropertyConditionGenerator.php

示例3: updateTranslations

 /**
  * Helper method to insert, remove or update translations entities associated with specified object
  *
  * @param \Doctrine\Common\Persistence\ObjectManager $objectManager
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $meta
  * @param \FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata $translatableMeta
  * @param object $object
  */
 protected function updateTranslations(ObjectManager $objectManager, ClassMetadata $meta, TranslatableClassMetadata $translatableMeta, $object)
 {
     $localeProperty = $translatableMeta->localeProperty;
     $propertyObserver = $this->getPropertyObserver($objectManager);
     $locale = $objectLocale = PropertyAccess::createPropertyAccessor()->getValue($object, $localeProperty);
     $objectLanguageChanged = !$propertyObserver->hasSavedValue($object, $localeProperty) && isset($objectLocale) || $propertyObserver->hasSavedValue($object, $localeProperty) && $propertyObserver->hasValueChanged($object, $localeProperty);
     if (!isset($locale)) {
         $locale = $this->getLocale();
     }
     $translatableProperties = $translatableMeta->getTranslatableProperties();
     foreach ($translatableProperties as $translation => $properties) {
         $translationEntity = $meta->getAssociationTargetClass($translation);
         $translationMeta = $objectManager->getClassMetadata($translationEntity);
         $translationLanguageField = $this->getTranslationLanguageField($objectManager, $translationMeta->name);
         $translationAssociation = $meta->getAssociationMapping($translation);
         $translations = $meta->getFieldValue($object, $translation);
         $currentTranslation = null;
         if (isset($translations)) {
             $currentTranslation = $this->findTranslation($translations, $translationMeta, $translationLanguageField, $locale);
         }
         $propertiesFound = false;
         foreach ($properties as $property => $translationField) {
             $propertyValue = PropertyAccess::createPropertyAccessor()->getValue($object, $property);
             if (isset($propertyValue)) {
                 $propertiesFound = true;
             }
             if ($objectLanguageChanged || !$propertyObserver->hasSavedValue($object, $property) && isset($propertyValue) || $propertyObserver->hasSavedValue($object, $property) && $propertyObserver->hasValueChanged($object, $property)) {
                 if (isset($propertyValue)) {
                     if (!isset($currentTranslation)) {
                         $currentTranslation = new $translationEntity();
                         $translationMeta->setFieldValue($currentTranslation, $translationLanguageField, $locale);
                         $translationMeta->setFieldValue($currentTranslation, $translationAssociation['mappedBy'], $object);
                         if (isset($translationAssociation['indexBy'])) {
                             $index = $translationMeta->getFieldValue($currentTranslation, $translationAssociation['indexBy']);
                             $translations[$index] = $currentTranslation;
                         } else {
                             $translations[] = $currentTranslation;
                         }
                         $objectManager->persist($currentTranslation);
                     }
                     $translationMeta->setFieldValue($currentTranslation, $translationField, $propertyValue);
                 } else {
                     if ($currentTranslation) {
                         $translationMeta->setFieldValue($currentTranslation, $translationField, null);
                     }
                 }
             }
         }
         if ($propertiesFound && !isset($locale)) {
             throw new Exception\RuntimeException('Neither object\'s locale nor the default locale was defined for translatable properties');
         }
         if (!$propertiesFound && isset($currentTranslation) && isset($objectLocale)) {
             $objectManager->remove($currentTranslation);
             if ($translations->contains($currentTranslation)) {
                 $translations->removeElement($currentTranslation);
             }
         }
     }
 }
开发者ID:byteincoffee,项目名称:doctrine-extensions,代码行数:67,代码来源:TranslatableListener.php


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