1 | <?php |
||
17 | class GenerateActionCommand extends AbstractKeekoCommand { |
||
18 | |||
19 | use ActionCommandHelperTrait; |
||
20 | |||
21 | protected function configure() { |
||
22 | $this |
||
23 | ->setName('generate:action') |
||
24 | ->setDescription('Generates an action') |
||
25 | 20 | ->addArgument( |
|
26 | 20 | 'name', |
|
27 | 20 | InputArgument::OPTIONAL, |
|
28 | 20 | 'The name of the action, which should be generated. Typically in the form %nomen%-%verb% (e.g. user-create)' |
|
29 | 20 | ) |
|
30 | 20 | ->addOption( |
|
31 | 20 | 'classname', |
|
32 | 'c', |
||
33 | 20 | InputOption::VALUE_OPTIONAL, |
|
34 | 20 | 'The class name (If ommited, class name will be guessed from action name)', |
|
35 | 20 | null |
|
36 | 20 | ) |
|
37 | 20 | ->addOption( |
|
38 | 20 | 'model', |
|
39 | 'm', |
||
40 | 20 | InputOption::VALUE_OPTIONAL, |
|
41 | 20 | 'The model for which the actions should be generated (if ommited all models will be generated)' |
|
42 | 20 | ) |
|
43 | 20 | ->addOption( |
|
44 | 20 | 'title', |
|
45 | '', |
||
46 | 20 | InputOption::VALUE_OPTIONAL, |
|
47 | 20 | 'The title for the generated option' |
|
48 | 20 | ) |
|
49 | 20 | ->addOption( |
|
50 | 20 | 'acl', |
|
51 | '', |
||
52 | 20 | InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, |
|
53 | 20 | 'The acl\'s for this action (Options are: guest, user, admin)' |
|
54 | 20 | ) |
|
55 | 20 | ; |
|
56 | 20 | ||
57 | $this->configureGenerateOptions(); |
||
58 | 20 | ||
59 | 20 | parent::configure(); |
|
60 | 20 | } |
|
61 | 20 | ||
62 | protected function initialize(InputInterface $input, OutputInterface $output) { |
||
63 | 20 | parent::initialize($input, $output); |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Checks whether actions can be generated at all by reading composer.json and verify |
||
68 | * all required information are available |
||
69 | */ |
||
70 | private function check() { |
||
76 | 20 | ||
77 | protected function interact(InputInterface $input, OutputInterface $output) { |
||
78 | $this->check(); |
||
83 | 10 | ||
84 | 10 | protected function execute(InputInterface $input, OutputInterface $output) { |
|
119 | |||
120 | /** |
||
121 | * Generates a skeleton action |
||
122 | * |
||
123 | * @param string $actionName |
||
124 | */ |
||
125 | private function generateSkeleton($actionName) { |
||
167 | |||
168 | 6 | /** |
|
169 | 2 | * Generates actions for a model |
|
170 | 2 | * |
|
171 | * @param Table $model |
||
172 | */ |
||
173 | 4 | private function generateModel(Table $model) { |
|
191 | 8 | ||
192 | /** |
||
193 | 5 | * Generates a model action |
|
194 | 5 | * |
|
195 | 5 | * @param Table $model |
|
196 | 5 | * @param string $type |
|
197 | 5 | */ |
|
198 | 1 | private function generateModelAction(Table $model, $type) { |
|
207 | 5 | ||
208 | 5 | /** |
|
209 | 4 | * Generates a relationship action |
|
210 | 5 | * |
|
211 | 5 | * @param Relationship $relationship |
|
212 | 5 | * @param string $type |
|
213 | */ |
||
214 | 5 | private function generateRelationshipAction(Relationship $relationship, $type) { |
|
223 | 4 | ||
224 | 4 | /** |
|
225 | 4 | * Generates an action |
|
226 | 4 | * |
|
227 | * @param Table|Relationship $object |
||
228 | * @param string $type |
||
229 | * @return ActionSchema |
||
230 | */ |
||
231 | private function generateAction($object, $type) { |
||
245 | } |
||
246 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: