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

[make:command] lets use attributes if possible #822

Merged
merged 1 commit into from
Apr 9, 2021

Conversation

jrushlow
Copy link
Collaborator

@jrushlow jrushlow commented Feb 22, 2021

Console command attribute class renamed from ConsoleCommand => AsCommand symfony/symfony#40556

closes #820

@@ -9,11 +9,19 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

<?php if ($use_attributes): ?>
Copy link
Member

Choose a reason for hiding this comment

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

It's more complex than this. $use_attributes tells us if the PHP version supports attributes. But in this case, we also need to see if the version of Symfony has the ConsoleCommand class. Also, this will need a use statement on top.

I know we're in the process of fixing some test failures to due upstream changes (so it's hard to look at CI), but let's make sure that if we misconfigure this somehow (e.g. forget the use statement) that it does cause a test to fail.

@jrushlow jrushlow force-pushed the feature/command-attributes branch from e7db329 to 0f6902e Compare March 23, 2021 15:22
@jrushlow jrushlow force-pushed the feature/command-attributes branch from fc69bfc to 3ca3736 Compare April 5, 2021 13:27
@jrushlow jrushlow changed the title lets use attributes in commands if possible [make:command] lets use attributes if possible Apr 5, 2021
@jrushlow jrushlow force-pushed the feature/command-attributes branch from 41cfaa5 to 6d0db57 Compare April 5, 2021 17:28
@@ -63,6 +64,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
[
'command_name' => $commandName,
'set_description' => !class_exists(LazyCommand::class),
'use_command_attribute' => 80000 <= \PHP_VERSION_ID && class_exists(AsCommand::class),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Under a different PR, I think we can add a helper to the PhpCompatUtil to eliminate having to check the PHP version before calling class_exists(). But the complexity required to make that happen is beyond the scope of this PR.

https://bugs.php.net/bug.php?id=80938 explains why this must be done like this.

@@ -2,18 +2,29 @@

namespace <?= $namespace; ?>;

<?php if ($use_attributes && $use_command_attribute): ?>
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to check both? $use_command_attribute already checks for PHP 8.0 or higher. So it seems like it fully describes which situation we are in, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we could drop $use_attributes here, but then we would loose the ability to determine if attributes should be used based on the platform-overrides. Then again as I'm saying this, regardless of platform overrides, they wouldn't be able to use attributes anyway if PHP was not 8+ at runtime..

Thinking we drop $use_attributes for now and when I'm able to accomplish the helper in PhpCompatUtil, we can re introduce / refactor our logic here.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right about the config.platform.php thing. So then... shouldn't we keep the $use_attributes? Otherwise, it's possible that I'm using PHP 8... but my config.platform.php is set to 7.4... and suddenly we generate code that uses attributes?

@jrushlow jrushlow force-pushed the feature/command-attributes branch from 67cdc66 to 95eafee Compare April 8, 2021 19:27
@weaverryan
Copy link
Member

Thanks Jesse!

@weaverryan weaverryan merged commit c1c1386 into symfony:main Apr 9, 2021
@jrushlow jrushlow deleted the feature/command-attributes branch April 25, 2021 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate ConsoleCommand attribute on PHP8
3 participants