8000 determine if we can use attributes · symfony/maker-bundle@3ca3736 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ca3736

Browse files
committed
determine if we can use attributes
1 parent 85761bd commit 3ca3736

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Maker/MakeCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bundle\MakerBundle\Generator;
1717
use Symfony\Bundle\MakerBundle\InputConfiguration;
1818
use Symfony\Bundle\MakerBundle\Str;
19+
use Symfony\Component\Console\Attribute\AsCommand;
1920
use Symfony\Component\Console\Command\Command;
2021
use Symfony\Component\Console\Command\LazyCommand;
2122
use Symfony\Component\Console\Input\InputArgument;
@@ -63,6 +64,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
6364
[
6465
'command_name' => $commandName,
6566
'set_description' => !class_exists(LazyCommand::class),
67+
'attribute_class_exists' => class_exists(AsCommand::class),
6668
]
6769
);
6870

src/Resources/skeleton/command/Command.tpl.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

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

5+
<?php if ($use_attributes && $attribute_class_exists): ?>
6+
use Symfony\Component\Console\Attribute\AsCommand;
7+
<?php endif; ?>
58
use Symfony\Component\Console\Command\Command;
69
use Symfony\Component\Console\Input\InputArgument;
710
use Symfony\Component\Console\Input\InputInterface;
811
use Symfony\Component\Console\Input\InputOption;
912
use Symfony\Component\Console\Output\OutputInterface;
1013
use Symfony\Component\Console\Style\SymfonyStyle;
1114

12-
<?php if ($use_attributes): ?>
15+
<?php if ($use_attributes && $attribute_class_exists): ?>
1316
#[ConsoleCommand(
1417
name: '<?= $command_name; ?>',
1518
description: 'Add a short description for your command',

0 commit comments

Comments
 (0)
0