1
1
<?php
2
2
3
- namespace Symfony \Components \CLI \Task ;
3
+ namespace Symfony \Components \CLI \Command ;
4
4
5
5
use Symfony \Components \CLI \Input \Definition ;
6
6
use Symfony \Components \CLI \Input \Option ;
20
20
*/
21
21
22
22
/**
23
- * Base class for all tasks .
23
+ * Base class for all commands .
24
24
*
25
25
* @package symfony
26
26
* @subpackage cli
27
27
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
28
28
*/
29
- class Task
29
+ class Command
30
30
{
31
31
protected $ name ;
32
32
protected $ namespace ;
@@ -60,12 +60,12 @@ public function __construct($name = null)
60
60
61
61
if (!$ this ->name )
62
62
{
63
- throw new \LogicException ('The task name cannot be empty. ' );
63
+ throw new \LogicException ('The command name cannot be empty. ' );
64
64
}
65
65
}
66
66
67
67
/**
68
- * Sets the application instance for this task .
68
+ * Sets the application instance for this command .
69
69
*
70
70
* @param Application $application An Application instance
71
71
*/
@@ -75,14 +75,14 @@ public function setApplication(Application $application = null)
75
75
}
76
76
77
77
/**
78
- * Configures the current task .
78
+ * Configures the current command .
79
79
*/
80
80
protected function configure ()
81
81
{
82
82
}
83
83
84
84
/**
85
- * Executes the current task .
85
+ * Executes the current command .
86
86
*
87
87
* @param InputInterface $input An InputInterface instance
88
88
* @param OutputInterface $output An OutputInterface instance
@@ -91,7 +91,7 @@ protected function configure()
91
91
*/
92
92
protected function execute (InputInterface $ input , OutputInterface $ output )
93
93
{
94
- throw new \LogicException ('You must override the execute() method in the concrete task class. ' );
94
+ throw new \LogicException ('You must override the execute() method in the concrete command class. ' );
95
95
}
96
96
97
97
/**
@@ -109,7 +109,7 @@ public function run(InputInterface $input, OutputInterface $output)
109
109
// add the application arguments and options
110
110
$ this ->mergeApplicationDefinition ();
111
111
112
- // bind the input against the task specific arguments/options
112
+ // bind the input against the command specific arguments/options
113
113
try
114
114
{
115
115
$ input ->bind ($ this ->definition );
@@ -140,11 +140,11 @@ public function run(InputInterface $input, OutputInterface $output)
140
140
}
141
141
142
142
/**
143
- * Sets the code to execute when running this task .
143
+ * Sets the code to execute when running this command .
144
144
*
145
145
* @param \Closure $code A \Closure
146
146
*
147
- * @return Task The current instance
147
+ * @return Command The current instance
148
148
*/
149
149
public function setCode (\Closure $ code )
150
150
{
@@ -154,7 +154,7 @@ public function setCode(\Closure $code)
154
154
}
155
155
156
156
/**
157
- * Merges the application definition with the task definition.
157
+ * Merges the application definition with the command definition.
158
158
*/
159
159
protected function mergeApplicationDefinition ()
160
160
{
@@ -178,7 +178,7 @@ protected function mergeApplicationDefinition()
178
178
*
179
179
* @param array|Definition $definition An array of argument and option instances or a definition instance
180
180
*
181
- * @return Task The current instance
181
+ * @return Command The current instance
182
182
*/
183
183
public function setDefinition ($ definition )
184
184
{
@@ -204,7 +204,7 @@ public function setDefinition($definition)
204
204
* @param string $description A description text
205
205
* @param mixed $default The default value (for Argument::OPTIONAL mode only)
206
206
*
207
- * @return Task The current instance
207
+ * @return Command The current instance
208
208
*/
209
209
public function addArgument ($ name , $ mode = null , $ description = '' , $ default = null )
210
210
{
@@ -222,7 +222,7 @@ public function addArgument($name, $mode = null, $description = '', $default = n
222
222
* @param string $description A description text
223
223
* @param mixed $default The default value (must be null for self::PARAMETER_REQUIRED or self::PARAMETER_NONE)
224
224
*
225
- * @return Task The current instance
225
+ * @return Command The current instance
226
226
*/
227
227
public function addOption ($ name , $ shortcut = null , $ mode = null , $ description = '' , $ default = null )
228
228
{
@@ -232,16 +232,16 @@ public function addOption($name, $shortcut = null, $mode = null, $description =
232
232
}
233
233
234
234
/**
235
- * Sets the name of the task .
235
+ * Sets the name of the command .
236
236
*
237
237
* This method can set both the namespace and the name if
238
238
* you separate them by a colon (:)
239
239
*
240
- * $task ->setName('foo:bar');
240
+ * $command ->setName('foo:bar');
241
241
*
242
- * @param string $name The task name
242
+ * @param string $name The command name
243
243
*
244
- * @return Task The current instance
244
+ * @return Command The current instance
245
245
*/
246
246
public function setName ($ name )
247
247
{
@@ -257,7 +257,7 @@ public function setName($name)
257
257
258
258
if (!$ name )
259
259
{
260
- throw new \InvalidArgumentException ('A task name cannot be empty ' );
260
+ throw new \InvalidArgumentException ('A command name cannot be empty ' );
261
261
}
262
262
263
263
$ this ->namespace = $ namespace ;
@@ -267,41 +267,41 @@ public function setName($name)
267
267
}
268
268
269
269
/**
270
- * Returns the task namespace.
270
+ * Returns the command namespace.
271
271
*
272
- * @return string The task namespace
272
+ * @return string The command namespace
273
273
*/
274
274
public function getNamespace ()
275
275
{
276
276
return $ this ->namespace ;
277
277
}
278
278
279
279
/**
280
- * Returns the task name
280
+ * Returns the command name
281
281
*
282
- * @return string The task name
282
+ * @return string The command name
283
283
*/
284
284
public function getName ()
285
285
{
286
286
return $ this ->name ;
287
287
}
288
288
289
289
/**
290
- * Returns the fully qualified task name.
290
+ * Returns the fully qualified command name.
291
291
*
292
- * @return string The fully qualified task name
292
+ * @return string The fully qualified command name
293
293
*/
294
294
public function getFullName ()
295
295
{
296
296
return $ this ->getNamespace () ? $ this ->getNamespace ().': ' .$ this ->getName () : $ this ->getName ();
297
297
}
298
298
299
299
/**
300
- * Sets the description for the task .
300
+ * Sets the description for the command .
301
301
*
302
- * @param string $description The description for the task
302
+ * @param string $description The description for the command
303
303
*
304
- * @return Task The current instance
304
+ * @return Command The current instance
305
305
*/
306
306
public function setDescription ($ description )
307
307
{
@@ -311,21 +311,21 @@ public function setDescription($description)
311
311
}
312
312
313
313
/**
314
- * Returns the description for the task .
314
+ * Returns the description for the command .
315
315
*
316
- * @return string The description for the task
316
+ * @return string The description for the command
317
317
*/
318
318
public function getDescription ()
319
319
{
320
320
return $ this ->description ;
321
321
}
322
322
323
323
/**
324
- * Sets the help for the task .
324
+ * Sets the help for the command .
325
325
*
326
- * @param string $help The help for the task
326
+ * @param string $help The help for the command
327
327
*
328
- * @return Task The current instance
328
+ * @return Command The current instance
329
329
*/
330
330
public function setHelp ($ help )
331
331
{
@@ -335,21 +335,21 @@ public function setHelp($help)
335
335
}
336
336
337
337
/**
338
- * Returns the help for the task .
338
+ * Returns the help for the command .
339
339
*
340
- * @return string The help for the task
340
+ * @return string The help for the command
341
341
*/
342
342
public function getHelp ()
343
343
{
344
344
return $ this ->help ;
345
345
}
346
346
347
347
/**
348
- * Sets the aliases for the task .
348
+ * Sets the aliases for the command .
349
349
*
350
- * @param array $aliases An array of aliases for the task
350
+ * @param array $aliases An array of aliases for the command
351
351
*
352
- * @return Task The current instance
352
+ * @return Command The current instance
353
353
*/
354
354
public function setAliases ($ aliases )
355
355
{
@@ -359,17 +359,17 @@ public function setAliases($aliases)
359
359
}
360
360
361
361
/**
362
- * Returns the aliases for the task .
362
+ * Returns the aliases for the command .
363
363
*
364
- * @return array An array of aliases for the task
364
+ * @return array An array of aliases for the command
365
365
*/
366
366
public function getAliases ()
367
367
{
368
368
return $ this ->aliases ;
369
369
}
370
370
371
371
/**
372
- * Returns the synopsis for the task .
372
+ * Returns the synopsis for the command .
373
373
*
374
374
* @return string The synopsis
375
375
*/
@@ -466,9 +466,9 @@ static public function askAndValidate(OutputInterface $output, $question, \Closu
466
466
}
467
467
468
468
/**
469
- * Returns a text representation of the task .
469
+ * Returns a text representation of the command .
470
470
*
471
- * @return string A string representing the task
471
+ * @return string A string representing the command
472
472
*/
473
473
public function asText ()
474
474
{
@@ -495,41 +495,41 @@ public function asText()
495
495
}
496
496
497
497
/**
498
- * Returns an XML representation of the task .
498
+ * Returns an XML representation of the command .
499
499
*
500
500
* @param Boolean $asDom Whether to return a DOM or an XML string
501
501
*
502
- * @return string|DOMDocument An XML string representing the task
502
+ * @return string|DOMDocument An XML string representing the command
503
503
*/
504
504
public function asXml ($ asDom = false )
505
505
{
506
506
$ dom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
507
507
$ dom ->formatOutput = true ;
508
- $ dom ->appendChild ($ taskXML = $ dom ->createElement ('task ' ));
509
- $ taskXML ->setAttribute ('id ' , $ this ->getFullName ());
510
- $ taskXML ->setAttribute ('namespace ' , $ this ->getNamespace () ? $ this ->getNamespace () : '_global ' );
511
- $ taskXML ->setAttribute ('name ' , $ this ->getName ());
508
+ $ dom ->appendChild ($ commandXML = $ dom ->createElement ('command ' ));
509
+ $ commandXML ->setAttribute ('id ' , $ this ->getFullName ());
510
+ $ commandXML ->setAttribute ('namespace ' , $ this ->getNamespace () ? $ this ->getNamespace () : '_global ' );
511
+ $ commandXML ->setAttribute ('name ' , $ this ->getName ());
512
512
513
- $ taskXML ->appendChild ($ usageXML = $ dom ->createElement ('usage ' ));
513
+ $ commandXML ->appendChild ($ usageXML = $ dom ->createElement ('usage ' ));
514
514
$ usageXML ->appendChild ($ dom ->createTextNode (sprintf ($ this ->getSynopsis (), '' )));
515
515
516
- $ taskXML ->appendChild ($ descriptionXML = $ dom ->createElement ('description ' ));
516
+ $ commandXML ->appendChild ($ descriptionXML = $ dom ->createElement ('description ' ));
517
517
$ descriptionXML ->appendChild ($ dom ->createTextNode (implode ("\n " , explode ("\n" , $ this ->getDescription ()))));
518
518
519
- $ taskXML ->appendChild ($ helpXML = $ dom ->createElement ('help ' ));
519
+ $ commandXML ->appendChild ($ helpXML = $ dom ->createElement ('help ' ));
520
520
$ help = $ this ->help ;
521
521
$ helpXML ->appendChild ($ dom ->createTextNode (implode ("\n " , explode ("\n" , $ help ))));
522
522
523
- $ taskXML ->appendChild ($ aliasesXML = $ dom ->createElement ('aliases ' ));
523
+ $ commandXML ->appendChild ($ aliasesXML = $ dom ->createElement ('aliases ' ));
524
524
foreach ($ this ->getAliases () as $ alias )
525
525
{
526
526
$ aliasesXML ->appendChild ($ aliasXML = $ dom ->createElement ('alias ' ));
527
527
$ aliasXML ->appendChild ($ dom ->createTextNode ($ alias ));
528
528
}
529
529
530
530
$ definition = $ this ->definition ->asXml (true );
531
- $ taskXML ->appendChild ($ dom ->importNode ($ definition ->getElementsByTagName ('arguments ' )->item (0 ), true ));
532
- $ taskXML ->appendChild ($ dom ->importNode ($ definition ->getElementsByTagName ('options ' )->item (0 ), true ));
531
+ $ commandXML ->appendChild ($ dom ->importNode ($ definition ->getElementsByTagName ('arguments ' )->item (0 ), true ));
532
+ $ commandXML ->appendChild ($ dom ->importNode ($ definition ->getElementsByTagName ('options ' )->item (0 ), true ));
533
533
534
534
return $ asDom ? $ dom : $ dom ->saveXml ();
535
535
}
0 commit comments