/** * @see BackBee\Config\Persistor\PersistorInterface::persist */ public function persist(Config $config, array $configToPersist) { if (array_key_exists('override_site', $configToPersist)) { $configToPersist = array('override_site' => $configToPersist['override_site']); } $baseScope = 'BUNDLE_CONFIG.'; $key = $this->app->getContainer()->get('bundle.loader')->getBundleIdByBaseDir($config->getBaseDir()); if (null === $key) { $key = $application; $baseScope = 'APPLICATION_CONFIG.'; } $scope = $baseScope . $this->app->getContext() . '.' . $this->app->getEnvironment(); $registry = $this->app->getEntityManager()->getRepository('BackBee\\Bundle\\Registry')->findOneBy(array('key' => $key, 'scope' => $scope)); if (null === $registry) { $registry = new RegistryEntity(); $registry->setKey($key); $registry->setScope($scope); $this->app->getEntityManager()->persist($registry); } $registry->setValue(serialize($configToPersist)); $success = true; try { $this->app->getEntityManager()->flush($registry); } catch (\Exception $e) { $success = false; } return $success; }
/** * Returns a Registry entry for $nonce. * * @param string $nonce * * @return \BackBee\Bundle\Registry */ private function getRegistry($nonce) { if (null === ($registry = $this->registryRepository->findOneBy(['key' => $nonce, 'scope' => 'SECURITY.NONCE']))) { $registry = new Registry(); $registry->setKey($nonce)->setScope('SECURITY.NONCE'); } return $registry; }
/** * Selects and save the theme to use for the given site. If site argument * is omitted, it will define the default theme to use. * * @param string $name * @param Site|null $site * @return array */ public function selectTheme($name, Site $site = null) { if (!isset($this->settings['options']) || !is_array($this->settings['options']) || !array_key_exists($name, $this->settings['options'])) { throw new \LogicException("Cannot select `{$name}` theme because it does not exist."); } $registry = $this->getThemeRegistry($site); if (null === $registry || null !== $site && null !== $registry && 'default' === $registry->getKey()) { $registry = new Registry(); $registry->setKey($site ? $site->getLabel() : 'default'); $registry->setType('selected_theme'); $registry->setScope('THEME_CONFIG'); $this->app->getEntityManager()->persist($registry); } $registry->setValue($name); $this->app->getEntityManager()->flush($registry); return $this; }
/** * Automatique registry builder from the current entity object. */ private function buildRegistryFromObject() { if (!$this->entity instanceof DomainObjectInterface) { throw new \Exception('EntityRegistry have to implement DomainObjectInterface', 1); } $this->classname = get_class($this->entity); $identifier = new Registry(); $this->registries[] = $identifier->setType($this->classname)->setKey('identifier')->setValue($this->entity->getObjectIdentifier()); foreach ($this->entity->getObjectProperties() as $key => $value) { $registry = new Registry(); $this->registries[] = $registry->setType($this->classname)->setKey($key)->setValue($value)->setScope($this->entity->getObjectIdentifier()); } }