本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::newInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::newInstance方法的具体用法?PHP ClassMetadata::newInstance怎么用?PHP ClassMetadata::newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::newInstance方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reverseTransform
/**
* @inheritdoc
*/
public function reverseTransform($value)
{
if (is_null($value)) {
return null;
}
if (!is_numeric($value) && $this->tags && $this->property) {
$object = $this->metadata->newInstance();
$this->propertyAccessor->setValue($object, $this->property, $value);
return $object;
}
return $this->em->getRepository($this->class)->find($value);
}
示例2: 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;
}
示例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) {
$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;
}
示例4: getResult
/**
* @param ClassMetadata $classMetadata
* @param array $options
* @return bool
* @throws \InvalidArgumentException
*/
public function getResult(ClassMetadata $classMetadata, array $options = [])
{
if (!isset($options['property'])) {
throw new \InvalidArgumentException('The property option must be specified!');
}
if (!$this->propertyAccessor->isReadable($classMetadata->newInstance(), $options['property'])) {
return false;
}
if ($annotation = $this->annotationQuery->getResult($classMetadata, ['property' => $options['property'], 'annotationClass' => 'Sentient\\Data\\Metadata\\Annotation\\InvisibleProperty', 'checkSetter' => false])) {
return false;
}
if ($annotation = $this->annotationQuery->getResult($classMetadata, ['property' => $options['property'], 'annotationClass' => 'Sentient\\Data\\Metadata\\Annotation\\CrudProperty', 'checkSetter' => false])) {
if (!empty($options['important'])) {
return !empty($annotation->important);
}
return !empty($annotation->visible);
}
return true;
}
示例5: getResult
/**
* {@inheritdoc}
*/
public function getResult(ClassMetadata $classMetadata, array $options = [])
{
if (!isset($options['property'])) {
throw new \InvalidArgumentException('The property option was not specified.');
}
$instance = $classMetadata->newInstance();
if (!$this->propertyAccessor->isWritable($instance, $options['property']) || !$this->propertyAccessor->isReadable($instance, $options['property'])) {
return false;
}
if (isset($options['create'])) {
$create = $options['create'];
unset($options['create']);
} else {
$create = true;
}
if ($annotation = $this->annotationQuery->getResult($classMetadata, array_merge($options, ['annotationClass' => 'Sentient\\Data\\Metadata\\Annotation\\LockedProperty']))) {
if ($create ? $annotation->onCreate : $annotation->onUpdate) {
return false;
}
}
if ($annotation = $this->annotationQuery->getResult($classMetadata, array_merge($options, ['annotationClass' => 'Sentient\\Data\\Metadata\\Annotation\\CrudProperty']))) {
if ($annotation->editable === CrudProperty::EDITABLE_ALWAYS) {
return true;
}
if ($annotation->editable === CrudProperty::EDITABLE_NEVER) {
return false;
}
if ($annotation->editable === CrudProperty::EDITABLE_ON_CREATE) {
return $create;
}
if ($annotation->editable === CrudProperty::EDITABLE_ON_UPDATE) {
return !$create;
}
throw new \RuntimeException('The editable property has an invalid value.');
}
foreach ($this->bannedAnnotations as $annotationClass) {
if ($this->annotationQuery->getResult($classMetadata, array_merge($options, compact('annotationClass')))) {
return false;
}
}
return true;
}
示例6: newInstance
/**
* @param ClassMetadata $class
*
* @return \Doctrine\Common\Persistence\ObjectManagerAware|object
*/
private function newInstance($class)
{
$entity = $class->newInstance();
if ($entity instanceof \Doctrine\Common\Persistence\ObjectManagerAware) {
$entity->injectObjectManager($this->em, $class);
}
return $entity;
}
示例7: isTranslation
/**
* Checks if entity is a translation
*
* @param ClassMetadata $classMetadata
* @return boolean
*/
private function isTranslation(ClassMetadata $classMetadata)
{
if ($classMetadata->getReflectionClass()->isInstantiable()) {
return $classMetadata->newInstance() instanceof TranslationInterface;
}
return false;
}
示例8: testCanInstantiateInternalPhpClassSubclass
/**
* @group DDC-3120
*/
public function testCanInstantiateInternalPhpClassSubclass()
{
$classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');
$classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
}
示例9: __construct
public function __construct(MaterializedPathManager $hm, ClassMetadata $meta)
{
$this->hm = $hm;
$this->classMetadata = $meta;
$this->prototype = $meta->newInstance();
}
开发者ID:parker4444,项目名称:Doctrine2-Hierarchical-Structural-Behavior,代码行数:6,代码来源:MaterializedPathQueryFactory.php
示例10: newInstance
/** {@inheritdoc} */
public function newInstance()
{
return $this->classMetadata->newInstance();
}
示例11: __construct
/**
* __construct
*
* @param Doctrine\ORM\EntityManager $em
* @param Doctrine\ORM\Mapping\ClassMetadata $meta
* @return void
*/
public function __construct(EntityManager $em, ClassMetadata $meta)
{
$this->em = $em;
$this->classMetadata = $meta;
$this->prototype = $meta->newInstance();
}
示例12: testCanInstantiateInternalPhpClassSubclass
/**
* @group DDC-3120
*/
public function testCanInstantiateInternalPhpClassSubclass()
{
$classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
}