/**
  * @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);
 }
Esempio n. 2
0
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * @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;
 }
 /**
  * {@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;
 }
Esempio n. 6
0
 /**
  * @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;
 }
 /**
  * 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;
 }
Esempio n. 8
0
 /**
  * @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());
 }
 public function __construct(MaterializedPathManager $hm, ClassMetadata $meta)
 {
     $this->hm = $hm;
     $this->classMetadata = $meta;
     $this->prototype = $meta->newInstance();
 }
Esempio n. 10
0
 /** {@inheritdoc} */
 public function newInstance()
 {
     return $this->classMetadata->newInstance();
 }
 /**
  * __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();
 }
Esempio n. 12
0
 /**
  * @group DDC-3120
  */
 public function testCanInstantiateInternalPhpClassSubclass()
 {
     $classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');
     $this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
 }
Esempio n. 13
0
 /**
  * Return a new instance of the record for this form
  * @return mixed
  */
 public function getNewRecord()
 {
     return $this->metadata->newInstance();
 }