diff options
| -rw-r--r-- | phpBB/config/default/services_twig.yml | 2 | ||||
| -rw-r--r-- | phpBB/includes/functions_url_matcher.php | 33 | ||||
| -rw-r--r-- | phpBB/phpbb/cache/driver/file.php | 7 | ||||
| -rw-r--r-- | phpBB/phpbb/di/container_builder.php | 68 | 
4 files changed, 69 insertions, 41 deletions
| diff --git a/phpBB/config/default/services_twig.yml b/phpBB/config/default/services_twig.yml index 0745d8b47e..06ce5bc15c 100644 --- a/phpBB/config/default/services_twig.yml +++ b/phpBB/config/default/services_twig.yml @@ -1,5 +1,5 @@  parameters: -    core.template.cache_path: %core.root_path%cache/twig/ +    core.template.cache_path: %core.root_path%cache/%environment%/twig/  services:      template.twig.environment: diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php index 3bbc1cc924..c06f4f6cb1 100644 --- a/phpBB/includes/functions_url_matcher.php +++ b/phpBB/includes/functions_url_matcher.php @@ -11,6 +11,7 @@  *  */ +use Symfony\Component\Config\ConfigCache;  use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;  use Symfony\Component\Routing\Matcher\UrlMatcher;  use Symfony\Component\Routing\RequestContext; @@ -34,14 +35,10 @@ if (!defined('IN_PHPBB'))  */  function phpbb_get_url_matcher(\phpbb\extension\manager $manager, RequestContext $context, $root_path, $php_ext)  { -	if (defined('DEBUG')) +	$config_cache = new ConfigCache($root_path . 'cache/' . PHPBB_ENVIRONMENT . '/url_matcher.' . $php_ext, defined('DEBUG')); +	if (!$config_cache->isFresh())  	{ -		return phpbb_create_url_matcher($manager, $context, $root_path); -	} - -	if (!phpbb_url_matcher_dumped($root_path, $php_ext)) -	{ -		phpbb_create_dumped_url_matcher($manager, $root_path, $php_ext); +		phpbb_create_dumped_url_matcher($manager, $root_path, $config_cache);  	}  	return phpbb_load_url_matcher($context, $root_path, $php_ext); @@ -52,10 +49,10 @@ function phpbb_get_url_matcher(\phpbb\extension\manager $manager, RequestContext  *  * @param \phpbb\extension\manager $manager Extension manager  * @param string $root_path Root path -* @param string $php_ext PHP file extension + * @param ConfigCache $config_cache The config cache  * @return null  */ -function phpbb_create_dumped_url_matcher(\phpbb\extension\manager $manager, $root_path, $php_ext) +function phpbb_create_dumped_url_matcher(\phpbb\extension\manager $manager, $root_path, $config_cache)  {  	$provider = new \phpbb\controller\provider($root_path);  	$provider->find_routing_files($manager->all_enabled()); @@ -65,7 +62,7 @@ function phpbb_create_dumped_url_matcher(\phpbb\extension\manager $manager, $roo  		'class'			=> 'phpbb_url_matcher',  	)); -	file_put_contents($root_path . 'cache/url_matcher.' . $php_ext, $cached_url_matcher_dump); +	$config_cache->write($cached_url_matcher_dump, $routes->getResources());  }  /** @@ -93,20 +90,6 @@ function phpbb_create_url_matcher(\phpbb\extension\manager $manager, RequestCont  */  function phpbb_load_url_matcher(RequestContext $context, $root_path, $php_ext)  { -	require($root_path . 'cache/url_matcher.' . $php_ext); +	require($root_path . 'cache/' . PHPBB_ENVIRONMENT . '/url_matcher.' . $php_ext);  	return new phpbb_url_matcher($context);  } - -/** -* Determine whether we have our dumped URL matcher -* -* The class is automatically dumped to the cache directory -* -* @param string $root_path Root path -* @param string $php_ext PHP file extension -* @return bool True if it exists, false if not -*/ -function phpbb_url_matcher_dumped($root_path, $php_ext) -{ -	return file_exists($root_path . 'cache/url_matcher.' . $php_ext); -} diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index adfe87b740..d3708fe9a0 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -28,7 +28,12 @@ class file extends \phpbb\cache\driver\base  	function __construct($cache_dir = null)  	{  		global $phpbb_root_path; -		$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/'; +		$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/'; + +		if (!is_dir($this->cache_dir)) +		{ +			@mkdir($this->cache_dir, 0777, true); +		}  	}  	/** diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 638c13e86d..b264b0182f 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -13,16 +13,21 @@  namespace phpbb\di; +use Symfony\Component\Config\ConfigCache;  use Symfony\Component\DependencyInjection\ContainerBuilder;  use Symfony\Component\DependencyInjection\Dumper\PhpDumper;  use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass;  class container_builder  { -	/** @var string phpBB Root Path */ +	/** +	 * @var string phpBB Root Path +	 */  	protected $phpbb_root_path; -	/** @var string php file extension  */ +	/** +	 * @var string php file extension +	 */  	protected $php_ext;  	/** @@ -112,6 +117,11 @@ class container_builder  	protected $config_php_file;  	/** +	 * @var string +	 */ +	protected $cache_dir; + +	/**  	* Constructor  	*  	* @param \phpbb\config_php_file $config_php_file @@ -133,18 +143,16 @@ class container_builder  	public function get_container()  	{  		$container_filename = $this->get_container_filename(); -		if (!defined('DEBUG_CONTAINER') && $this->dump_container && file_exists($container_filename)) +		$config_cache = new ConfigCache($container_filename, defined('DEBUG')); +		if ($this->dump_container && $config_cache->isFresh())  		{  			require($container_filename);  			$this->container = new \phpbb_cache_container();  		}  		else  		{ -			if ($this->config_path === null) -			{ -				$this->config_path = $this->phpbb_root_path . 'config'; -			} -			$container_extensions = array(new \phpbb\di\extension\core($this->config_path)); + +			$container_extensions = array(new \phpbb\di\extension\core($this->get_config_path()));  			if ($this->use_extensions)  			{ @@ -178,9 +186,9 @@ class container_builder  				$this->container->compile();  			} -			if ($this->dump_container && !defined('DEBUG_CONTAINER')) +			if ($this->dump_container)  			{ -				$this->dump_container($container_filename); +				$this->dump_container($config_cache);  			}  		} @@ -267,6 +275,16 @@ class container_builder  	}  	/** +	 * Returns the path to the container configuration (default: root_path/config) +	 * +	 * @return string +	 */ +	protected function get_config_path() +	{ +		return $this->config_path ?: $this->phpbb_root_path . 'config'; +	} + +	/**  	* Set custom parameters to inject into the container.  	*  	* @param array $custom_parameters @@ -277,11 +295,31 @@ class container_builder  	}  	/** +	 * Set the path to the cache directory. +	 * +	 * @param string $cache_dir Path to the cache directory +	 */ +	public function set_cache_dir($cache_dir) +	{ +		$this->cache_dir = $cache_dir; +	} + +	/** +	 * Returns the path to the cache directory (default: root_path/cache/environment). +	 * +	 * @return string Path to the cache directory. +	 */ +	protected function get_cache_dir() +	{ +		return $this->cache_dir ?: $this->phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/'; +	} + +	/**  	* Dump the container to the disk.  	* -	* @param string $container_filename The name of the file. +	* @param ConfigCache $cache The config cache  	*/ -	protected function dump_container($container_filename) +	protected function dump_container($cache)  	{  		$dumper = new PhpDumper($this->container);  		$cached_container_dump = $dumper->dump(array( @@ -289,7 +327,7 @@ class container_builder  			'base_class'    => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder',  		)); -		file_put_contents($container_filename, $cached_container_dump); +		$cache->write($cached_container_dump, $this->container->getResources());  	}  	/** @@ -386,6 +424,8 @@ class container_builder  			);  		} +		$this->custom_parameters['environment'] = PHPBB_ENVIRONMENT; +  		foreach ($this->custom_parameters as $key => $value)  		{  			$this->container->setParameter($key, $value); @@ -400,6 +440,6 @@ class container_builder  	protected function get_container_filename()  	{  		$filename = str_replace(array('/', '.'), array('slash', 'dot'), $this->phpbb_root_path); -		return $this->phpbb_root_path . 'cache/container_' . $filename . '.' . $this->php_ext; +		return $this->get_cache_dir() . 'container_' . $filename . '.' . $this->php_ext;  	}  } | 
