Skip to content

Commit 4980bba

Browse files
committed
minor #221 Extend from AbstractController when using Symfony 4.1 or higher (javiereguiluz)
This PR was squashed before being merged into the 1.0-dev branch (closes #221). Discussion ---------- Extend from AbstractController when using Symfony 4.1 or higher Related to symfony/symfony-docs#9991 ... let's extend from `AbstractController` when possible. Commits ------- 2e6403b Extend from AbstractController when using Symfony 4.1 or higher
2 parents fe8c5e9 + 2e6403b commit 4980bba

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Maker/MakeController.php

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

1414
use Doctrine\Common\Annotations\Annotation;
15+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1516
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1617
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1718
use Symfony\Bundle\MakerBundle\Generator;
@@ -55,6 +56,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
5556
$controllerClassNameDetails->getFullName(),
5657
'controller/Controller.tpl.php',
5758
[
59+
'parent_class_name' => \method_exists(AbstractController::class, 'getParameter') ? 'AbstractController' : 'Controller',
5860
'route_path' => Str::asRoutePath($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
5961
'route_name' => Str::asRouteName($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
6062
'twig_installed' => $this->isTwigInstalled(),

src/Resources/skeleton/controller/Controller.tpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace <?= $namespace; ?>;
44

5+
use Symfony\Bundle\FrameworkBundle\Controller\<?= $parent_class_name; ?>;
56
use Symfony\Component\Routing\Annotation\Route;
6-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
77

8-
class <?= $class_name; ?> extends Controller
8+
class <?= $class_name; ?> extends <?= $parent_class_name; ?><?= "\n" ?>
99
{
1010
/**
1111
* @Route("<?= $route_path ?>", name="<?= $route_name ?>")

0 commit comments

Comments
 (0)