本文整理汇总了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];
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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));
}
}
};
}
示例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));
}
};
}
示例8: modelName
/**
* {@inheritdoc}
*/
public function modelName($model, ClassMetadata $metadata)
{
$identifiers = $metadata->getIdentifierValues($model);
$className = lcfirst(ClassUtils::getClassName($metadata->getName()));
return $className . implode('_', $identifiers);
}
示例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))));
}