Esempio n. 1
0
 /**
  * Set path component
  *
  * @param string $path Path component
  * @param boolean $urlencode If true, parts of path should be encoded with rawurlencode()
  */
 public function set_path($path, $urlencode = false)
 {
     // Since 1.7.0 Twig returns the real path of the file. We need it to be relative.
     $real_root_path = $this->filesystem->realpath($this->path_helper->get_phpbb_root_path()) . DIRECTORY_SEPARATOR;
     // If the asset is under the phpBB root path we need to remove its path and then prepend $phpbb_root_path
     if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path) {
         $path = $this->path_helper->get_phpbb_root_path() . str_replace('\\', '/', substr($path, strlen($real_root_path)));
     } else {
         // Else we make the path relative to the current working directory
         $real_root_path = $this->filesystem->realpath('.') . DIRECTORY_SEPARATOR;
         if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path) {
             $path = str_replace('\\', '/', substr($path, strlen($real_root_path)));
         }
     }
     if ($urlencode) {
         $paths = explode('/', $path);
         foreach ($paths as &$dir) {
             $dir = rawurlencode($dir);
         }
         $path = implode('/', $paths);
     }
     $this->components['path'] = $path;
 }
Esempio n. 2
0
 /**
  * Build and return a new Container respecting the current configuration
  *
  * @return \phpbb_cache_container|ContainerBuilder
  */
 public function get_container()
 {
     $container_filename = $this->get_container_filename();
     $config_cache = new ConfigCache($container_filename, defined('DEBUG'));
     if ($this->use_cache && $config_cache->isFresh()) {
         require $config_cache->getPath();
         $this->container = new \phpbb_cache_container();
     } else {
         $this->container_extensions = array(new extension\core($this->get_config_path()));
         if ($this->use_extensions) {
             $this->load_extensions();
         }
         // Inject the config
         if ($this->config_php_file) {
             $this->container_extensions[] = new extension\config($this->config_php_file);
         }
         $this->container = $this->create_container($this->container_extensions);
         // Easy collections through tags
         $this->container->addCompilerPass(new pass\collection_pass());
         // Event listeners "phpBB style"
         $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener'));
         // Event listeners "Symfony style"
         $this->container->addCompilerPass(new RegisterListenersPass('dispatcher'));
         $filesystem = new filesystem();
         $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path())));
         $loader->load($this->container->getParameter('core.environment') . '/config.yml');
         $this->inject_custom_parameters();
         if ($this->compile_container) {
             $this->container->compile();
             if ($this->use_cache) {
                 $this->dump_container($config_cache);
             }
         }
     }
     if ($this->compile_container && $this->config_php_file) {
         $this->container->set('config.php', $this->config_php_file);
     }
     return $this->container;
 }
Esempio n. 3
0
 /**
  * Build and return a new Container respecting the current configuration
  *
  * @return \phpbb_cache_container|ContainerBuilder
  */
 public function get_container()
 {
     try {
         $container_filename = $this->get_container_filename();
         $config_cache = new ConfigCache($container_filename, defined('DEBUG'));
         if ($this->use_cache && $config_cache->isFresh()) {
             if ($this->use_extensions) {
                 require $this->get_autoload_filename();
             }
             require $config_cache->getPath();
             $this->container = new \phpbb_cache_container();
         } else {
             $this->container_extensions = array(new extension\core($this->get_config_path()));
             if ($this->use_extensions) {
                 $this->load_extensions();
             }
             // Inject the config
             if ($this->config_php_file) {
                 $this->container_extensions[] = new extension\config($this->config_php_file);
             }
             $this->container = $this->create_container($this->container_extensions);
             // Easy collections through tags
             $this->container->addCompilerPass(new pass\collection_pass());
             // Event listeners "phpBB style"
             $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener'));
             // Event listeners "Symfony style"
             $this->container->addCompilerPass(new RegisterListenersPass('dispatcher'));
             if ($this->use_extensions) {
                 $this->register_ext_compiler_pass();
             }
             $filesystem = new filesystem();
             $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path())));
             $loader->load($this->container->getParameter('core.environment') . '/config.yml');
             $this->inject_custom_parameters();
             if ($this->compile_container) {
                 $this->container->compile();
                 if ($this->use_cache) {
                     $this->dump_container($config_cache);
                 }
             }
         }
         if ($this->compile_container && $this->config_php_file) {
             $this->container->set('config.php', $this->config_php_file);
         }
         return $this->container;
     } catch (\Exception $e) {
         // Don't try to recover if we are in the development environment
         if ($this->get_environment() === 'development') {
             throw $e;
         }
         if ($this->build_exception === null) {
             $this->build_exception = $e;
             return $this->without_extensions()->without_cache()->with_custom_parameters(array_merge($this->custom_parameters, ['container_exception' => $e]))->get_container();
         } else {
             // Rethrow the original exception if it's still failing
             throw $this->build_exception;
         }
     }
 }