11
11
12
12
namespace Symfony \Component \Console ;
13
13
14
+ use Symfony \Component \Console \Command \CommandConfiguration ;
14
15
use Symfony \Component \Console \Descriptor \TextDescriptor ;
15
16
use Symfony \Component \Console \Descriptor \XmlDescriptor ;
16
17
use Symfony \Component \Console \Helper \DebugFormatterHelper ;
59
60
*/
60
61
class Application
61
62
{
63
+ /**
64
+ * @var CommandConfiguration[]
65
+ */
62
66
private $ commands = array ();
63
67
private $ wantHelps = false ;
64
68
private $ runningCommand ;
@@ -404,6 +408,32 @@ public function add(Command $command)
404
408
return $ command ;
405
409
}
406
410
411
+ /**
412
+ * Adds a command object.
413
+ *
414
+ * If a command with the same name already exists, it will be overridden.
415
+ *
416
+ * @param CommandConfiguration $commandConfiguration A command configuration
417
+ *
418
+ * @return CommandConfiguration The command configuration
419
+ *
420
+ * @api
421
+ */
422
+ public function addCommandConfiguration (CommandConfiguration $ commandConfiguration )
423
+ {
424
+ if (!$ commandConfiguration ->isEnabled ()) {
425
+ return $ commandConfiguration ;
426
+ }
427
+
428
+ $ this ->commands [$ commandConfiguration ->getName ()] = $ commandConfiguration ;
429
+
430
+ foreach ($ commandConfiguration ->getAliases () as $ alias ) {
431
+ $ this ->commands [$ alias ] = $ commandConfiguration ;
432
+ }
433
+
434
+ return $ commandConfiguration ;
435
+ }
436
+
407
437
/**
408
438
* Returns a registered command by name or alias.
409
439
*
@@ -422,12 +452,13 @@ public function get($name)
422
452
}
423
453
424
454
$ command = $ this ->commands [$ name ];
455
+ $ command = $ command ->getCommand ();
425
456
426
457
if ($ this ->wantHelps ) {
427
458
$ this ->wantHelps = false ;
428
459
429
460
$ helpCommand = $ this ->get ('help ' );
430
- $ helpCommand ->setCommand ($ command );
461
+ $ helpCommand ->setTargetCommand ($ command );
431
462
432
463
return $ helpCommand ;
433
464
}
@@ -583,13 +614,15 @@ public function find($name)
583
614
public function all ($ namespace = null )
584
615
{
585
616
if (null === $ namespace ) {
586
- return $ this ->commands ;
617
+ return array_map (function (CommandConfiguration $ commandConfiguration ) {
618
+ return $ commandConfiguration ->getCommand ();
619
+ }, $ this ->commands );
587
620
}
588
621
589
622
$ commands = array ();
590
- foreach ($ this ->commands as $ name => $ command ) {
623
+ foreach ($ this ->commands as $ name => $ commandConfiguration ) {
591
624
if ($ namespace === $ this ->extractNamespace ($ name , substr_count ($ namespace , ': ' ) + 1 )) {
592
- $ commands [$ name ] = $ command ;
625
+ $ commands [$ name ] = $ commandConfiguration -> getCommand () ;
593
626
}
594
627
}
595
628
0 commit comments