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\Component\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+
use 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()) {

0 commit comments

Comments
 (0)