本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::newInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::newInstance方法的具体用法?PHP ClassMetadata::newInstance怎么用?PHP ClassMetadata::newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::newInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Insert one new record using the Entity class.
*/
public function execute($manager, $insertedEntities)
{
$obj = $this->class->newInstance();
foreach ($this->columnFormatters as $field => $format) {
if (null !== $format) {
$value = is_callable($format) ? $format($insertedEntities, $obj) : $format;
$this->class->reflFields[$field]->setValue($obj, $value);
}
}
$manager->persist($obj);
return $obj;
}
示例2: 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]);
}
示例3: 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;
}