File tree 3 files changed +53
-11
lines changed
3 files changed +53
-11
lines changed Original file line number Diff line number Diff line change 14
14
}
15
15
],
16
16
"require" : {
17
- "php" : " ^7.2"
17
+ "php" : " ^7.2" ,
18
+ "psr/container" : " ^1.0"
18
19
},
19
20
"require-dev" : {
20
21
"phpunit/phpunit" : " ^7.5" ,
Original file line number Diff line number Diff line change 2
2
3
3
declare (strict_types=1 );
4
4
5
- /**
6
- * This file is part of Narration Framework.
7
- *
8
- * (c) Nuno Maduro <[email protected] >
9
- *
10
- * For the full copyright and license information, please view the LICENSE
11
- * file that was distributed with this source code.
12
- */
13
-
14
5
namespace Narration \Console ;
15
6
16
7
use Symfony \Component \Console \Application ;
@@ -38,7 +29,7 @@ private function __construct(Application $application)
38
29
*
39
30
* @return \Narration\Console\Kernel
40
31
*/
41
- public static function withCommands ( array $ commands ): self
32
+ public static function using ( Router $ router ): self
42
33
{
43
34
$ application = new Application ('Narrative ' , '@dev ' );
44
35
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Narration \Console ;
6
+
7
+ use Symfony \Component \Console \Application ;
8
+ use Symfony \Component \Console \Input \InputInterface ;
9
+
10
+ final class Router
11
+ {
12
+ /**
13
+ * @var \Psr\Container\ContainerInterface
14
+ */
15
+ private $ container ;
16
+
17
+ /**
18
+ * @var array
19
+ */
20
+ private $ commands ;
21
+
22
+ /**
23
+ * Router constructor.
24
+ *
25
+ * @param \Psr\Container\ContainerInterface $container
26
+ */
27
+ public function __construct (ContainerInterface $ container )
28
+ {
29
+ $ this ->container = $ container ;
30
+ }
31
+
32
+ /**
33
+ * @param string $name
34
+ * @param callable $callable
35
+ */
36
+ public function command (string $ name , callable $ callable ): void
37
+ {
38
+ $ instance = $ this ->container ->get ($ callable );
39
+
40
+ $ this ->commands [] = new InvokableCommand ($ name , $ instance );
41
+ }
42
+
43
+ /**
44
+ * @return array
45
+ */
46
+ public function getCommands (): array
47
+ {
48
+ return $ this ->commands ;
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments