Skip to content

Commit aa3c326

Browse files
Merge branch '3.3' into 3.4
* 3.3: (33 commits) Preserve HttpOnly value when deserializing a header [DX] [TwigBundle] Enhance the new exception page design Fix deprecated message [DI][Security] Prevent unwanted deprecation notices when using Expression Languages bumped Symfony version to 3.3.5 updated VERSION for 3.3.4 updated CHANGELOG for 3.3.4 [VarDumper] Reduce size of serialized Data objects bumped Symfony version to 3.2.12 updated VERSION for 3.2.11 updated CHANGELOG for 3.2.11 fixed bad merge Fix indent of methods [Cache] Handle APCu failures gracefully [DoctrineBridge] Use normalizedIds for resetting entity manager services [FrameworkBundle] Do not remove files from assets dir [FrameworkBundle] 3.3: Don't get() private services from debug:router bumped Symfony version to 3.3.4 updated VERSION for 3.3.3 updated CHANGELOG for 3.3.3 ...
2 parents 6cac249 + f086661 commit aa3c326

File tree

6 files changed

+135
-38
lines changed

6 files changed

+135
-38
lines changed

Command/AssetsInstallCommand.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
121121
continue;
122122
}
123123

124-
$targetDir = $bundlesDir.preg_replace('/bundle$/', '', strtolower($bundle->getName()));
124+
$assetDir = preg_replace('/bundle$/', '', strtolower($bundle->getName()));
125+
$targetDir = $bundlesDir.$assetDir;
126+
$validAssetDirs[] = $assetDir;
125127

126128
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
127129
$message = sprintf("%s\n-> %s", $bundle->getName(), $targetDir);
@@ -153,14 +155,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
153155
$exitCode = 1;
154156
$rows[] = array(sprintf('<fg=red;options=bold>%s</>', '\\' === DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */), $message, $e->getMessage());
155157
}
156-
$validAssetDirs[] = $targetDir;
157158
}
158159
// remove the assets of the bundles that no longer exist
159-
foreach (new \FilesystemIterator($bundlesDir) as $dir) {
160-
if (!in_array($dir, $validAssetDirs)) {
161-
$this->filesystem->remove($dir);
162-
}
163-
}
160+
$dirsToRemove = Finder::create()->depth(0)->directories()->exclude($validAssetDirs)->in($bundlesDir);
161+
$this->filesystem->remove($dirsToRemove);
164162

165163
$io->table(array('', 'Bundle', 'Method / Error'), $rows);
166164

Command/RouterDebugCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
15+
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Input\InputOption;
@@ -112,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
112113
private function convertController(Route $route)
113114
{
114115
if ($route->hasDefault('_controller')) {
115-
$nameParser = $this->getContainer()->get('controller_name_converter');
116+
$nameParser = new ControllerNameParser($this->getApplication()->getKernel());
116117
try {
117118
$route->setDefault('_controller', $nameParser->build($route->getDefault('_controller')));
118119
} catch (\InvalidArgumentException $e) {
@@ -136,7 +137,7 @@ private function extractCallable(Route $route)
136137
}
137138
}
138139

139-
$nameParser = $this->getContainer()->get('controller_name_converter');
140+
$nameParser = new ControllerNameParser($this->getApplication()->getKernel());
140141
try {
141142
$shortNotation = $nameParser->build($controller);
142143
$route->setDefault('_controller', $shortNotation);

Controller/ControllerResolver.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,19 @@ protected function createController($controller)
4949
$controller = $this->parser->parse($controller);
5050
}
5151

52-
return parent::createController($controller);
52+
$resolvedController = parent::createController($controller);
53+
54+
if (1 === substr_count($controller, ':') && is_array($resolvedController)) {
55+
if ($resolvedController[0] instanceof ContainerAwareInterface) {
56+
$resolvedController[0]->setContainer($this->container);
57+
}
58+
59+
if ($resolvedController[0] instanceof AbstractController && null !== $previousContainer = $resolvedController[0]->setContainer($this->container)) {
60+
$resolvedController[0]->setContainer($previousContainer);
61+
}
62+
}
63+
64+
return $resolvedController;
5365
}
5466

5567
/**

Tests/Command/RouterDebugCommandTest.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Console\Application;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
1616
use Symfony\Component\Console\Tester\CommandTester;
1717
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
18+
use Symfony\Component\HttpKernel\KernelInterface;
1819
use Symfony\Component\Routing\Route;
1920
use Symfony\Component\Routing\RouteCollection;
2021

@@ -51,16 +52,15 @@ public function testDebugInvalidRoute()
5152
*/
5253
private function createCommandTester()
5354
{
54-
$application = new Application();
55+
$application = new Application($this->getKernel());
5556

5657
$command = new RouterDebugCommand();
57-
$command->setContainer($this->getContainer());
5858
$application->add($command);
5959

6060
return new CommandTester($application->find('debug:router'));
6161
}
6262

63-
private function getContainer()
63+
private function getKernel()
6464
{
6565
$routeCollection = new RouteCollection();
6666
$routeCollection->add('foo', new Route('foo'));
@@ -82,14 +82,25 @@ private function getContainer()
8282
->with('router')
8383
->will($this->returnValue(true))
8484
;
85-
8685
$container
86+
->expects($this->any())
8787
->method('get')
88-
->will($this->returnValueMap(array(
89-
array('router', 1, $router),
90-
array('controller_name_converter', 1, $loader),
91-
)));
88+
->with('router')
89+
->willReturn($router)
90+
;
91+
92+
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
93+
$kernel
94+
->expects($this->any())
95+
->method('getContainer')
96+
->willReturn($container)
97+
;
98+
$kernel
99+
->expects($this->once())
100+
->method('getBundles')
101+
->willReturn(array())
102+
;
92103

93-
return $container;
104+
return $kernel;
94105
}
95106
}

Tests/Command/RouterMatchCommandTest.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Console\Application;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
1616
use Symfony\Component\Console\Tester\CommandTester;
1717
use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
1818
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
19+
use Symfony\Component\HttpKernel\KernelInterface;
1920
use Symfony\Component\Routing\Route;
2021
use Symfony\Component\Routing\RouteCollection;
2122
use Symfony\Component\Routing\RequestContext;
@@ -45,20 +46,14 @@ public function testWithNotMatchPath()
4546
*/
4647
private function createCommandTester()
4748
{
48-
$application = new Application();
49-
50-
$command = new RouterMatchCommand();
51-
$command->setContainer($this->getContainer());
52-
$application->add($command);
53-
54-
$command = new RouterDebugCommand();
55-
$command->setContainer($this->getContainer());
56-
$application->add($command);
49+
$application = new Application($this->getKernel());
50+
$application->add(new RouterMatchCommand());
51+
$application->add(new RouterDebugCommand());
5752

5853
return new CommandTester($application->find('router:match'));
5954
}
6055

61-
private function getContainer()
56+
private function getKernel()
6257
{
6358
$routeCollection = new RouteCollection();
6459
$routeCollection->add('foo', new Route('foo'));
@@ -81,16 +76,27 @@ private function getContainer()
8176

8277
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
8378
$container
84-
->expects($this->once())
79+
->expects($this->atLeastOnce())
8580
->method('has')
8681
->with('router')
8782
->will($this->returnValue(true));
88-
$container->method('get')
89-
->will($this->returnValueMap(array(
90-
array('router', 1, $router),
91-
array('controller_name_converter', 1, $loader),
92-
)));
83+
$container
84+
->expects($this->any())
85+
->method('get')
86+
->willReturn($router);
87+
88+
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
89+
$kernel
90+
->expects($this->any())
91+
->method('getContainer')
92+
->willReturn($container)
93+
;
94+
$kernel
95+
->expects($this->once())
96+
->method('getBundles')
97+
->willReturn(array())
98+
;
9399

94-
return $container;
100+
return $kernel;
95101
}
96102
}

Tests/Controller/ControllerResolverTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Psr\Container\ContainerInterface as Psr11ContainerInterface;
1515
use Psr\Log\LoggerInterface;
16+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1617
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
1718
use Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver;
1819
use Symfony\Component\DependencyInjection\Container;
@@ -68,6 +69,24 @@ public function testGetControllerWithBundleNotation()
6869
$this->assertSame('testAction', $controller[1]);
6970
}
7071

72+
public function testContainerAwareControllerGetsContainerWhenNotSet()
73+
{
74+
class_exists(AbstractControllerTest::class);
75+
76+
$controller = new ContainerAwareController();
77+
78+
$container = new Container();
79+
$container->set(TestAbstractController::class, $controller);
80+
81+
$resolver = $this->createControllerResolver(null, $container);
82+
83+
$request = Request::create('/');
84+
$request->attributes->set('_controller', TestAbstractController::class.':testAction');
85+
86+
$this->assertSame(array($controller, 'testAction'), $resolver->getController($request));
87+
$this->assertSame($container, $controller->getContainer());
88+
}
89+
7190
public function testAbstractControllerGetsContainerWhenNotSet()
7291
{
7392
class_exists(AbstractControllerTest::class);
@@ -86,6 +105,24 @@ class_exists(AbstractControllerTest::class);
86105
$this->assertSame($container, $controller->setContainer($container));
87106
}
88107

108+
public function testAbstractControllerServiceWithFcqnIdGetsContainerWhenNotSet()
109+
{
110+
class_exists(AbstractControllerTest::class);
111+
112+
$controller = new DummyController();
113+
114+
$container = new Container();
115+
$container->set(DummyController::class, $controller);
116+
117+
$resolver = $this->createControllerResolver(null, $container);
118+
119+
$request = Request::create('/');
120+
$request->attributes->set('_controller', DummyController::class.':fooAction');
121+
122+
$this->assertSame(array($controller, 'fooAction'), $resolver->getController($request));
123+
$this->assertSame($container, $controller->getContainer());
124+
}
125+
89126
public function testAbstractControllerGetsNoContainerWhenSet()
90127
{
91128
class_exists(AbstractControllerTest::class);
@@ -106,6 +143,26 @@ class_exists(AbstractControllerTest::class);
106143
$this->assertSame($controllerContainer, $controller->setContainer($container));
107144
}
108145

146+
public function testAbstractControllerServiceWithFcqnIdGetsNoContainerWhenSet()
147+
{
148+
class_exists(AbstractControllerTest::class);
149+
150+
$controller = new DummyController();
151+
$controllerContainer = new Container();
152+
$controller->setContainer($controllerContainer);
153+
154+
$container = new Container();
155+
$container->set(DummyController::class, $controller);
156+
157+
$resolver = $this->createControllerResolver(null, $container);
158+
159+
$request = Request::create('/');
160+
$request->attributes->set('_controller', DummyController::class.':fooAction');
161+
162+
$this->assertSame(array($controller, 'fooAction'), $resolver->getController($request));
163+
$this->assertSame($controllerContainer, $controller->getContainer());
164+
}
165+
109166
protected function createControllerResolver(LoggerInterface $logger = null, Psr11ContainerInterface $container = null, ControllerNameParser $parser = null)
110167
{
111168
if (!$parser) {
@@ -152,3 +209,15 @@ public function __invoke()
152209
{
153210
}
154211
}
212+
213+
class DummyController extends AbstractController
214+
{
215+
public function getContainer()
216+
{
217+
return $this->container;
218+
}
219+
220+
public function fooAction()
221+
{
222+
}
223+
}

0 commit comments

Comments
 (0)