/** * 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; }
/** * @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]); }
/** * 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; }