Skip to content

Generate a different controller when Twig is not installed #7

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

Closed
wants to merge 3 commits into from
Closed

Generate a different controller when Twig is not installed #7

wants to merge 3 commits into from

Conversation

javiereguiluz
Copy link
Member

This fixes #6.


private function isTwigInstalled()
{
return class_exists('Symfony\Bundle\TwigBundle\TwigBundle')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the class constant here

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 mean this? class_exists(TwigBundle::class) and the use ... import or class_exists(Symfony\Bundle\TwigBundle\TwigBundle::class) ? I don't like it because the editor shows a "not found class" error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, like that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But as I said, the current version works as expected:

right

but the other proposal makes your editor display an error (it's annoying and confusing):

wrong

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's we do in the core too. So why do we want to change that here? Indeed, the error is not so nice, but that's related to the IDE/editor. And the end user will probably not look into this class anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is what Symfony does, there's nothing more to discuss 😄 Consistency is the most important thing.


private function isTwigInstalled()
{
return class_exists(Symfony\Bundle\TwigBundle\TwigBundle::class);
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 add a use Symfony\Bundle\TwigBundle\TwigBundle statement and then use TwigBundle::class here.

public function index()
{
// replace this line with your own code!
return $this->render('@Maker/demoPage.html.twig', [ 'path' => str_replace($this->getParameter('kernel.project_dir').'/', '', __FILE__) ]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use demo.html.twig as a template name instead. @Maker won't work anyway and we don't recommend using @App.

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 a separate PR I'm going to propose to remove this code and the demo template entirely. We don't need it in a generator bundle (it's useful only after creating a new project, but we already have that covered).

@javiereguiluz
Copy link
Member Author

I'm having some tech issues updating this PR ... so I've created another PR: #8.

fabpot added a commit that referenced this pull request Nov 18, 2017
…viereguiluz)

This PR was squashed before being merged into the 1.0-dev branch (closes #8).

Discussion
----------

 Generate a different controller when Twig is not installed

It fixes #6 and replaces #7.

Commits
-------

eb8da45  Generate a different controller when Twig is not installed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return a simple Response from make:controller is twig is not installed
3 participants