[ticket/13829] Don't fail if the cache isn't writeable

PHPBB3-13829
This commit is contained in:
Nicofuma 2015-05-10 19:18:10 +02:00
parent 11167f6060
commit d48e95bb3a

View file

@ -14,6 +14,7 @@
namespace phpbb\routing; namespace phpbb\routing;
use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper;
use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\Matcher\UrlMatcher;
@ -249,22 +250,29 @@ class router implements RouterInterface
*/ */
protected function create_dumped_url_matcher() protected function create_dumped_url_matcher()
{ {
$cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_matcher.{$this->php_ext}", defined('DEBUG')); try
if (!$cache->isFresh())
{ {
$dumper = new PhpMatcherDumper($this->get_routes()); $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_matcher.{$this->php_ext}", defined('DEBUG'));
if (!$cache->isFresh())
{
$dumper = new PhpMatcherDumper($this->get_routes());
$options = array( $options = array(
'class' => 'phpbb_url_matcher', 'class' => 'phpbb_url_matcher',
'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', 'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
); );
$cache->write($dumper->dump($options), $this->get_routes()->getResources()); $cache->write($dumper->dump($options), $this->get_routes()->getResources());
}
require_once($cache->getPath());
$this->matcher = new \phpbb_url_matcher($this->context);
}
catch (IOException $e)
{
$this->create_new_url_matcher();
} }
require_once($cache->getPath());
$this->matcher = new \phpbb_url_matcher($this->context);
} }
/** /**
@ -297,22 +305,29 @@ class router implements RouterInterface
*/ */
protected function create_dumped_url_generator() protected function create_dumped_url_generator()
{ {
$cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_generator.{$this->php_ext}", defined('DEBUG')); try
if (!$cache->isFresh())
{ {
$dumper = new PhpGeneratorDumper($this->get_routes()); $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_generator.{$this->php_ext}", defined('DEBUG'));
if (!$cache->isFresh())
{
$dumper = new PhpGeneratorDumper($this->get_routes());
$options = array( $options = array(
'class' => 'phpbb_url_generator', 'class' => 'phpbb_url_generator',
'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', 'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
); );
$cache->write($dumper->dump($options), $this->get_routes()->getResources()); $cache->write($dumper->dump($options), $this->get_routes()->getResources());
}
require_once($cache->getPath());
$this->generator = new \phpbb_url_generator($this->context);
}
catch (IOException $e)
{
$this->create_new_url_generator();
} }
require_once($cache->getPath());
$this->generator = new \phpbb_url_generator($this->context);
} }
/** /**