Merge branch '2.8' into 3.3

* 2.8:
  [Routing] Fix resource miss
  [Security] Fixed auth provider authenticate() cannot return void
  declare argument type
  streamed response should return $this
  content can be a resource
  Adding the Form default theme files to be warmed up in Twig's cache
This commit is contained in:
Fabien Potencier 2017-10-20 11:30:21 -07:00
commit 402246ebaa
16 changed files with 70 additions and 17 deletions

View File

@ -46,7 +46,14 @@ class ExtensionPass implements CompilerPassInterface
if ($container->has('form.extension')) {
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
$coreThemePath = dirname(dirname($reflClass->getFileName())).'/Resources/views/Form';
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array($coreThemePath));
$paths = $container->getDefinition('twig.cache_warmer')->getArgument(2);
$paths[$coreThemePath] = null;
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $paths);
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $paths);
}
if ($container->has('translator')) {

View File

@ -100,6 +100,7 @@ class TwigExtension extends Extension
}
}
// paths are modified in ExtensionPass if forms are enabled
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $config['paths']);
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $config['paths']);

View File

@ -153,7 +153,7 @@ class AcceptHeader
private function sort()
{
if (!$this->sorted) {
uasort($this->items, function ($a, $b) {
uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) {
$qA = $a->getQuality();
$qB = $b->getQuality();

View File

@ -144,7 +144,7 @@ class Request
public $headers;
/**
* @var string
* @var string|resource
*/
protected $content;

View File

@ -78,12 +78,12 @@ class StreamedResponse extends Response
public function sendHeaders()
{
if ($this->headersSent) {
return;
return $this;
}
$this->headersSent = true;
parent::sendHeaders();
return parent::sendHeaders();
}
/**
@ -94,7 +94,7 @@ class StreamedResponse extends Response
public function sendContent()
{
if ($this->streamed) {
return;
return $this;
}
$this->streamed = true;
@ -104,6 +104,8 @@ class StreamedResponse extends Response
}
call_user_func($this->callback);
return $this;
}
/**

View File

@ -112,4 +112,15 @@ class StreamedResponseTest extends TestCase
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
$this->assertEquals(204, $response->getStatusCode());
}
public function testReturnThis()
{
$response = new StreamedResponse(function () {});
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
$response = new StreamedResponse(function () {});
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
}
}

View File

@ -318,10 +318,10 @@ class RouteCollectionBuilder
$routeCollection->addCollection($subCollection);
}
}
foreach ($this->resources as $resource) {
$routeCollection->addResource($resource);
}
foreach ($this->resources as $resource) {
$routeCollection->addResource($resource);
}
return $routeCollection;

View File

@ -12,7 +12,9 @@
namespace Symfony\Component\Routing\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouteCollectionBuilder;
@ -59,7 +61,18 @@ class RouteCollectionBuilderTest extends TestCase
$this->assertCount(1, $addedCollection->getResources());
// make sure the routes were imported into the top-level builder
$routeCollection = $routes->build();
$this->assertCount(1, $routes->build());
$this->assertCount(1, $routeCollection->getResources());
}
public function testImportAddResources()
{
$routeCollectionBuilder = new RouteCollectionBuilder(new YamlFileLoader(new FileLocator(array(__DIR__.'/Fixtures/'))));
$routeCollectionBuilder->import('file_resource.yml');
$routeCollection = $routeCollectionBuilder->build();
$this->assertCount(1, $routeCollection->getResources());
}
/**

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Core\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
@ -44,7 +45,7 @@ class AnonymousAuthenticationProvider implements AuthenticationProviderInterface
public function authenticate(TokenInterface $token)
{
if (!$this->supports($token)) {
return;
throw new AuthenticationException('The token is not supported by this authentication provider.');
}
if ($this->secret !== $token->getSecret()) {

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Security\Core\Authentication\Provider;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@ -51,7 +52,7 @@ class PreAuthenticatedAuthenticationProvider implements AuthenticationProviderIn
public function authenticate(TokenInterface $token)
{
if (!$this->supports($token)) {
return;
throw new AuthenticationException('The token is not supported by this authentication provider.');
}
if (!$user = $token->getUser()) {

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Security\Core\Authentication\Provider;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
class RememberMeAuthenticationProvider implements AuthenticationProviderInterface
@ -40,7 +41,7 @@ class RememberMeAuthenticationProvider implements AuthenticationProviderInterfac
public function authenticate(TokenInterface $token)
{
if (!$this->supports($token)) {
return;
throw new AuthenticationException('The token is not supported by this authentication provider.');
}
if ($this->secret !== $token->getSecret()) {

View File

@ -56,7 +56,7 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter
public function authenticate(TokenInterface $token)
{
if (!$this->supports($token)) {
return;
throw new AuthenticationException('The token is not supported by this authentication provider.');
}
$username = $token->getUsername();

View File

@ -24,11 +24,15 @@ class AnonymousAuthenticationProviderTest extends TestCase
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
* @expectedExceptionMessage The token is not supported by this authentication provider.
*/
public function testAuthenticateWhenTokenIsNotSupported()
{
$provider = $this->getProvider('foo');
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
}
/**

View File

@ -36,11 +36,15 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase
$this->assertFalse($provider->supports($token));
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
* @expectedExceptionMessage The token is not supported by this authentication provider.
*/
public function testAuthenticateWhenTokenIsNotSupported()
{
$provider = $this->getProvider();
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
}
/**

View File

@ -26,12 +26,16 @@ class RememberMeAuthenticationProviderTest extends TestCase
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
* @expectedExceptionMessage The token is not supported by this authentication provider.
*/
public function testAuthenticateWhenTokenIsNotSupported()
{
$provider = $this->getProvider();
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$this->assertNull($provider->authenticate($token));
$provider->authenticate($token);
}
/**

View File

@ -29,11 +29,15 @@ class UserAuthenticationProviderTest extends TestCase
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
* @expectedExceptionMessage The token is not supported by this authentication provider.
*/
public function testAuthenticateWhenTokenIsNotSupported()
{
$provider = $this->getProvider();
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
}
/**