1 | <?php namespace Simondubois\UnsplashDownloader; |
||
14 | class Command extends SymfonyCommand |
||
15 | { |
||
16 | |||
17 | // |
||
18 | // Constants & Attributes |
||
19 | // |
||
20 | const DESCRIPTION_DESTINATION = 'Directory where to download photos.'; |
||
21 | const DESCRIPTION_QUANTITY = 'Number of photos to download.'; |
||
22 | const DESCRIPTION_HISTORY = 'Filename to use as download history. |
||
23 | When photos are downloaded, their IDs will be stored into the file. |
||
24 | Then any further download is going to ignore photos that have their ID in the history. |
||
25 | Usefull to delete unwanted pictures and prevent the CLI to download them again.'; |
||
26 | const DESCRIPTION_FEATURED = 'Download only featured photos (incompatible with --category).'; |
||
27 | const DESCRIPTION_CATEGORIES = 'Print out categories and quit (no download).'; |
||
28 | const DESCRIPTION_CATEGORY = 'Only download photos for the given category ID (incompatible with the --featured).'; |
||
29 | /** |
||
30 | * Output instance. |
||
31 | * Stored to simplify method calls and to be used in callbacks. |
||
32 | * @var OutputInterface |
||
33 | */ |
||
34 | public $output; |
||
35 | |||
36 | |||
37 | |||
38 | // |
||
39 | // Helpers |
||
40 | // |
||
41 | |||
42 | /** |
||
43 | * Output text only if run with verbose attribute |
||
44 | * @param string $message Text to output |
||
45 | * @param string|null $context Context of the message |
||
46 | * @param int $type Symfony output type |
||
47 | */ |
||
48 | 2 | public function verboseOutput($message, $context = null, $type = OutputInterface::OUTPUT_NORMAL) { |
|
66 | |||
67 | |||
68 | |||
69 | /** |
||
70 | * Output text only if run with verbose attribute |
||
71 | * @param string $message Text to output |
||
72 | * @param string|null $context Context of the message |
||
73 | * @param int $type Symfony output type |
||
74 | */ |
||
75 | 1 | public function output($message, $context = null, $type = OutputInterface::OUTPUT_NORMAL) { |
|
93 | |||
94 | |||
95 | |||
96 | // |
||
97 | // Handle command setup |
||
98 | // |
||
99 | |||
100 | /** |
||
101 | * Configure the Symfony command |
||
102 | */ |
||
103 | 6 | protected function configure() |
|
109 | |||
110 | /** |
||
111 | * Set command options |
||
112 | */ |
||
113 | 6 | private function configureOptions() |
|
122 | |||
123 | |||
124 | |||
125 | // |
||
126 | // Handle command operations |
||
127 | // |
||
128 | |||
129 | /** |
||
130 | * Process the download based on provided options |
||
131 | * @param InputInterface $input Command input |
||
132 | * @param OutputInterface $output Command output |
||
133 | */ |
||
134 | 2 | public function execute(InputInterface $input, OutputInterface $output) |
|
150 | |||
151 | /** |
||
152 | * Instantiate a new task |
||
153 | * @return Task Task instance |
||
154 | */ |
||
155 | 1 | public function task() { |
|
156 | 1 | $task = new Task(); |
|
157 | 1 | $task->setNotificationCallback([$this, 'output']); |
|
158 | |||
159 | 1 | return $task; |
|
160 | } |
||
161 | |||
162 | /** |
||
163 | * Check & validate the parameters |
||
164 | * @param Validate $validate Validate instance |
||
165 | * @param Task $task Download task |
||
166 | * @param array $options Command options |
||
167 | */ |
||
168 | 1 | public function parameters(Validate $validate, Task $task, $options) |
|
176 | |||
177 | /** |
||
178 | * Check & validate the destination parameter |
||
179 | * @param Validate $validate Validate instance |
||
180 | * @param Task $task Download task |
||
181 | * @param string $option Option value |
||
182 | */ |
||
183 | 1 | public function destinationParameter(Validate $validate, Task $task, $option) |
|
191 | |||
192 | /** |
||
193 | * Check & validate the quantity parameter |
||
194 | * @param Validate $validate Validate instance |
||
195 | * @param Task $task Download task |
||
196 | * @param string $option Option value |
||
197 | */ |
||
198 | 1 | public function quantityParameter(Validate $validate, Task $task, $option) |
|
206 | |||
207 | /** |
||
208 | * Check & validate the history parameter |
||
209 | * @param Validate $validate Validate instance |
||
210 | * @param Task $task Download task |
||
211 | * @param string $option Option value |
||
212 | */ |
||
213 | 1 | public function historyParameter(Validate $validate, Task $task, $option) |
|
226 | |||
227 | /** |
||
228 | * Check & validate the featured parameter |
||
229 | * @param Task $task Download task |
||
230 | * @param bool $option Option value |
||
231 | */ |
||
232 | 1 | public function featuredParameter(Task $task, $option) |
|
242 | |||
243 | /** |
||
244 | * Check & validate the category parameter |
||
245 | * @param Validate $validate Validate instance |
||
246 | * @param Task $task Download task |
||
247 | * @param string $option Option value |
||
248 | */ |
||
249 | 1 | public function categoryParameter(Validate $validate, Task $task, $option) |
|
259 | |||
260 | } |
||
261 |