Merge branch '2.1'

* 2.1:
  [Routing] made it compatible with older PCRE version (pre 8)
  tiny refactoring for consistency
  fixed docblock return type
  Added HttpCache\Store::generateContentDigest() + changed visibility

Conflicts:
	src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php
	src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
	src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php
	src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php
	src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php
	src/Symfony/Component/Routing/Tests/RouteCompilerTest.php
This commit is contained in:
Fabien Potencier 2012-11-19 13:32:16 +01:00
commit cec11fa08a
7 changed files with 19 additions and 9 deletions

View File

@ -23,7 +23,7 @@ class ServerBag extends ParameterBag
/**
* Gets the HTTP headers.
*
* @return string
* @return array
*/
public function getHeaders()
{

View File

@ -24,7 +24,7 @@ use Symfony\Component\HttpFoundation\Response;
*/
class Store implements StoreInterface
{
private $root;
protected $root;
private $keyCache;
private $locks;
@ -164,7 +164,7 @@ class Store implements StoreInterface
// write the response body to the entity store if this is the original response
if (!$response->headers->has('X-Content-Digest')) {
$digest = 'en'.sha1($response->getContent());
$digest = $this->generateContentDigest($response);
if (false === $this->save($digest, $response->getContent())) {
throw new \RuntimeException('Unable to store the entity.');
@ -202,6 +202,18 @@ class Store implements StoreInterface
return $key;
}
/**
* Returns content digest for $response.
*
* @param Response $response
*
* @return string
*/
protected function generateContentDigest(Response $response)
{
return 'en'.sha1($response->getContent());
}
/**
* Invalidates all cache entries that match the request.
*

View File

@ -55,7 +55,6 @@ class ApacheMatcherDumper extends MatcherDumper
$hostnameRegex = $compiledRoute->getHostnameRegex();
if (null !== $hostnameRegex && $prevHostnameRegex !== $hostnameRegex) {
$prevHostnameRegex = $hostnameRegex;
$hostnameRegexUnique++;

View File

@ -288,7 +288,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
public function getResources()
{
$resources = $this->resources;
foreach ($this as $routes) {
foreach ($this->routes as $routes) {
if ($routes instanceof RouteCollection) {
$resources = array_merge($resources, $routes->getResources());
}

View File

@ -212,9 +212,9 @@ class RouteCompiler implements RouteCompilerInterface
// Variable tokens
if (0 === $index && 0 === $firstOptional) {
// When the only token is an optional variable token, the separator is required
return sprintf('%s(?<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
return sprintf('%s(?P<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
} else {
$regexp = sprintf('%s(?<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
$regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
if ($index >= $firstOptional) {
// Enclose each optional token in a subpattern to make it optional.
// "?:" means it is non-capturing, i.e. the portion of the subject string that

View File

@ -71,7 +71,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
if ($pathinfo === '/test/baz3/') {
return array('_route' => 'baz3');
}
}
// baz4

View File

@ -100,7 +100,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with an optional variable as the first segment with requirements',
array('/{bar}', array('bar' => 'bar'), array('bar' => '(foo|bar)')),
'', '#^/(?<bar>(foo|bar))?$#s', array('bar'), array(
'', '#^/(?P<bar>(foo|bar))?$#s', array('bar'), array(
array('variable', '/', '(foo|bar)', 'bar'),
)),