Пример #1
0
 /**
  * @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;
 }
Пример #2
0
 /**
  * Loads bundle services into application's dependency injection container.
  *
  * @param Config        $config
  * @param callable|null $recipe
  */
 private function loadServices(Config $config, callable $recipe = null)
 {
     if (false === $this->runRecipe($config, $recipe)) {
         $directories = BundleConfigDirectory::getDirectories($this->application->getBaseRepository(), $this->application->getContext(), $this->application->getEnvironment(), basename(dirname($config->getBaseDir())));
         array_unshift($directories, $this->getConfigDirByBundleBaseDir(dirname($config->getBaseDir())));
         foreach ($directories as $directory) {
             $filepath = $directory . DIRECTORY_SEPARATOR . 'services.xml';
             if (is_file($filepath) && is_readable($filepath)) {
                 try {
                     ServiceLoader::loadServicesFromXmlFile($this->container, $directory);
                 } catch (\Exception $e) {
                     // nothing to do
                 }
             }
             $filepath = $directory . DIRECTORY_SEPARATOR . 'services.yml';
             if (is_file($filepath) && is_readable($filepath)) {
                 try {
                     ServiceLoader::loadServicesFromYamlFile($this->container, $directory);
                 } catch (\Exception $e) {
                     // nothing to do
                 }
             }
         }
     }
 }
Пример #3
0
 /**
  * Returns path to the right directory to dump and save config.yml file.
  *
  * @param string $baseDir config base directory
  *
  * @return string
  */
 private function getConfigDumpRightDirectory($baseDir)
 {
     $configDumpDir = $this->app->getBaseRepository();
     if ($this->persistPerContext && ApplicationInterface::DEFAULT_CONTEXT !== $this->app->getContext()) {
         $configDumpDir .= DIRECTORY_SEPARATOR . $this->app->getContext();
     }
     $configDumpDir .= DIRECTORY_SEPARATOR . 'Config';
     if ($this->persistPerEnvironment && ApplicationInterface::DEFAULT_ENVIRONMENT !== $this->app->getEnvironment()) {
         $configDumpDir .= DIRECTORY_SEPARATOR . $this->app->getEnvironment();
     }
     $key = $this->app->getContainer()->get('bundle.loader')->getBundleIdByBaseDir($baseDir);
     if (null !== $key) {
         $configDumpDir .= DIRECTORY_SEPARATOR . 'bundle' . DIRECTORY_SEPARATOR . $key;
     }
     if (!is_dir($configDumpDir) && false === @mkdir($configDumpDir, 0755, true)) {
         throw new \Exception('Unable to create config dump directory');
     }
     return $configDumpDir;
 }
 /**
  * Returns all classcontents classnames
  *
  * @return string[] An array that contains all classcontents classnames
  */
 public function getAllClassContentClassnames()
 {
     if (null === $this->contentClassnames) {
         $cacheId = md5('all_classcontents_classnames_' . $this->app->getContext() . '_' . $this->app->getEnvironment());
         if (!$this->app->isDebugMode() && false !== ($value = $this->cache->load($cacheId))) {
             $this->contentClassnames = json_decode($value, true);
         } else {
             $this->contentClassnames = [AbstractClassContent::CLASSCONTENT_BASE_NAMESPACE . 'ContentSet'];
             foreach ($this->app->getClassContentDir() as $directory) {
                 $this->contentClassnames = array_merge($this->contentClassnames, CategoryManager::getClassContentClassnamesFromDir($directory));
             }
             $this->cache->save($cacheId, json_encode($this->contentClassnames));
         }
     }
     return $this->contentClassnames;
 }
Пример #5
0
 /**
  * ContainerBuilder's constructor;.
  *
  * @param BackBee\ApplicationInterface $application the application we want to build a container for
  */
 public function __construct(ApplicationInterface $application)
 {
     $this->application = $application;
     $this->repository_directory = $application->getBaseRepository();
     $this->context = $application->getContext();
     $this->environment = $application->getEnvironment();
 }
Пример #6
0
 /**
  * Configurator's constructor.
  *
  * @param boolean $overrideConfig define if we should override config on extend()
  */
 public function __construct(ApplicationInterface $application, BundleLoader $bundleLoader)
 {
     $this->application = $application;
     $this->bundleLoader = $bundleLoader;
     $this->baseRepository = $application->getBaseRepository();
     $this->context = $application->getContext();
     $this->environment = $application->getEnvironment();
     $this->overrideConfig = $application->isOverridedConfig();
 }