8000 Merge branch '2.8' into 3.3 · alexpott/symfony@402246e · GitHub
[go: up one dir, main page]

Skip to content

Commit 402246e

Browse files
committed
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
2 parents 2f1af1b + 77a74df commit 402246e

16 files changed

+70
-17
lines changed

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ public function process(ContainerBuilder $container)
4646
if ($container->has('form.extension')) {
4747
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
4848
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
49-
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
49+
50+
$coreThemePath = dirname(dirname($reflClass->getFileName())).'/Resources/views/Form';
51+
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array($coreThemePath));
52+
53+
$paths = $container->getDefinition('twig.cache_warmer')->getArgument(2);
54+
$paths[$coreThemePath] = null;
55+
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $paths);
56+
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $paths);
5057
}
5158

5259
if ($container->has('translator')) {

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function load(array $configs, ContainerBuilder $container)
100100
}
101101
}
102102

103+
// paths are modified in ExtensionPass if forms are enabled
103104
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $config['paths']);
104105
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $config['paths']);
105106

src/Symfony/Component/HttpFoundation/AcceptHeader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function first()
153153
private function sort()
154154
{
155155
if (!$this->sorted) {
156-
uasort($this->items, function ($a, $b) {
156+
uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) {
157157
$qA = $a->getQuality();
158158
$qB = $b->getQuality();
159159

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class Request
144144
public $headers;
145145

146146
/**
147-
* @var string
147+
* @var string|resource
148148
*/
149149
protected $content;
150150

src/Symfony/Component/HttpFoundation/StreamedResponse.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ public function setCallback(callable $callback)
7878
public function sendHeaders()
7979
{
8080
if ($this->headersSent) {
81-
return;
81+
return $this;
8282
}
8383

8484
$this->headersSent = true;
8585

86-
parent::sendHeaders();
86+
return parent::sendHeaders();
8787
}
8888

8989
/**
@@ -94,7 +94,7 @@ public function sendHeaders()
9494
public function sendContent()
9595
{
9696
if ($this->streamed) {
97-
return;
97+
return $this;
9898
}
9999

100100
$this->streamed = true;
@@ -104,6 +104,8 @@ public function sendContent()
104104
}
105105

106106
call_user_func($this->callback);
107+
108+
return $this;
107109
}
108110

109111
/**

src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,15 @@ public function testCreate()
112112
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
113113
$this->assertEquals(204, $response->getStatusCode());
114114
}
115+
116+
public function testReturnThis()
117+
{
118+
$response = new StreamedResponse(function () {});
119+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
120+
$this->assertInstanceOf('Symfony\Comp 10000 onent\HttpFoundation\StreamedResponse', $response->sendContent());
121+
122+
$response = new StreamedResponse(function () {});
123+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
124+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
125+
}
115126
}

src/Symfony/Component/Routing/RouteCollectionBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ public function build()
318318

319319
$routeCollection->addCollection($subCollection);
320320
}
321+
}
321322

322-
foreach ($this->resources as $resource) {
323-
$routeCollection->addResource($resource);
324-
}
323+
foreach ($this->resources as $resource) {
324+
$routeCollection->addResource($resource);
325325
}
326326

327327
return $routeCollection;

src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
namespace Symfony\Component\Routing\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Config\FileLocator;
1516
use Symfony\Component\Config\Resource\FileResource;
17+
use Symfony\Component\Routing\Loader\YamlFileLoader;
1618
use Symfony\Component\Routing\Route;
1719
use Symfony\Component\Routing\RouteCollection;
1820
use Symfony\Component\Routing\RouteCollectionBuilder;
@@ -59,7 +61,18 @@ public function testImport()
5961
$this->assertCount(1, $addedCollection->getResources());
6062

6163
// make sure the routes were imported into the top-level builder
64+
$routeCollection = $routes->build();
6265
$this->assertCount(1, $routes->build());
66+
$this->assertCount(1, $routeCollection->getResources());
67+
}
68+
69+
public function testImportAddResources()
70+
{
71+
$routeCollectionBuilder = new RouteCollectionBuilder(new YamlFileLoader(new FileLocator(array(__DIR__.'/Fixtures/'))));
72+
$routeCollectionBuilder->import('file_resource.yml');
73+
$routeCollection = $routeCollectionBuilder->build();
74+
75+
$this->assertCount(1, $routeCollection->getResources());
6376
}
6477

6578
/**

src/Symfony/Component/Security/Core/Authentication/Provider/AnonymousAuthenticationProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Core\Authentication\Provider;
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1516
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1617
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
1718

@@ -44,7 +45,7 @@ public function __construct($secret)
4445
public function authenticate(TokenInterface $token)
4546
{
4647
if (!$this->supports($token)) {
47-
return;
48+
throw new AuthenticationException('The token is not supported by this authentication provider.');
4849
}
4950

5051
if ($this->secret !== $token->getSecret()) {

src/Symfony/Component/Security/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\User\UserProviderInterface;
1515
use Symfony\Component\Security\Core\User\UserCheckerInterface;
16+
u F438 se Symfony\Component\Security\Core\Exception\AuthenticationException;
1617
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1718
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
1819
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -51,7 +52,7 @@ public function __construct(UserProviderInterface $userProvider, UserCheckerInte
5152
public function authenticate(TokenInterface $token)
5253
{
5354
if (!$this->supports($token)) {
54-
return;
55+
throw new AuthenticationException('The token is not supported by this authentication provider.');
5556
}
5657

5758
if (!$user = $token->getUser()) {

src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Security\Core\User\UserCheckerInterface;
1515
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1616
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
17+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1718
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1819

1920
class RememberMeAuthenticationProvider implements AuthenticationProviderInterface
@@ -40,7 +41,7 @@ public function __construct(UserCheckerInterface $userChecker, $secret, $provide
4041
public function authenticate(TokenInterface $token)
4142
{
4243
if (!$this->supports($token)) {
43-
return;
44+
throw new AuthenticationException('The token is not supported by this authentication provider.');
4445
}
4546

4647
if ($this->secret !== $token->getSecret()) {

src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(UserCheckerInterface $userChecker, $providerKey, $hi
5656
public function authenticate(TokenInterface $token)
5757
{
5858
if (!$this->supports($token)) {
59-
return;
59+
throw new AuthenticationException('The token is not supported by this authentication provider.');
6060
}
6161

6262
$username = $token->getUsername();

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ public function testSupports()
2424
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
2525
}
2626

27+
/**
28+
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
29+
* @expectedExceptionMessage The token is not supported by this authentication provider.
30+
*/
2731
public function testAuthenticateWhenTokenIsNotSupported()
2832
{
2933
$provider = $this->getProvider('foo');
3034

31-
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
35+
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
3236
}
3337

3438
/**

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ public function testSupports()
3636
$this->assertFalse($provider->supports($token));
3737
}
3838

39+
/**
40+
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
41+
* @expectedExceptionMessage The token is not supported by this authentication provider.
42+
*/
3943
public function testAuthenticateWhenTokenIsNotSupported()
4044
{
4145
$provider = $this->getProvider();
4246

43-
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
47+
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
4448
}
4549

4650
/**

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ public function testSupports()
2626
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
2727
}
2828

29+
/**
30+
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
31+
* @expectedExceptionMessage The token is not supported by this authentication provider.
32+
*/
2933
public function testAuthenticateWhenTokenIsNotSupported()
3034
{
3135
$provider = $this->getProvider();
3236

3337
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
34-
$this->assertNull($provider->authenticate($token));
38+
$provider->authenticate($token);
3539
}
3640

3741
/**

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ public function testSupports()
2929
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
3030
}
3131

32+
/**
33+
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
34+
* @expectedExceptionMessage The token is not supported by this authentication provider.
35+
*/
3236
public function testAuthenticateWhenTokenIsNotSupported()
3337
{
3438
$provider = $this->getProvider();
< 5968 code>3539

36-
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
40+
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
3741
}
3842

3943
/**

0 commit comments

Comments
 (0)
0