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


PHP ClassMetadata::getIdentifier方法代码示例

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


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

 /**
  * @param Criteria $criteria
  */
 public function count(Criteria $criteria)
 {
     $identifiers = $this->metadata->getIdentifier();
     $identifierName = reset($identifiers);
     $qb = $this->repository->createQueryBuilder('e');
     $this->buildWhereClause($qb, $criteria);
     return $qb->select("count(e.{$identifierName})")->getQuery()->getSingleScalarResult();
 }
开发者ID:stanlemon,项目名称:rest-bundle,代码行数:11,代码来源:OrmRepositoryWrapper.php

示例3:

 function it_schedules_owning_document_for_update_when_setting_element_by_key_in_the_collection(MongoDBODMUnitOfWork $uow, DocumentStub $document, ObjectRepository $repository, ClassMetadata $classMetadata, EntityStub $entity4, EntityStub $entity8, EntityStub $entity15, EntityStub $newEntity)
 {
     $classMetadata->getIdentifier()->willReturn(['id']);
     $repository->findBy(['id' => [4, 8, 15]])->willReturn([$entity4, $entity8, $entity15]);
     $uow->getDocumentState($document)->willReturn(MongoDBODMUnitOfWork::STATE_MANAGED);
     $uow->isScheduledForUpdate($document)->willReturn(false);
     $uow->scheduleForUpdate($document)->shouldBeCalled();
     $this->setOwner($document);
     $this->set(2, $newEntity);
 }
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:10,代码来源:ReferencedCollectionSpec.php

示例4: fieldList

 public function fieldList(ClassMetadata $metadata, $includeId = true)
 {
     $return = [];
     $serializerMetadata = $metadata->getSerializer();
     foreach ($metadata->getFieldNames() as $field) {
         if (isset($serializerMetadata['fields'][$field]['unserializeIgnore']) && $serializerMetadata['fields'][$field]['unserializeIgnore']) {
             continue;
         }
         $return[] = $field;
     }
     if (!$includeId) {
         unset($return[$metadata->getIdentifier()]);
     }
     return $return;
 }
开发者ID:zoopcommerce,项目名称:shard,代码行数:15,代码来源:Unserializer.php

示例5: execute

 /**
  * Insert one new record using the Entity class.
  * @param ObjectManager $manager
  * @param bool $generateId
  * @return EntityPopulator
  */
 public function execute(ObjectManager $manager, $insertedEntities, $generateId = false)
 {
     $obj = $this->class->newInstance();
     $this->fillColumns($obj, $insertedEntities);
     $this->callMethods($obj, $insertedEntities);
     if ($generateId) {
         $idsName = $this->class->getIdentifier();
         foreach ($idsName as $idName) {
             $id = $this->generateId($obj, $idName, $manager);
             $this->class->reflFields[$idName]->setValue($obj, $id);
         }
     }
     $manager->persist($obj);
     return $obj;
 }
开发者ID:brainrepo,项目名称:Faker,代码行数:21,代码来源:EntityPopulator.php

示例6: reverseTransform

 /**
  * @inheritdoc
  */
 public function reverseTransform($value)
 {
     if (!is_array($value) || count($value) === 0) {
         return new ArrayCollection();
     }
     if ($this->tags && $this->property) {
         $objects = [];
         foreach ($value as $val) {
             if (!is_numeric($value)) {
                 $objects[] = $this->metadata->newInstance();
                 $this->propertyAccessor->setValue(end($objects), $this->property, $val);
             }
             $objects[] = $this->em->getRepository($this->class)->find($val);
         }
         return $objects;
     }
     return $this->em->getRepository($this->class)->findBy([$this->metadata->getIdentifier()[0] => $value]);
 }
开发者ID:snovichkov,项目名称:Select2Bundle,代码行数:21,代码来源:EntitiesToPropertyTransformer.php

示例7: readMetadata

 /**
  * {@inheritdoc}
  */
 public function readMetadata(ClassMetadata $doctrineMeta, array &$meta)
 {
     $reflectionClass = $doctrineMeta->getReflectionClass();
     $copyingPolicy = null;
     if (isset($meta['clonable'])) {
         $copyingPolicy = $meta['clonable']['copyingPolicy'];
     }
     $clonableAnnotation = $this->reader->getClassAnnotation($reflectionClass, Clonable::ANNOTATION);
     if ($clonableAnnotation instanceof Clonable) {
         $copyingPolicy = $clonableAnnotation->copyingPolicy;
     }
     if (empty($copyingPolicy)) {
         return;
     }
     if (!isset($meta['clonable'])) {
         $meta['clonable'] = [];
     }
     $meta['clonable']['copyingPolicy'] = $copyingPolicy;
     $properties = $this->getPropertiesToCopy($reflectionClass, $copyingPolicy, $doctrineMeta->getIdentifier());
     $meta['clonable']['properties'] = isset($meta['clonable']['properties']) ? array_merge($meta['clonable']['properties'], $properties) : $properties;
 }
开发者ID:darvinstudio,项目名称:darvin-utils,代码行数:24,代码来源:ClonableDriver.php

示例8: isShortIdentifierGetter

 /**
  * Checks if the method is a short identifier getter.
  *
  * What does this mean? For proxy objects the identifier is already known,
  * however accessing the getter for this identifier usually triggers the
  * lazy loading, leading to a query that may not be necessary if only the
  * ID is interesting for the userland code (for example in views that
  * generate links to the entity, but do not display anything else).
  *
  * @param \ReflectionMethod                                  $method
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $class
  *
  * @return boolean
  */
 private function isShortIdentifierGetter($method, ClassMetadata $class)
 {
     $identifier = lcfirst(substr($method->getName(), 3));
     $startLine = $method->getStartLine();
     $endLine = $method->getEndLine();
     $cheapCheck = $method->getNumberOfParameters() == 0 && substr($method->getName(), 0, 3) == 'get' && in_array($identifier, $class->getIdentifier(), true) && $class->hasField($identifier) && $endLine - $startLine <= 4;
     if ($cheapCheck) {
         $code = file($method->getDeclaringClass()->getFileName());
         $code = trim(implode(' ', array_slice($code, $startLine - 1, $endLine - $startLine + 1)));
         $pattern = sprintf(self::PATTERN_MATCH_ID_METHOD, $method->getName(), $identifier);
         if (preg_match($pattern, $code)) {
             return true;
         }
     }
     return false;
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:30,代码来源:ProxyGenerator.php

示例9: extractPropertiesAnnotations

 /**
  * Extract the property annotations.
  *
  * @param \ReflectionProperty[] $reflProperties
  * @param ClassMetadata|\Revinate\SearchBundle\Lib\Search\Mapping\ClassMetadata $metadata
  *
  * @return ClassMetadata|\Revinate\SearchBundle\Lib\Search\Mapping\ClassMetadata
  */
 private function extractPropertiesAnnotations(array $reflProperties, ClassMetadata $metadata)
 {
     foreach ($reflProperties as $reflProperty) {
         foreach ($this->reader->getPropertyAnnotations($reflProperty) as $annotation) {
             foreach ($this->entityFieldAnnotationClasses as $fieldAnnotationClass) {
                 if ($annotation instanceof $fieldAnnotationClass) {
                     if ($annotation instanceof $this->entityIdAnnotationClass) {
                         $metadata->setIdentifier($reflProperty->name);
                     } elseif ($annotation instanceof $this->entityTimeSeriesFieldAnnotationClass) {
                         $metadata->setTimeSeriesField($reflProperty->name);
                     } elseif ($annotation instanceof $this->entityParamAnnotationClass) {
                         $metadata->addParameterMapping($reflProperty, $annotation);
                     } elseif ($annotation instanceof $this->entityParentFieldAnnotationClass) {
                         $metadata->setParentField($reflProperty->name);
                     } elseif ($annotation instanceof $this->entityVersionFieldAnnotationClass) {
                         /** @var Search\VersionField $annotation */
                         $metadata->setVersionField($reflProperty->name);
                         $metadata->setVersionType($annotation->versionType);
                     } else {
                         $metadata->addFieldMapping($reflProperty, $annotation);
                     }
                     continue 2;
                 }
             }
         }
     }
     $id = $metadata->getIdentifier();
     if (empty($id)) {
         throw new \Exception(__METHOD__ . ': Id field must be defined!');
     }
     if ($metadata->timeSeriesScale && !$metadata->getTimeSeriesField()) {
         throw new \Exception(__METHOD__ . ': TimeSeriesField must be defined for a time series index!');
     }
     return $metadata;
 }
开发者ID:revinate,项目名称:search-bundle,代码行数:43,代码来源:AnnotationDriver.php


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