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:
commit
402246ebaa
|
@ -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')) {
|
||||
|
|
|
@ -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']);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ class Request
|
|||
public $headers;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var string|resource
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in New Issue