Skip to content
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

Closed

Conversation

javiereguiluz
Copy link
Member

Related to symfony/symfony-docs#9991 ... let's extend from AbstractController when possible.

@@ -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',
Copy link
Member

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

Copy link
Member Author

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!

Copy link
Member

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

Copy link
Member Author

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!

@@ -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',
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@chalasr chalasr Jul 6, 2018

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" ?>
Copy link
Member

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?

Copy link
Member Author

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 😅

@javiereguiluz javiereguiluz added the Feature New Feature label Jul 26, 2018
weaverryan added a commit that referenced this pull request Aug 29, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants