Merge branch '2.0'

* 2.0:
  [HttpKernel] fixed Content-Length header when using ESI tags (closes #2623)
  [HttpFoundation] added an exception to MimeTypeGuesser::guess() when no guesser are available (closes #2636)
  [Security] fixed HttpUtils::checkRequestPath() to not catch all exceptions (closes #2637)
  [DoctrineBundle] added missing default parameters, needed to setup and use DBAL without ORM
  [Transation] Fix grammar.
  [TwigBundle] Fix trace to not show 'in at line' when file/line are empty.
This commit is contained in:
Fabien Potencier 2011-11-14 14:32:22 +01:00
commit 1340ea67a6
8 changed files with 64 additions and 15 deletions

View File

@ -14,6 +14,8 @@
<parameter key="doctrine.dbal.events.mysql_session_init.class">Doctrine\DBAL\Event\Listeners\MysqlSessionInit</parameter>
<parameter key="doctrine.dbal.events.oracle_session_init.class">Doctrine\DBAL\Event\Listeners\OracleSessionInit</parameter>
<parameter key="doctrine.class">Symfony\Bundle\DoctrineBundle\Registry</parameter>
<parameter key="doctrine.entity_managers" type="collection"></parameter>
<parameter key="doctrine.default_entity_manager"></parameter>
</parameters>
<services>

View File

@ -5,10 +5,10 @@
{{ trace.type ~ trace.function }}
</strong>
({{ trace.args|format_args }})
<br />
{% endif %}
{% if trace.file is defined and trace.line is defined %}
{% if trace.file is defined and trace.file and trace.line is defined and trace.line %}
{{ trace.function ? '<br />' : '' }}
in {{ trace.file|format_file(trace.line) }}&nbsp;
{% spaceless %}
<a href="#" onclick="toggle('trace_{{ prefix ~ '_' ~ i }}'); switchIcons('icon_{{ prefix ~ '_' ~ i }}_open', 'icon_{{ prefix ~ '_' ~ i }}_close'); return false;">

View File

@ -106,16 +106,14 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface
throw new AccessDeniedException($path);
}
$mimeType = null;
foreach ($this->guessers as $guesser) {
$mimeType = $guesser->guess($path);
if (null !== $mimeType) {
break;
}
if (!$this->guessers) {
throw new \LogicException('Unable to guess the mime type as no guesser are available.');
}
return $mimeType;
foreach ($this->guessers as $guesser) {
if (null !== $mimeType = $guesser->guess($path)) {
return $mimeType;
}
}
}
}

View File

@ -585,6 +585,9 @@ class HttpCache implements HttpKernelInterface
$response->setContent(ob_get_clean());
$response->headers->remove('X-Body-Eval');
if (!$response->headers->has('Transfer-Encoding')) {
$response->headers->set('Content-Length', strlen($response->getContent()));
}
} elseif ($response->headers->has('X-Body-File')) {
$response->setContent(file_get_contents($response->headers->get('X-Body-File')));
} else {

View File

@ -16,6 +16,8 @@ use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
/**
* Encapsulates the logic needed to create sub-requests, redirect the user, and match URLs.
@ -108,7 +110,9 @@ class HttpUtils
$parameters = $this->router->match($request->getPathInfo());
return $path === $parameters['_route'];
} catch (\Exception $e) {
} catch (MethodNotAllowedException $e) {
return false;
} catch (ResourceNotFoundException $e) {
return false;
}
}

View File

@ -28,7 +28,7 @@ class MessageSelector
*
* The message supports two different types of pluralization rules:
*
* interval: {0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples
* interval: {0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples
* indexed: There is one apple|There is %count% apples
*
* The indexed solution can also contain labels (e.g. one: There is one apple).
@ -36,7 +36,7 @@ class MessageSelector
* affect the functionality.
*
* The two methods can also be mixed:
* {0} There is no apples|one: There is one apple|more: There is %count% apples
* {0} There are no apples|one: There is one apple|more: There are %count% apples
*
* @throws InvalidArgumentException
* @param string $message The message being translated

View File

@ -978,4 +978,30 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache'));
}
public function testEsiRecalculateContentLengthHeader()
{
$responses = array(
array(
'status' => 200,
'body' => '<esi:include src="/foo" />',
'headers' => array(
'Content-Length' => 26,
'Cache-Control' => 's-maxage=300',
'Surrogate-Control' => 'content="ESI/1.0"',
),
),
array(
'status' => 200,
'body' => 'Hello World!',
'headers' => array(),
),
);
$this->setNextResponses($responses);
$this->request('GET', '/', array(), array(), true);
$this->assertEquals('Hello World!', $this->response->getContent());
$this->assertEquals(12, $this->response->headers->get('Content-Length'));
}
}

View File

@ -14,6 +14,7 @@ namespace Symfony\Tests\Component\Security\Http;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\HttpUtils;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
class HttpUtilsTest extends \PHPUnit_Framework_TestCase
{
@ -91,7 +92,7 @@ class HttpUtilsTest extends \PHPUnit_Framework_TestCase
$router
->expects($this->any())
->method('match')
->will($this->returnValue(array()))
->will($this->throwException(new ResourceNotFoundException()))
;
$utils = new HttpUtils($router);
$this->assertFalse($utils->checkRequestPath($this->getRequest(), 'foobar'));
@ -106,6 +107,21 @@ class HttpUtilsTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($utils->checkRequestPath($this->getRequest('/foo/bar'), 'foobar'));
}
/**
* @expectedException \RuntimeException
*/
public function testCheckRequestPathWithRouterLoadingException()
{
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');
$router
->expects($this->any())
->method('match')
->will($this->throwException(new \RuntimeException()))
;
$utils = new HttpUtils($router);
$utils->checkRequestPath($this->getRequest(), 'foobar');
}
private function getRouter()
{
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');