-
-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend from AbstractController when using Symfony 4.1 or higher #221
Conversation
src/Maker/MakeController.php
Outdated
@@ -55,6 +56,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen | |||
$controllerClassNameDetails->getFullName(), | |||
'controller/Controller.tpl.php', | |||
[ | |||
'parent_class_name' => (Kernel::VERSION_ID) >= 40100 ? 'AbstractController' : 'Controller', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should detect the FrameworkBundle version actually, not the HttpKernel one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to do that. Which is the constant in FrameworkBundle
that stores its version? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class_exists(AbstractController::class)
should be good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chalasr much simpler! I love it. Thanks!
src/Maker/MakeController.php
Outdated
@@ -55,6 +56,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen | |||
$controllerClassNameDetails->getFullName(), | |||
'controller/Controller.tpl.php', | |||
[ | |||
'parent_class_name' => class_exists(AbstractController::class) ? 'AbstractController' : 'Controller', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AbstractController exists also in 3.4, so the check doesn't achieve what the title of this PR tells
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right 😭 Should we revert to the original code then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's wrong with using AbstractController
on 3.4 code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That it doesn't have the ->getParameter()
shortcut ... so it's not really equivalent to Controller
. In 4.1 it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, change the check to \method_exists(AbstractController::class, 'getParameter')
then?
|
||
class <?= $class_name; ?> extends Controller | ||
class <?= $class_name; ?> extends <?= $parent_class_name; ?><?= "\n" ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just wondering: is the "\n"
necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory it's not and I didn't add it at first ... but the generated controller class was like this:
class CoolController extends AbstractController {
// ...
}
instead of this:
class CoolController extends AbstractController
{
// ...
}
Can any of you reproduce my wrong behavior? If yes, can you explain to me why, because I don't understand this 😅
…klutman) This PR was merged into the 1.0-dev branch. Discussion ---------- Extend from AbstractController and use Symfony's @route This PR would close #240 and update the `make:crud` command to correctly use Symfony's Routing component instead of the deprecated `FrameworkExtraBundle`'s. Would appreciate a thorough review as all I did was basically look at @javiereguiluz's PR #221 for the AbstractController fix. Commits ------- 07166c9 Extend from AbstractController and use Symfony's Route
Related to symfony/symfony-docs#9991 ... let's extend from
AbstractController
when possible.