1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Bundle\Maker; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\MakerBundle\ConsoleStyle; |
6
|
|
|
use Symfony\Bundle\MakerBundle\DependencyBuilder; |
7
|
|
|
use Symfony\Bundle\MakerBundle\Generator; |
8
|
|
|
use Symfony\Bundle\MakerBundle\InputConfiguration; |
9
|
|
|
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker; |
10
|
|
|
use Symfony\Bundle\MakerBundle\Validator; |
11
|
|
|
use Symfony\Component\Console\Command\Command; |
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Kevin Bond <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
final class MakeStory extends AbstractMaker |
20
|
|
|
{ |
21
|
2 |
|
public static function getCommandName(): string |
22
|
|
|
{ |
23
|
2 |
|
return 'make:story'; |
24
|
|
|
} |
25
|
|
|
|
26
|
16 |
|
public function configureCommand(Command $command, InputConfiguration $inputConfig): void |
27
|
|
|
{ |
28
|
|
|
$command |
29
|
16 |
|
->setDescription('Creates a Foundry story') |
30
|
16 |
|
->addArgument('name', InputArgument::OPTIONAL, 'The name of the story class (e.g. <fg=yellow>DefaultCategoriesStory</>)') |
31
|
16 |
|
->addOption('test', null, InputOption::VALUE_NONE, 'Create in <fg=yellow>tests/</> instead of <fg=yellow>src/</>') |
32
|
|
|
; |
33
|
|
|
|
34
|
16 |
|
$inputConfig->setArgumentAsNonInteractive('name'); |
35
|
16 |
|
} |
36
|
|
|
|
37
|
16 |
|
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void |
38
|
|
|
{ |
39
|
16 |
|
if ($input->getArgument('name')) { |
40
|
8 |
|
return; |
41
|
|
|
} |
42
|
|
|
|
43
|
8 |
|
if (!$input->getOption('test')) { |
44
|
4 |
|
$io->text('// Note: pass <fg=yellow>--test</> if you want to generate stories in your <fg=yellow>tests/</> directory'); |
45
|
4 |
|
$io->newLine(); |
46
|
|
|
} |
47
|
|
|
|
48
|
8 |
|
$argument = $command->getDefinition()->getArgument('name'); |
49
|
8 |
|
$value = $io->ask($argument->getDescription(), $argument->getDefault(), [Validator::class, 'notBlank']); |
|
|
|
|
50
|
8 |
|
$input->setArgument($argument->getName(), $value); |
51
|
8 |
|
} |
52
|
|
|
|
53
|
16 |
|
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void |
54
|
|
|
{ |
55
|
16 |
|
$storyClassNameDetails = $generator->createClassNameDetails( |
56
|
16 |
|
$input->getArgument('name'), |
|
|
|
|
57
|
16 |
|
$input->getOption('test') ? 'Tests\\Story' : 'Story', |
58
|
16 |
|
'Story' |
59
|
|
|
); |
60
|
|
|
|
61
|
16 |
|
$generator->generateClass( |
62
|
16 |
|
$storyClassNameDetails->getFullName(), |
63
|
16 |
|
__DIR__.'/../Resources/skeleton/Story.tpl.php', |
64
|
16 |
|
[] |
65
|
|
|
); |
66
|
|
|
|
67
|
16 |
|
$generator->writeChanges(); |
68
|
|
|
|
69
|
16 |
|
$this->writeSuccessMessage($io); |
70
|
|
|
|
71
|
16 |
|
$io->text([ |
72
|
16 |
|
'Next: Open your story class and start customizing it.', |
73
|
|
|
'Find the documentation at https://github.com/zenstruck/foundry#stories', |
74
|
|
|
]); |
75
|
16 |
|
} |
76
|
|
|
|
77
|
16 |
|
public function configureDependencies(DependencyBuilder $dependencies): void |
78
|
|
|
{ |
79
|
|
|
// noop |
80
|
16 |
|
} |
81
|
|
|
} |
82
|
|
|
|