1 | <?php |
||
27 | class GenerateController extends Command |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $controllerName; |
||
34 | |||
35 | /** |
||
36 | * @var InputInterface |
||
37 | */ |
||
38 | protected $input; |
||
39 | |||
40 | /** |
||
41 | * @var OutputInterface |
||
42 | */ |
||
43 | protected $output; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $path; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $namespace; |
||
54 | |||
55 | /** |
||
56 | * @var string|null |
||
57 | */ |
||
58 | protected $entityName; |
||
59 | |||
60 | /** |
||
61 | * @var CreateController |
||
62 | */ |
||
63 | protected $controllerGenerator; |
||
64 | |||
65 | /** |
||
66 | * Configures the current command. |
||
67 | */ |
||
68 | 10 | protected function configure() |
|
69 | { |
||
70 | 5 | $this |
|
71 | 10 | ->setName("generate:controller") |
|
72 | 10 | ->setDescription("Generate a controller class file.") |
|
73 | 10 | ->addArgument( |
|
74 | 10 | 'controllerName', |
|
75 | 10 | InputArgument::REQUIRED, |
|
76 | 5 | 'Controller class name.' |
|
77 | 5 | ) |
|
78 | 10 | ->addOption( |
|
79 | 10 | 'entity-name', |
|
80 | 10 | 'e', |
|
81 | 10 | InputOption::VALUE_OPTIONAL, |
|
82 | 5 | 'Creates a CRUD controller for provided entity.' |
|
83 | 5 | ) |
|
84 | 10 | ->addOption( |
|
85 | 10 | 'source-path', |
|
86 | 10 | 'p', |
|
87 | 10 | InputOption::VALUE_OPTIONAL, |
|
88 | 10 | 'Sets the application source path', |
|
89 | 10 | getcwd().'/src' |
|
90 | 5 | ) |
|
91 | 10 | ->addOption( |
|
92 | 10 | 'name-space', |
|
93 | 10 | 'o', |
|
94 | 10 | InputOption::VALUE_OPTIONAL, |
|
95 | 10 | 'The controller namespace.', |
|
96 | 5 | 'Controller' |
|
97 | 5 | ) |
|
98 | ; |
||
99 | 10 | } |
|
100 | |||
101 | /** |
||
102 | * Executes the current command. |
||
103 | * |
||
104 | * This method is not abstract because you can use this class |
||
105 | * as a concrete class. In this case, instead of defining the |
||
106 | * execute() method, you set the code to execute by passing |
||
107 | * a Closure to the setCode() method. |
||
108 | * |
||
109 | * @param InputInterface $input An InputInterface instance |
||
110 | * @param OutputInterface $output An OutputInterface instance |
||
111 | * |
||
112 | * @return null|integer null or 0 if everything went fine, or an error code |
||
113 | * |
||
114 | * @throws \LogicException When this abstract method is not implemented |
||
115 | * @see setCode() |
||
116 | */ |
||
117 | 2 | protected function execute(InputInterface $input, OutputInterface $output) |
|
118 | { |
||
119 | 2 | $this->setInput($input)->setOutput($output); |
|
120 | 2 | $output->writeln('Slick MVC <info>v1.2.0</info>'); |
|
121 | 2 | $result = $this->getControllerGenerator() |
|
122 | 2 | ->setInput($input) |
|
123 | 2 | ->setOutput($output) |
|
124 | 2 | ->setCommand($this) |
|
125 | 2 | ->run(); |
|
126 | 2 | $output->writeln('<info>...Done!</info>'); |
|
127 | 2 | return $result; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * Gets controllerName property |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | 6 | public function getControllerName() |
|
142 | |||
143 | /** |
||
144 | * Gets path property |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | 6 | public function getPath() |
|
149 | { |
||
150 | 6 | if (null == $this->path) { |
|
151 | 6 | $this->path = $this->input->getOption('source-path'); |
|
152 | 6 | if (!is_dir($this->path)) { |
|
153 | 2 | throw new FileNotFoundException( |
|
154 | 1 | "The provided path was not found in your system." |
|
155 | 1 | ); |
|
156 | } |
||
157 | 2 | } |
|
158 | 4 | return $this->path; |
|
159 | } |
||
160 | |||
161 | /** |
||
162 | * Get controller namespace |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | 4 | public function getNameSpace() |
|
173 | |||
174 | /** |
||
175 | * Get the entity name |
||
176 | * |
||
177 | * @return null|string |
||
178 | */ |
||
179 | 6 | public function getEntityName() |
|
186 | |||
187 | /** |
||
188 | * Gets controllerGenerator property |
||
189 | * |
||
190 | * @return CreateController |
||
191 | */ |
||
192 | 8 | public function getControllerGenerator() |
|
207 | |||
208 | /** |
||
209 | * Sets controllerGenerator property |
||
210 | * |
||
211 | * @param CreateController $controllerGenerator |
||
212 | * |
||
213 | * @return GenerateController |
||
214 | */ |
||
215 | 6 | public function setControllerGenerator( |
|
221 | |||
222 | /** |
||
223 | * Sets input property |
||
224 | * |
||
225 | * @param InputInterface $input |
||
226 | * |
||
227 | * @return GenerateController |
||
228 | */ |
||
229 | 8 | public function setInput(InputInterface $input) |
|
234 | |||
235 | /** |
||
236 | * Sets output property |
||
237 | * |
||
238 | * @param OutputInterface $output |
||
239 | * |
||
240 | * @return GenerateController |
||
241 | */ |
||
242 | 8 | public function setOutput(OutputInterface $output) |
|
247 | |||
248 | /** |
||
249 | * Gets the task for this command |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | 6 | protected function getTaskClass() |
|
264 | |||
265 | } |