Skip to content

Commit a69bd94

Browse files
Merge branch '3.4' into 4.0
* 3.4: [appveyor] set memory_limit=-1 [Console] Keep the modified exception handler [Console] Fix restoring exception handler [Router] Skip anonymous classes when loading annotated routes allow dashes in cwd pathname when running the tests Fixed Request::__toString ignoring cookies Make sure we only build once and have one time the prefix when importing routes [Security] Fix fatal error on non string username [FrameworkBundle] Automatically enable the CSRF if component *+ session* are loaded
2 parents a34b58e + 235d017 commit a69bd94

File tree

5 files changed

+69
-8
lines changed

5 files changed

+69
-8
lines changed

Loader/AnnotationFileLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,22 @@ protected function findClass($file)
111111
}
112112

113113
if (T_CLASS === $token[0]) {
114-
// Skip usage of ::class constant
115-
$isClassConstant = false;
114+
// Skip usage of ::class constant and anonymous classes
115+
$skipClassToken = false;
116116
for ($j = $i - 1; $j > 0; --$j) {
117117
if (!isset($tokens[$j][1])) {
118118
break;
119119
}
120120

121-
if (T_DOUBLE_COLON === $tokens[$j][0]) {
122-
$isClassConstant = true;
121+
if (T_DOUBLE_COLON === $tokens[$j][0] || T_NEW === $tokens[$j][0]) {
122+
$skipClassToken = true;
123123
break;
124124
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
125125
break;
126126
}
127127
}
128128

129-
if (!$isClassConstant) {
129+
if (!$skipClassToken) {
130130
$class = true;
131131
}
132132
}

RouteCollectionBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ public function import($resource, $prefix = '/', $type = null)
7676
foreach ($collection->getResources() as $resource) {
7777
$builder->addResource($resource);
7878
}
79-
80-
// mount into this builder
81-
$this->mount($prefix, $builder);
8279
}
8380

81+
// mount into this builder
82+
$this->mount($prefix, $builder);
83+
8484
return $builder;
8585
}
8686

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Tests\Fixtures\OtherAnnotatedClasses;
13+
14+
trait AnonymousClassInTrait
15+
{
16+
public function test()
17+
{
18+
return new class() {
19+
public function foo()
20+
{
21+
}
22+
};
23+
}
24+
}

Tests/Loader/AnnotationFileLoaderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ public function testLoadVariadic()
6161
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
6262
}
6363

64+
/**
65+
* @requires PHP 7.0
66+
*/
67+
public function testLoadAnonymousClass()
68+
{
69+
$this->reader->expects($this->never())->method('getClassAnnotation');
70+
$this->reader->expects($this->never())->method('getMethodAnnotations');
71+
72+
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/AnonymousClassInTrait.php');
73+
}
74+
6475
public function testSupports()
6576
{
6677
$fixture = __DIR__.'/../Fixtures/annotated.php';

Tests/RouteCollectionBuilderTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,30 @@ public function testAutomaticRouteNamesDoNotConflict()
335335
// there are 2 routes (i.e. with non-conflicting names)
336336
$this->assertCount(3, $collection->all());
337337
}
338+
339+
public function testAddsThePrefixOnlyOnceWhenLoadingMultipleCollections()
340+
{
341+
$firstCollection = new RouteCollection();
342+
$firstCollection->add('a', new Route('/a'));
343+
344+
$secondCollection = new RouteCollection();
345+
$secondCollection->add('b', new Route('/b'));
346+
347+
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
348+
$loader->expects($this->any())
349+
->method('supports')
350+
->will($this->returnValue(true));
351+
$loader
352+
->expects($this->any())
353+
->method('load')
354+
->will($this->returnValue(array($firstCollection, $secondCollection)));
355+
356+
$routeCollectionBuilder = new RouteCollectionBuilder($loader);
357+
$routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');
358+
$routes = $routeCollectionBuilder->build()->all();
359+
360+
$this->assertEquals(2, count($routes));
361+
$this->assertEquals('/other/a', $routes['a']->getPath());
362+
$this->assertEquals('/other/b', $routes['b']->getPath());
363+
}
338364
}

0 commit comments

Comments
 (0)