1 | <?php |
||
38 | class ImplementCommand extends GenericInlineConfigCommand implements InlineConfigCommandInterface |
||
39 | { |
||
40 | use |
||
41 | UsesInterfaceTrait, |
||
42 | UsesBehaviorTrait, |
||
43 | CommandTrait; |
||
44 | |||
45 | /** |
||
46 | * CONFIG |
||
47 | */ |
||
48 | public const NAME = 'behavior:implement'; |
||
49 | public const DESCRIPTION = 'Creates a Trait from a given Interface'; |
||
50 | public const HIDDEN = false; |
||
51 | public const USAGES = [ '@todo' ]; |
||
52 | public const HELP = <<<EOF |
||
53 | The <info>%command.name%</info> command creates an trait from a given interface: |
||
54 | <info>php %command.full_name% ClassName MethodName</info> |
||
55 | Will generate an example in the ClassNameSpec. |
||
56 | EOF; |
||
57 | |||
58 | public const ARGUMENTS = [ |
||
59 | self::INTERFACE_INPUT => [ |
||
60 | Config::MODE_KEY => InputArgument::REQUIRED, |
||
61 | Config::DESCRIPTION_KEY => 'Interface to create behavior for' |
||
62 | ], |
||
63 | self::TRAIT_INPUT => [ |
||
64 | Config::MODE_KEY => InputArgument::OPTIONAL, |
||
65 | Config::DESCRIPTION_KEY => 'Custom trait class name' |
||
66 | ] |
||
67 | ]; |
||
68 | |||
69 | public const OPTIONS = [ |
||
70 | self::FORCE_KEY => [ |
||
71 | Config::MODE_KEY => InputOption::VALUE_NONE, |
||
72 | Config::DESCRIPTION_KEY => 'Force creation of Trait without asking for confirmation', |
||
73 | Config::SHORTCUT_KEY => 'f' |
||
74 | ], |
||
75 | self::QUITE_KEY => [ |
||
76 | Config::MODE_KEY => InputOption::VALUE_NONE, |
||
77 | Config::DESCRIPTION_KEY => 'Force creation of Trait without asking for confirmation' |
||
78 | ] |
||
79 | ]; |
||
80 | |||
81 | protected const INTERFACE_CONFIRMATION_QUESTION = 'Interface %s? does not exist. Do you want to generate it?'; |
||
82 | protected const TRAIT_CONFIRMATION_QUESTION = 'Do you want to generate a Trait for Interface %s?'; |
||
83 | |||
84 | protected const INTERFACE_INPUT = 'interface'; |
||
85 | protected const TRAIT_INPUT = 'trait'; |
||
86 | |||
87 | protected const FORCE_KEY = 'force'; |
||
88 | protected const QUITE_KEY = 'quite'; |
||
89 | protected const INTERFACE_KEY = 'interface'; |
||
90 | |||
91 | protected const RESOURCE_MANAGER_ID = 'locator.resource_manager'; |
||
92 | protected const GENERATOR_MANAGER_ID = 'code_generator'; |
||
93 | |||
94 | /** |
||
95 | * @var string |
||
96 | */ |
||
97 | protected $interfaceName; |
||
98 | |||
99 | public function __construct(WriterInterface $writer, ConfiguratorInterface $configurator, $config = []) |
||
104 | |||
105 | /** |
||
106 | * @param InputInterface $input |
||
107 | * @param OutputInterface $output |
||
108 | * |
||
109 | * @return int|null |
||
110 | */ |
||
111 | protected function execute(InputInterface $input, OutputInterface $output) |
||
121 | |||
122 | /** |
||
123 | * @return bool |
||
124 | */ |
||
125 | private function confirmInterfaceGeneration() |
||
138 | |||
139 | /** |
||
140 | * @return object|ResourceManager |
||
141 | */ |
||
142 | protected function retrieveResourceManager() |
||
146 | |||
147 | /** |
||
148 | * @return object|GeneratorManager |
||
149 | */ |
||
150 | protected function retrieveGeneratorManager() |
||
154 | |||
155 | protected function ensureInterfaceExists() |
||
161 | |||
162 | protected function createInterface() |
||
171 | |||
172 | protected function getInterfaceInput(InputInterface $input) |
||
176 | |||
177 | protected function validateInterfaceInput() |
||
185 | |||
186 | /** |
||
187 | * @param string $interfaceName |
||
188 | */ |
||
189 | protected function setInterfaceName(string $interfaceName) |
||
193 | |||
194 | /** |
||
195 | * @return string |
||
196 | */ |
||
197 | protected function getInterfaceName(): string |
||
204 | } |
||
205 | |||
206 |