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


PHP EntityManagerInterface::getClassMetadata方法代码示例

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


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

示例1: __construct

 /**
  * Constructor.
  *
  * @param EntityManagerInterface  $em
  * @param string                  $class
  * @param string                  $metaClass
  */
 public function __construct(EntityManagerInterface $em, $class, $metaClass)
 {
     $this->em = $em;
     $this->repository = $em->getRepository($class);
     $this->class = $em->getClassMetadata($class)->name;
     $this->metaClass = $em->getClassMetadata($metaClass)->name;
 }
开发者ID:sketchmedia,项目名称:FOSMessageBundle,代码行数:14,代码来源:MessageManager.php

示例2: build

 /**
  * {@inheritdoc}
  */
 public function build(MetadataInterface $metadata, FormBuilderInterface $formBuilder, array $options)
 {
     $classMetadata = $this->entityManager->getClassMetadata($metadata->getClass('model'));
     if (1 < count($classMetadata->identifier)) {
         throw new \RuntimeException('The default form factory does not support entity classes with multiple primary keys.');
     }
     $fields = (array) $classMetadata->fieldNames;
     if (!$classMetadata->isIdentifierNatural()) {
         $fields = array_diff($fields, $classMetadata->identifier);
     }
     foreach ($fields as $fieldName) {
         $options = [];
         if (in_array($fieldName, ['createdAt', 'updatedAt', 'deletedAt'])) {
             continue;
         }
         if (Type::DATETIME === $classMetadata->getTypeOfField($fieldName)) {
             $options = ['widget' => 'single_text'];
         }
         $formBuilder->add($fieldName, null, $options);
     }
     foreach ($classMetadata->getAssociationMappings() as $fieldName => $associationMapping) {
         if (ClassMetadataInfo::ONE_TO_MANY !== $associationMapping['type']) {
             $formBuilder->add($fieldName, null, ['property' => 'id']);
         }
     }
 }
开发者ID:ahmadrabie,项目名称:Sylius,代码行数:29,代码来源:DefaultFormBuilder.php

示例3: testCanBePutInLazyLoadingMode

 public function testCanBePutInLazyLoadingMode()
 {
     $class = $this->_emMock->getClassMetadata('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct');
     $collection = new PersistentCollection($this->_emMock, $class, new ArrayCollection());
     $collection->setInitialized(false);
     $this->assertFalse($collection->isInitialized());
 }
开发者ID:selimcr,项目名称:servigases,代码行数:7,代码来源:PersistentCollectionTest.php

示例4: deserializeRelation

 public function deserializeRelation(JsonDeserializationVisitor $visitor, $relation, array $type, Context $context)
 {
     $className = isset($type['params'][0]['name']) ? $type['params'][0]['name'] : null;
     if (!class_exists($className)) {
         throw new \InvalidArgumentException('Class name should be explicitly set for deserialization');
     }
     /** @var ClassMetadata $metadata */
     $metadata = $this->manager->getClassMetadata($className);
     if (!is_array($relation)) {
         return $this->manager->getReference($className, $relation);
     }
     $single = false;
     if ($metadata->isIdentifierComposite) {
         $single = true;
         foreach ($metadata->getIdentifierFieldNames() as $idName) {
             $single = $single && array_key_exists($idName, $relation);
         }
     }
     if ($single) {
         return $this->manager->getReference($className, $relation);
     }
     $objects = [];
     foreach ($relation as $idSet) {
         $objects[] = $this->manager->getReference($className, $idSet);
     }
     return $objects;
 }
开发者ID:bankiru,项目名称:jsonrpc-server-bundle,代码行数:27,代码来源:RelationsHandler.php

示例5: update

 /**
  * update tables from array of entity classes
  * @param array $classes
  * @param bool $saveMode
  */
 public function update(array $classes, $saveMode = true)
 {
     $metaClasses = array();
     foreach ($classes as $class) {
         $metaClasses[] = $this->entityManager->getClassMetadata($class);
     }
     $this->tool->updateSchema($metaClasses, $saveMode);
 }
开发者ID:Silwereth,项目名称:core,代码行数:13,代码来源:SchemaHelper.php

示例6: getMetadataForEntity

 /**
  * @param object $entity
  *
  * @return ClassMetadata
  */
 protected function getMetadataForEntity($entity)
 {
     $class = ClassUtils::getClass($entity);
     if (!isset($this->metadataCache[$class])) {
         $this->metadataCache[$class] = $this->entityManager->getClassMetadata($class);
     }
     return $this->metadataCache[$class];
 }
开发者ID:ramunasd,项目名称:platform,代码行数:13,代码来源:ModifyCreatedAndUpdatedPropertiesListener.php

示例7: setSectionHasChildren

 public function setSectionHasChildren(Section $section = null, $pageCountModifier = 0)
 {
     if ($section !== null) {
         $repo = $this->entityManager->getRepository('BackBee\\CoreDomain\\NestedNode\\Page');
         $notDeletedDescendants = $repo->getNotDeletedDescendants($section->getPage(), 1, false, [], true, 0, 2);
         $section->setHasChildren($notDeletedDescendants->getIterator()->count() + $pageCountModifier > 0);
         $this->entityManager->getUnitOfWork()->recomputeSingleEntityChangeSet($this->entityManager->getClassMetadata('BackBee\\CoreDomain\\NestedNode\\Section'), $section);
     }
 }
开发者ID:ReissClothing,项目名称:BackBee,代码行数:9,代码来源:PageListener.php

示例8: getMapping

 /**
  * @see MetadataCache::getMapping
  */
 public function getMapping($className)
 {
     if (!is_string($className) && !is_object($className)) {
         throw new \Exception(self::ERROR_MAPPING_EXPECTED_VALUE);
     }
     $this->stringify($className);
     $metadata = $this->getMetadata($className);
     if (empty($metadata->mapping)) {
         $metadata->mapping = $this->entityManager->getClassMetadata($className);
     }
     return $metadata->mapping;
 }
开发者ID:gointegro,项目名称:hateoas,代码行数:15,代码来源:ArrayMetadataCache.php

示例9: ApplyCriteria

 /**
  * @param Request           $request
  * @param ResourceInterface $resourceEmbed
  * @param                   $data
  *
  * @return \Doctrine\Common\Collections\Collection|PersistentCollection
  */
 public function ApplyCriteria(Request $request, ResourceInterface $resourceEmbed, $data)
 {
     if ($data instanceof PersistentCollection && $data->count() > 0) {
         $embedClassMeta = $this->em->getClassMetadata($resourceEmbed->getEntityClass());
         $criteria = Criteria::create();
         foreach ($resourceEmbed->getFilters() as $filter) {
             if ($filter instanceof FilterInterface) {
                 $this->applyFilter($request, $filter, $criteria, $embedClassMeta);
                 $data = $data->matching($criteria);
             }
         }
     }
     return $data;
 }
开发者ID:eliberty,项目名称:api-bundle,代码行数:21,代码来源:ApplyCriteriaEmbed.php

示例10: guessFilterTypeFromArray

 /**
  * Determines the type of which filter class to instantiate, based on
  * the structured array received and the given entity class.
  *
  * @param FilterOptions $filterOptions
  * @param string        $entity
  *
  * @return null|FilterInterface
  */
 public function guessFilterTypeFromArray($filterOptions, $entity)
 {
     $filterType = null;
     /* in case the attribute to filter by is situated in another entity,
        parse the connected entities until you reach its entity */
     if ($path = $filterOptions->getPathArray()) {
         while ($path) {
             $entity = $this->em->getClassMetadata($entity)->getAssociationMapping(array_shift($path))['targetEntity'];
         }
     }
     if ($filter = $this->filterFieldReader->getFilter($entity, $attribute = $filterOptions->getName())) {
         /* get the type of the attribute that corresponds to the filter */
         $attributeType = isset($filter[$attribute]['options']['type']) ? $filter[$attribute]['options']['type'] : $this->em->getClassMetadata($entity)->getTypeOfField($filter[$attribute]['property']);
         $filterOptions->setAttribute($filter[$attribute]['property']);
         if (sizeof($filterOptions->getValues()) == 1) {
             switch ($attributeType) {
                 case 'integer':
                     $filterType = FilterInterface::NUMERIC_FILTER;
                     break;
                 case 'text':
                 case 'string':
                     $filterType = FilterInterface::STRING_FILTER;
                     break;
                 case 'date':
                     $filterType = FilterInterface::DATE_FILTER;
                     break;
                 case 'checker':
                     $filterType = FilterInterface::CHECK_FILTER;
                     break;
             }
         } else {
             switch ($attributeType) {
                 case 'integer':
                     $filterType = FilterInterface::NUMERIC_INTERVAL_FILTER;
                     break;
                 case 'date':
                     $filterType = FilterInterface::DATE_INTERVAL_FILTER;
                     break;
                 case 'string':
                     $filterType = FilterInterface::OR_STRING_FILTER;
                     break;
                 case 'date_check':
                     $filterType = FilterInterface::DATE_CHECK_FILTER;
                     break;
             }
         }
     }
     return $filterType;
 }
开发者ID:lenardpalko,项目名称:filters-bundle,代码行数:58,代码来源:FilterTypeGuesser.php

示例11: getClassMetadata

 /**
  * Retrieve ClassMetadata associated to entity class name.
  *
  * @param string $className
  *
  * @return \Doctrine\ORM\Mapping\ClassMetadata
  */
 protected function getClassMetadata($className)
 {
     if (!isset($this->_metadataCache[$className])) {
         $this->_metadataCache[$className] = $this->_em->getClassMetadata($className);
     }
     return $this->_metadataCache[$className];
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:14,代码来源:AbstractHydrator.php

示例12: transform

 public function transform($value)
 {
     // already transformed (or null)
     if (is_array($value) || is_null($value)) {
         return $value;
     }
     if (!is_object($value)) {
         throw new TransformationFailedException(sprintf('Expected an object to transform, got "%s"', json_encode($value)));
     }
     // load object if it's a Proxy
     if ($value instanceof Proxy) {
         $value->__load();
     }
     $meta = $this->entityManager->getClassMetadata(get_class($value));
     return $meta->getIdentifierValues($value);
 }
开发者ID:treehouselabs,项目名称:io-bundle,代码行数:16,代码来源:EntityToIdTransformer.php

示例13: getMutatedFields

 /**
  * Return the field names of fields that had their value/relation changed
  *
  * @param EntityManagerInterface $em
  * @param mixed                  $entity
  * @param mixed                  $original
  * @return bool
  */
 public function getMutatedFields(EntityManagerInterface $em, $entity, $original)
 {
     $mutation_data = [];
     /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
     $metadata = $em->getClassMetadata(get_class($entity));
     $fields = $metadata->getFieldNames();
     $associations = $metadata->getAssociationNames();
     if ($entity !== null && $original === null) {
         return array_merge($fields, $associations);
     }
     for ($i = 0, $n = count($fields); $i < $n; $i++) {
         $field = $fields[$i];
         $left = $metadata->getFieldValue($entity, $field);
         $right = $metadata->getFieldValue($original, $field);
         if ($left !== $right) {
             $mutation_data[] = $field;
         }
     }
     for ($i = 0, $n = count($associations); $i < $n; $i++) {
         $association = $associations[$i];
         $association_meta = $metadata->getAssociationMapping($association);
         if ($association_meta['type'] === ClassMetadataInfo::ONE_TO_ONE && !$association_meta['isOwningSide']) {
             continue;
         }
         $association_target_meta = $em->getClassMetadata($metadata->getAssociationTargetClass($association));
         $association_value_left = $metadata->getFieldValue($entity, $association);
         $association_value_right = $metadata->getFieldValue($original, $association);
         if ($this->hasAssociationChanged($association_target_meta, $association_value_left, $association_value_right)) {
             $mutation_data[] = $association;
         }
     }
     return $mutation_data;
 }
开发者ID:nutama,项目名称:entity-tracker-component,代码行数:41,代码来源:EntityMutationMetadataProvider.php

示例14: generateSelectClause

 /**
  * Generates the Select clause from this ResultSetMappingBuilder.
  *
  * Works only for all the entity results. The select parts for scalar
  * expressions have to be written manually.
  *
  * @param array $tableAliases
  *
  * @return string
  */
 public function generateSelectClause($tableAliases = array())
 {
     $sql = "";
     foreach ($this->columnOwnerMap as $columnName => $dqlAlias) {
         $tableAlias = isset($tableAliases[$dqlAlias]) ? $tableAliases[$dqlAlias] : $dqlAlias;
         if ($sql) {
             $sql .= ", ";
         }
         $sql .= $tableAlias . ".";
         if (isset($this->fieldMappings[$columnName])) {
             $class = $this->em->getClassMetadata($this->declaringClasses[$columnName]);
             $sql .= $class->fieldMappings[$this->fieldMappings[$columnName]]['columnName'];
         } else {
             if (isset($this->metaMappings[$columnName])) {
                 $sql .= $this->metaMappings[$columnName];
             } else {
                 if (isset($this->discriminatorColumn[$columnName])) {
                     $sql .= $this->discriminatorColumn[$columnName];
                 }
             }
         }
         $sql .= " AS " . $columnName;
     }
     return $sql;
 }
开发者ID:skyview059,项目名称:doctrine2,代码行数:35,代码来源:ResultSetMappingBuilder.php

示例15: prepare

 private function prepare($data)
 {
     $metaDataClass = $this->entityManager->getClassMetadata(get_class($data));
     $assocFields = $metaDataClass->getAssociationMappings();
     foreach ($assocFields as $assoc) {
         $relatedEntities = $metaDataClass->reflFields[$assoc['fieldName']]->getValue($data);
         if ($relatedEntities instanceof Collection) {
             if ($relatedEntities === $metaDataClass->reflFields[$assoc['fieldName']]->getValue($data)) {
                 continue;
             }
             if ($relatedEntities instanceof PersistentCollection) {
                 // Unwrap so that foreach() does not initialize
                 $relatedEntities = $relatedEntities->unwrap();
             }
             foreach ($relatedEntities as $relatedEntity) {
                 $relatedEntitiesState = $this->entityManager->getUnitOfWork()->getEntityState($relatedEntities);
                 if ($relatedEntitiesState === UnitOfWork::STATE_DETACHED) {
                     $metaDataClass->setFieldValue($data, $assoc['fieldName'], $this->entityManager->merge($relatedEntity));
                 }
             }
         } else {
             if ($relatedEntities !== null) {
                 $relatedEntitiesState = $this->entityManager->getUnitOfWork()->getEntityState($relatedEntities);
                 if ($relatedEntitiesState === UnitOfWork::STATE_DETACHED) {
                     $metaDataClass->setFieldValue($data, $assoc['fieldName'], $this->entityManager->merge($relatedEntities));
                 }
             }
         }
     }
 }
开发者ID:pbrazhko,项目名称:form-wizard-bundle-for-symfony,代码行数:30,代码来源:WizardStorage.php


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