Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit193b98a

Browse files
minor#25460 [FrameworkBundle] Move AbstractController::getParameter() from the trait to the class & use PSR-11 (nicolas-grekas)
This PR was merged into the 4.1-dev branch.Discussion----------[FrameworkBundle] Move AbstractController::getParameter() from the trait to the class & use PSR-11| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Feels more specific this way to me. Ping@chalasrCommits-------3051289 [FrameworkBundle] Move AbstractController::getParameter() from the trait to the class & use PSR-11
2 parents72e189a +3051289 commit193b98a

File tree

4 files changed

+42
-39
lines changed

4 files changed

+42
-39
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php‎

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

1414
usePsr\Container\ContainerInterface;
1515
useDoctrine\Common\Persistence\ManagerRegistry;
16-
useSymfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
1716
useSymfony\Component\DependencyInjection\ServiceSubscriberInterface;
1817
useSymfony\Component\Form\FormFactoryInterface;
1918
useSymfony\Component\HttpFoundation\RequestStack;
@@ -53,6 +52,22 @@ public function setContainer(ContainerInterface $container)
5352
return$previous;
5453
}
5554

55+
/**
56+
* Gets a container parameter by its name.
57+
*
58+
* @return mixed
59+
*
60+
* @final
61+
*/
62+
protectedfunctiongetParameter(string$name)
63+
{
64+
if (!$this->container->has('parameter_bag')) {
65+
thrownew \LogicException('The "parameter_bag" service is not available. Try running "composer require dependency-injection:^4.1"');
66+
}
67+
68+
return$this->container->get('parameter_bag')->get($name);
69+
}
70+
5671
publicstaticfunctiongetSubscribedServices()
5772
{
5873
returnarray(
@@ -68,7 +83,7 @@ public static function getSubscribedServices()
6883
'form.factory' =>'?'.FormFactoryInterface::class,
6984
'security.token_storage' =>'?'.TokenStorageInterface::class,
7085
'security.csrf.token_manager' =>'?'.CsrfTokenManagerInterface::class,
71-
'parameter_bag' =>'?'.ContainerBagInterface::class,
86+
'parameter_bag' =>'?'.ContainerInterface::class,
7287
);
7388
}
7489
}

‎src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -377,20 +377,4 @@ protected function isCsrfTokenValid(string $id, string $token): bool
377377

378378
return$this->container->get('security.csrf.token_manager')->isTokenValid(newCsrfToken($id,$token));
379379
}
380-
381-
/**
382-
* Gets a container parameter by its name.
383-
*
384-
* @return mixed
385-
*
386-
* @final
387-
*/
388-
protectedfunctiongetParameter(string$name)
389-
{
390-
if (!$this->container->has('parameter_bag')) {
391-
thrownew \LogicException('The "parameter_bag" service is not available. Try running "composer require dependency-injection:^4.1"');
392-
}
393-
394-
return$this->container->get('parameter_bag')->get($name);
395-
}
396380
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,33 @@
1313

1414
usePsr\Container\ContainerInterface;
1515
useSymfony\Bundle\FrameworkBundle\Controller\AbstractController;
16+
useSymfony\Component\DependencyInjection\Container;
17+
useSymfony\Component\DependencyInjection\ParameterBag\ContainerBag;
18+
useSymfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
1619

1720
class AbstractControllerTestextends ControllerTraitTest
1821
{
1922
protectedfunctioncreateController()
2023
{
2124
returnnewTestAbstractController();
2225
}
26+
27+
publicfunctiontestGetParameter()
28+
{
29+
$container =newContainer(newFrozenParameterBag(array('foo' =>'bar')));
30+
31+
$controller =$this->createController();
32+
$controller->setContainer($container);
33+
34+
if (!class_exists(ContainerBag::class)) {
35+
$this->expectException(\LogicException::class);
36+
$this->expectExceptionMessage('The "parameter_bag" service is not available. Try running "composer require dependency-injection:^4.1"');
37+
}else {
38+
$container->set('parameter_bag',newContainerBag($container));
39+
}
40+
41+
$this->assertSame('bar',$controller->getParameter('foo'));
42+
}
2343
}
2444

2545
class TestAbstractControllerextends AbstractController
@@ -57,6 +77,11 @@ public function setContainer(ContainerInterface $container)
5777
returnparent::setContainer($container);
5878
}
5979

80+
publicfunctiongetParameter(string$name)
81+
{
82+
returnparent::getParameter($name);
83+
}
84+
6085
publicfunctionfooAction()
6186
{
6287
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
useSymfony\Bundle\FrameworkBundle\Tests\TestCase;
1515
useSymfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
1616
useSymfony\Component\DependencyInjection\Container;
17-
useSymfony\Component\DependencyInjection\ParameterBag\ContainerBag;
18-
useSymfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
19-
useSymfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
2017
useSymfony\Component\HttpFoundation\BinaryFileResponse;
2118
useSymfony\Component\HttpFoundation\File\File;
2219
useSymfony\Component\HttpFoundation\JsonResponse;
@@ -531,23 +528,6 @@ public function testGetDoctrine()
531528

532529
$this->assertEquals($doctrine,$controller->getDoctrine());
533530
}
534-
535-
publicfunctiontestGetParameter()
536-
{
537-
$container =newContainer(newFrozenParameterBag(array('foo' =>'bar')));
538-
539-
$controller =$this->createController();
540-
$controller->setContainer($container);
541-
542-
if (!interface_exists(ContainerBagInterface::class)) {
543-
$this->expectException(\LogicException::class);
544-
$this->expectExceptionMessage('The "parameter_bag" service is not available. Try running "composer require dependency-injection:^4.1"');
545-
}else {
546-
$container->set('parameter_bag',newContainerBag($container));
547-
}
548-
549-
$this->assertSame('bar',$controller->getParameter('foo'));
550-
}
551531
}
552532

553533
trait TestControllerTrait
@@ -572,6 +552,5 @@ trait TestControllerTrait
572552
createFormaspublic;
573553
createFormBuilderaspublic;
574554
getDoctrineaspublic;
575-
getParameteraspublic;
576555
}
577556
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp