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