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


PHP ClassMetadata::isCollectionValuedAssociation方法代码示例

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


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

示例1: guessColumnFormatters

 public function guessColumnFormatters(\Faker\Generator $generator)
 {
     $formatters = array();
     $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;
         }
         $size = isset($this->class->fieldMappings[$fieldName]['length']) ? $this->class->fieldMappings[$fieldName]['length'] : null;
         if ($formatter = $nameGuesser->guessFormat($fieldName, $size)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($fieldName, $this->class)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     foreach ($this->class->getAssociationNames() as $assocName) {
         if ($this->class->isCollectionValuedAssociation($assocName)) {
             continue;
         }
         $relatedClass = $this->class->getAssociationTargetClass($assocName);
         $unique = $optional = false;
         $mappings = $this->class->getAssociationMappings();
         foreach ($mappings as $mapping) {
             if ($mapping['targetEntity'] == $relatedClass) {
                 if ($mapping['type'] == ClassMetadata::ONE_TO_ONE) {
                     $unique = true;
                     $optional = isset($mapping['joinColumns'][0]['nullable']) ? $mapping['joinColumns'][0]['nullable'] : false;
                     break;
                 }
             }
         }
         $index = 0;
         $formatters[$assocName] = function ($inserted) use($relatedClass, &$index, $unique, $optional) {
             if ($unique && isset($inserted[$relatedClass])) {
                 $related = null;
                 if (isset($inserted[$relatedClass][$index]) || !$optional) {
                     $related = $inserted[$relatedClass][$index];
                 }
                 $index++;
                 return $related;
             } elseif (isset($inserted[$relatedClass])) {
                 return $inserted[$relatedClass][mt_rand(0, count($inserted[$relatedClass]) - 1)];
             }
             return null;
         };
     }
     return $formatters;
 }
开发者ID:leloulight,项目名称:ProjectManager,代码行数:52,代码来源:EntityPopulator.php

示例2: setFieldLimit

 /**
  * @param array         $fieldConfig
  * @param ClassMetadata $metadata
  * @param string        $fieldName
  * @param int           $limit
  */
 protected function setFieldLimit(array &$fieldConfig, ClassMetadata $metadata, $fieldName, $limit)
 {
     if ($metadata->hasAssociation($fieldName)) {
         if (!array_key_exists(ConfigUtil::MAX_RESULTS, $fieldConfig) && $metadata->isCollectionValuedAssociation($fieldName)) {
             $fieldConfig[ConfigUtil::MAX_RESULTS] = $limit;
         }
         $this->setLimits($fieldConfig, $metadata->name, $limit);
     }
 }
开发者ID:startupz,项目名称:platform-1,代码行数:15,代码来源:SetMaxRelatedEntities.php

示例3: createAssociationMetadata

 /**
  * @param ClassMetadata $classMetadata
  * @param string        $associationName
  *
  * @return AssociationMetadata
  */
 public function createAssociationMetadata(ClassMetadata $classMetadata, $associationName)
 {
     $targetClass = $classMetadata->getAssociationTargetClass($associationName);
     $associationMetadata = new AssociationMetadata();
     $associationMetadata->setName($associationName);
     $associationMetadata->setTargetClassName($targetClass);
     $associationMetadata->setIsCollection($classMetadata->isCollectionValuedAssociation($associationName));
     $targetMetadata = $this->doctrineHelper->getEntityMetadataForClass($targetClass);
     $targetIdFields = $targetMetadata->getIdentifierFieldNames();
     if (count($targetIdFields) === 1) {
         $associationMetadata->setDataType($targetMetadata->getTypeOfField(reset($targetIdFields)));
     } else {
         $associationMetadata->setDataType(DataType::STRING);
     }
     return $associationMetadata;
 }
开发者ID:Maksold,项目名称:platform,代码行数:22,代码来源:EntityMetadataFactory.php

示例4: extendLoadMetadataForClass

 /**
  * Merge DoctrineClassMetadata and DataAuditClassMetadata
  * @param  DoctrineClassMetadata $doctrineClassMetadata
  * @return null|ClassMetadata
  * @throws \InvalidArgumentException
  */
 public function extendLoadMetadataForClass(DoctrineClassMetadata $doctrineClassMetadata)
 {
     if ($doctrineClassMetadata->isMappedSuperclass || !($classMetadata = $this->loadMetadataForClass($doctrineClassMetadata->getReflectionClass()))) {
         return null;
     }
     /** @var $property PropertyMetadata */
     foreach ($classMetadata->propertyMetadata as $name => $property) {
         if ($doctrineClassMetadata->isInheritedField($name) || isset($doctrineClassMetadata->associationMappings[$property->name]['inherited'])) {
             unset($classMetadata->propertyMetadata[$name]);
             continue;
         }
         if ($doctrineClassMetadata->isCollectionValuedAssociation($name)) {
             $property->isCollection = true;
             $targetMapping = $doctrineClassMetadata->getAssociationMapping($name);
             if (!method_exists($targetMapping['targetEntity'], $property->method)) {
                 throw new \InvalidArgumentException(sprintf("Method %s in Class %s is not defined. Class must implement " . "a method '__toString' or configure getMethod with Versioned annotation", $property->method, $targetMapping['targetEntity']));
             }
         }
     }
     return $classMetadata;
 }
开发者ID:Maksold,项目名称:platform,代码行数:27,代码来源:AnnotationDriver.php

示例5: createAssociationMetadata

 /**
  * @param ClassMetadata $classMetadata
  * @param string        $associationName
  *
  * @return AssociationMetadata
  */
 public function createAssociationMetadata(ClassMetadata $classMetadata, $associationName)
 {
     $targetClass = $classMetadata->getAssociationTargetClass($associationName);
     $associationMetadata = new AssociationMetadata();
     $associationMetadata->setName($associationName);
     $associationMetadata->setTargetClassName($targetClass);
     $associationMetadata->setIsCollection($classMetadata->isCollectionValuedAssociation($associationName));
     $targetMetadata = $this->doctrineHelper->getEntityMetadataForClass($targetClass);
     $targetIdFields = $targetMetadata->getIdentifierFieldNames();
     if (count($targetIdFields) === 1) {
         $associationMetadata->setDataType($targetMetadata->getTypeOfField(reset($targetIdFields)));
     } else {
         $associationMetadata->setDataType(DataType::STRING);
     }
     if ($targetMetadata->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) {
         $associationMetadata->setAcceptableTargetClassNames($targetMetadata->subClasses);
     } else {
         $associationMetadata->addAcceptableTargetClassName($targetClass);
     }
     return $associationMetadata;
 }
开发者ID:startupz,项目名称:platform-1,代码行数:27,代码来源:EntityMetadataFactory.php

示例6: createAssociationField

 /**
  * @param FormBuilder $form
  * @param ClassMetadata $metaData
  * @param string $fieldName
  */
 public function createAssociationField($form, $metaData, $fieldName)
 {
     $formField = new SelectField(array());
     $formField->setLabel($this->translateName($fieldName));
     $formField->setName($fieldName);
     $mapping = $metaData->getAssociationMapping($fieldName);
     $required = false;
     $targetEntityName = $metaData->getAssociationTargetClass($fieldName);
     $targetEntity = $this->doctrineService->getRepository($targetEntityName);
     if ($metaData->isCollectionValuedAssociation($fieldName)) {
         $formField->setMultiple(true);
         $formField->setRequired(false);
     } else {
         foreach ($mapping['joinColumns'] as $joinColumn) {
             if (!$joinColumn['nullable']) {
                 $required = true;
                 break;
             }
         }
         $formField->setRequired($required);
     }
     $collection = static::entityToCollection($targetEntity->findAll(), !$formField->isMultiple());
     $formField->setCollection($collection);
     $form->addField($formField);
 }
开发者ID:itephp,项目名称:doctrine-bridge,代码行数:30,代码来源:DoctrineDesigner.php

示例7: convertMetadata

 /**
  * @param ClassMetadata $metadata
  * @return JavaScript\Metadata
  */
 private function convertMetadata(ClassMetadata $metadata)
 {
     $meta = new JavaScript\Metadata();
     $meta->originalName = $metadata->getName();
     $meta->namespace = str_replace('\\', '_', $metadata->getReflectionClass()->getNamespaceName());
     $meta->functionName = $metadata->getReflectionClass()->getShortName();
     $parent = $metadata->getReflectionClass()->getParentClass();
     $meta->superFunctionName = $parent ? $parent->getShortName() : 'DBEntity';
     // Convert fields.
     foreach ($metadata->getFieldNames() as $fieldName) {
         $field = new JavaScript\Field();
         $field->name = $fieldName;
         $field->methodName = ucfirst($fieldName);
         $field->type = $this->convertDoctrineType($metadata->getTypeOfField($fieldName));
         $field->isIdentifier = $metadata->isIdentifier($fieldName);
         $meta->fields[] = $field;
     }
     // Convert associations.
     foreach ($metadata->getAssociationNames() as $assocName) {
         $assoc = new JavaScript\Association();
         $assoc->name = $assocName;
         $assoc->methodName = ucfirst($assocName);
         $assoc->isCollection = $metadata->isCollectionValuedAssociation($assocName);
         $assoc->isSingle = $metadata->isSingleValuedAssociation($assocName);
         $assoc->singleName = Inflector::singularize($assoc->methodName);
         $assoc->invertedField = $metadata->getAssociationMappedByTargetField($assocName);
         $targetClass = new \ReflectionClass($metadata->getAssociationTargetClass($assocName));
         $assoc->singleType = $targetClass->getShortName();
         $assoc->type = $assoc->singleType . ($assoc->isCollection ? '[]' : '');
         $meta->associations[] = $assoc;
     }
     return $meta;
 }
开发者ID:CornyPhoenix,项目名称:JsEntitiesBundle,代码行数:37,代码来源:JsEntityConverter.php

示例8: save

 /**
  * @param \Doctrine\ORM\Mapping\ClassMetadata $meta
  * @param \Nette\ComponentModel\Component $component
  * @param mixed $entity
  * @return boolean
  */
 public function save(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof BaseControl) {
         return false;
     }
     $name = $component->getOption(self::FIELD_NAME, $component->getName());
     $value = $component->getValue();
     if ($this->accessor->isWritable($entity, $name) && !$meta->hasAssociation($name)) {
         try {
             $this->accessor->setValue($entity, $name, $value);
             return true;
         } catch (\Kdyby\Doctrine\MemberAccessException $e) {
         }
     }
     if (!$meta->hasAssociation($name)) {
         return false;
     }
     $value = $component->getValue();
     $entityClass = $this->relatedMetadata($entity, $name)->getName();
     $repository = $this->entityManager->getRepository($entityClass);
     if ($meta->isCollectionValuedAssociation($name)) {
         $property = \Doctrine\Common\Util\Inflector::singularize($name);
         foreach ($repository->findAll() as $associatedEntity) {
             if (in_array($associatedEntity->id, $value)) {
                 $hasMethod = 'has' . ucfirst($property);
                 if (!$entity->{$hasMethod}($associatedEntity)) {
                     $addMethod = 'add' . ucfirst($property);
                     $entity->{$addMethod}($associatedEntity);
                 }
             } else {
                 $removeMethod = 'remove' . ucfirst($property);
                 $entity->{$removeMethod}($associatedEntity);
             }
         }
     } elseif ($value === null || ($value = $repository->find($value))) {
         if ($this->accessor->isWritable($entity, $name)) {
             try {
                 $this->accessor->setValue($entity, $name, $value);
             } catch (\Kdyby\Doctrine\MemberAccessException $e) {
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:venne,项目名称:venne,代码行数:51,代码来源:TextControl.php


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