/** * @param EntityManager $entityManager * @throws \Doctrine\ORM\ORMInvalidArgumentException * @throws \Doctrine\ORM\OptimisticLockException */ public function load(EntityManager $entityManager) { $faker = Factory::create(); $count = 10; for ($i = 0; $i < $count; $i++) { $setting = new Setting(); $setting->setName($faker->unique()->word); $setting->setValue($faker->word); $entityManager->persist($setting); } $entityManager->flush(); }
/** * @param string $name * @param mixed $value string, int, boolean, object, ... * @param int $owner * @param null|string $group * @return $this * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\ORMInvalidArgumentException */ public function set($name, $value, $owner = null, $group = null) { try { $item = $this->get($name, $owner, $group); } catch (PropertyNotExistsException $ex) { $item = null; } $nname = null !== $owner ? $name . '_' . $owner : $name; if (null !== $item || !(array_key_exists($name, $this->defaults) && $this->defaults[$name] === $item)) { $setting = $this->em->getRepository('SettingsBundle:Setting')->findOneBy(['name' => $nname, 'ownerId' => $owner, 'group' => $group]); if (null === $setting) { $setting = new Setting(); } } else { $setting = new Setting(); } $setting->setName($nname); $setting->setValue($value); $setting->setOwnerId($owner); $setting->setGroup($group); $this->em->persist($setting); $this->em->flush($setting); if ($this->cacheProvider) { $this->cacheProvider->save($nname, serialize($setting)); } return $this; }