本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::getIdentifier方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getIdentifier方法的具体用法?PHP ClassMetadata::getIdentifier怎么用?PHP ClassMetadata::getIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getIdentifier方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* @inheritdoc
*/
public function transform($value)
{
if (null === $value) {
return [];
}
$text = is_null($this->property) ? (string) $value : $this->propertyAccessor->getValue($value, $this->property);
$identifier = $this->propertyAccessor->getValue($value, $this->metadata->getIdentifier()[0]);
return [$identifier ?: $text => $text];
}
示例2: refresh
/**
* @param object $entity
* @return object
*/
public function refresh($entity)
{
$column = $this->metaData->getIdentifier()[0];
$queryResult = $this->em->createQueryBuilder()->select('*')->from($this->metaData->getTableName())->where($column . ' = :id')->setParameter('id', $entity->{$column})->execute()->fetch();
if (!$queryResult) {
throw new RuntimeException('Cannot refresh entity with ' . $column . ' = ' . $entity->{$column});
}
return $this->hydrate($entity, $queryResult);
}
示例3: execute
/**
* Insert one new record using the Entity class.
*/
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;
}
示例4: execute
/**
* Insert one new record using the Entity class.
*/
public function execute(ObjectManager $manager, $insertedEntities, $generateId = false)
{
$obj = $this->class->newInstance();
$this->fillColumns($obj, $insertedEntities);
$this->callMethods($obj, $insertedEntities);
if ($generateId) {
$ids = $this->class->getIdentifier();
for ($i = 0; $i < count($ids); $i++) {
// foreach ($idsName as $idName) {
$generateId = $this->generateId($obj, $ids[$i], $manager);
$this->class->reflFields[$ids[$i]]->setValue($obj, $generateId);
}
}
//echo "Wykonuję persist";
$manager->persist($obj);
$manager->flush($obj);
return $obj;
}
示例5: getIdentifier
/**
* @param ClassMetadata $metadata
*
* @return string
* @throws LogicException
*/
protected function getIdentifier(ClassMetadata $metadata)
{
if ($metadata->isIdentifierComposite) {
throw new \LogicException('Composite identifiers are not supported.');
}
return $metadata->getIdentifier()[0];
}