Skip to content

Commit 973ff7a

Browse files
committed
wip
1 parent 44d3c68 commit 973ff7a

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.2"
17+
"php": "^7.2",
18+
"psr/container": "^1.0"
1819
},
1920
"require-dev": {
2021
"phpunit/phpunit": "^7.5",

src/Kernel.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
declare(strict_types=1);
44

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-
145
namespace Narration\Console;
156

167
use Symfony\Component\Console\Application;
@@ -38,7 +29,7 @@ private function __construct(Application $application)
3829
*
3930
* @return \Narration\Console\Kernel
4031
*/
41-
public static function withCommands(array $commands): self
32+
public static function using(Router $router): self
4233
{
4334
$application = new Application('Narrative', '@dev');
4435

src/Router.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

0 commit comments

Comments
 (0)