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


PHP ClassMetadata::getIdentifierValues方法代码示例

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


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

示例1: getEntityId

 /**
  * @param  object                    $entity
  * @return int
  * @throws \InvalidArgumentException
  */
 public function getEntityId($entity)
 {
     $className = $this->class;
     if (!$entity instanceof $className) {
         throw new \InvalidArgumentException('Expected instance of ' . $this->class);
     }
     $idFields = $this->metadata->getIdentifierFieldNames();
     $idField = current($idFields);
     $entityIds = $this->metadata->getIdentifierValues($entity);
     return $entityIds[$idField];
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:16,代码来源:ApiEntityManager.php

示例2: getIdentifierValues

 /**
  * Returns the values of the identifier fields of an entity.
  *
  * Doctrine must know about this entity, that is, the entity must already
  * be persisted or added to the identity map before. Otherwise an
  * exception is thrown.
  *
  * @param  object $entity The entity for which to get the identifier
  *
  * @return array          The identifier values
  *
  * @throws FormException  If the entity does not exist in Doctrine's identity map
  */
 public function getIdentifierValues($entity)
 {
     if (!$this->em->contains($entity)) {
         throw new FormException('Entities passed to the choice field must be managed');
     }
     return $this->classMetadata->getIdentifierValues($entity);
 }
开发者ID:usefulthink,项目名称:symfony,代码行数:20,代码来源:EntityChoiceList.php

示例3: getIdentifierValues

 /**
  * Returns the values of the identifier fields of an entity.
  *
  * Doctrine must know about this entity, that is, the entity must already
  * be persisted or added to the identity map before. Otherwise an
  * exception is thrown.
  *
  * @param object $entity The entity for which to get the identifier
  *
  * @return array          The identifier values
  *
  * @throws Exception If the entity does not exist in Doctrine's identity map
  */
 private function getIdentifierValues($entity)
 {
     if (!$this->em->contains($entity)) {
         throw new Exception('Entities passed to the choice field must be managed. Maybe ' . 'persist them in the entity manager?');
     }
     $this->em->initializeObject($entity);
     return $this->classMetadata->getIdentifierValues($entity);
 }
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:21,代码来源:EntityChoiceList.php

示例4: getIdValue

 /**
  * Returns the ID value for an object.
  *
  * This method assumes that the object has a single-column ID.
  *
  * @param object $object The object.
  *
  * @return mixed The ID value.
  */
 public function getIdValue($object)
 {
     if (!$object) {
         return;
     }
     if (!$this->om->contains($object)) {
         throw new RuntimeException('Entities passed to the choice field must be managed. Maybe ' . 'persist them in the entity manager?');
     }
     $this->om->initializeObject($object);
     return current($this->classMetadata->getIdentifierValues($object));
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:20,代码来源:IdReader.php

示例5: toMany

 /**
  * @param mixed $valueOrObject
  * @param       $target
  * @return array
  */
 protected function toMany($valueOrObject, $target)
 {
     if (!is_array($valueOrObject)) {
         $valueOrObject = (array) $valueOrObject;
     }
     $values = array();
     foreach ($valueOrObject as $value) {
         if (is_numeric($value)) {
             $values[] = $this->objectManager->find($target, $value);
             continue;
         }
         $identifiers = $this->metadata->getIdentifierValues($valueOrObject);
         $values[] = $this->objectManager->find($target, $identifiers);
     }
     return $values;
 }
开发者ID:ashimidashajia,项目名称:zendstore,代码行数:21,代码来源:DoctrineEntity.php

示例6: createCloner

 /**
  * Creates a closure capable of finalizing state a cloned proxy
  *
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata
  * @param \Doctrine\ORM\Persisters\BasicEntityPersister      $entityPersister
  *
  * @return \Closure
  *
  * @throws \Doctrine\ORM\EntityNotFoundException
  */
 private function createCloner(ClassMetadata $classMetadata, BasicEntityPersister $entityPersister)
 {
     return function (BaseProxy $proxy) use($entityPersister, $classMetadata) {
         if ($proxy->__isInitialized()) {
             return;
         }
         $proxy->__setInitialized(true);
         $proxy->__setInitializer(null);
         $class = $entityPersister->getClassMetadata();
         $original = $entityPersister->load($classMetadata->getIdentifierValues($proxy));
         if (null === $original) {
             throw new EntityNotFoundException();
         }
         foreach ($class->getReflectionClass()->getProperties() as $reflectionProperty) {
             $propertyName = $reflectionProperty->getName();
             if ($class->hasField($propertyName) || $class->hasAssociation($propertyName)) {
                 $reflectionProperty->setAccessible(true);
                 $reflectionProperty->setValue($proxy, $reflectionProperty->getValue($original));
             }
         }
     };
 }
开发者ID:6975usa,项目名称:doctrine,代码行数:32,代码来源:ProxyFactory.php

示例7: createCloner

 /**
  * Creates a closure capable of finalizing state a cloned proxy
  *
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata
  * @param \Doctrine\ORM\Persisters\Entity\EntityPersister    $entityPersister
  *
  * @return \Closure
  *
  * @throws \Doctrine\ORM\EntityNotFoundException
  */
 private function createCloner(ClassMetadata $classMetadata, EntityPersister $entityPersister)
 {
     return function (BaseProxy $proxy) use($entityPersister, $classMetadata) {
         if ($proxy->__isInitialized()) {
             return;
         }
         $proxy->__setInitialized(true);
         $proxy->__setInitializer(null);
         $class = $entityPersister->getClassMetadata();
         $identifier = $classMetadata->getIdentifierValues($proxy);
         $original = $entityPersister->loadById($identifier);
         if (null === $original) {
             throw EntityNotFoundException::fromClassNameAndIdentifier($classMetadata->getName(), $this->identifierFlattener->flattenIdentifier($classMetadata, $identifier));
         }
         foreach ($class->getReflectionClass()->getProperties() as $property) {
             if (!$class->hasField($property->name) && !$class->hasAssociation($property->name)) {
                 continue;
             }
             $property->setAccessible(true);
             $property->setValue($proxy, $property->getValue($original));
         }
     };
 }
开发者ID:aschempp,项目名称:doctrine2,代码行数:33,代码来源:ProxyFactory.php

示例8: modelName

 /**
  * {@inheritdoc}
  */
 public function modelName($model, ClassMetadata $metadata)
 {
     $identifiers = $metadata->getIdentifierValues($model);
     $className = lcfirst(ClassUtils::getClassName($metadata->getName()));
     return $className . implode('_', $identifiers);
 }
开发者ID:ibasaw,项目名称:fixture-dumper,代码行数:9,代码来源:DefaultNamingStrategy.php

示例9: fromInvalidReference

 /**
  * @param ClassMetadata $metadata
  * @param object        $object
  *
  * @return MissingBatchItemException
  */
 public static function fromInvalidReference(ClassMetadata $metadata, $object)
 {
     return new self(sprintf('Requested batch item %s#%s (of type %s) with identifier "%s" could not be found', get_class($object), spl_object_hash($object), $metadata->getName(), json_encode($metadata->getIdentifierValues($object))));
 }
开发者ID:Ocramius,项目名称:DoctrineBatchUtils,代码行数:10,代码来源:MissingBatchItemException.php


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