|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zapheus\Bridge\Slytherin; |
|
4
|
|
|
|
|
5
|
|
|
use Rougin\Slytherin\Routing\Router; |
|
6
|
|
|
use Rougin\Slytherin\Routing\RouterInterface; |
|
7
|
|
|
use Zapheus\Container\WritableInterface; |
|
8
|
|
|
use Zapheus\Provider\ProviderInterface; |
|
9
|
|
|
use Zapheus\Routing\Route; |
|
10
|
|
|
use Zapheus\Routing\Router as ZapheusRouter; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Routing Provider |
|
14
|
|
|
* |
|
15
|
|
|
* @package App |
|
16
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class RoutingProvider implements ProviderInterface |
|
19
|
|
|
{ |
|
20
|
|
|
const SLYTHERIN_CONTAINER = 'Rougin\Slytherin\Container\Container'; |
|
21
|
|
|
|
|
22
|
|
|
const SLYTHERIN_ROUTER = 'Rougin\Slytherin\Routing\RouterInterface'; |
|
23
|
|
|
|
|
24
|
|
|
const ZAPHEUS_ROUTER = 'Zapheus\Routing\RouterInterface'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var \Rougin\Slytherin\Routing\RouterInterface|null |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $router; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Initializes the provider instance. |
|
33
|
|
|
* |
|
34
|
|
|
* @param \Rougin\Slytherin\Routing\RouterInterface|null $router |
|
35
|
|
|
*/ |
|
36
|
3 |
|
public function __construct(RouterInterface $router = null) |
|
37
|
|
|
{ |
|
38
|
3 |
|
$this->router = $router; |
|
39
|
3 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Registers the bindings in the container. |
|
43
|
|
|
* |
|
44
|
|
|
* @param \Zapheus\Container\WritableInterface $container |
|
45
|
|
|
* @return \Zapheus\Container\ContainerInterface |
|
46
|
|
|
*/ |
|
47
|
3 |
|
public function register(WritableInterface $container) |
|
48
|
|
|
{ |
|
49
|
3 |
|
$zapheus = new ZapheusRouter; |
|
50
|
|
|
|
|
51
|
3 |
|
$router = $this->router; |
|
52
|
|
|
|
|
53
|
3 |
|
if ($this->router === null) { |
|
54
|
3 |
|
$slytherin = $container->get(self::SLYTHERIN_CONTAINER); |
|
55
|
|
|
|
|
56
|
3 |
|
$router = $slytherin->get(self::SLYTHERIN_ROUTER); |
|
57
|
2 |
|
} |
|
58
|
|
|
|
|
59
|
3 |
|
foreach ((array) $router->routes() as $route) { |
|
60
|
3 |
|
list($method, $uri, $handler) = (array) $route; |
|
61
|
|
|
|
|
62
|
3 |
|
$zapheus->add(new Route($method, $uri, $handler)); |
|
63
|
2 |
|
} |
|
64
|
|
|
|
|
65
|
3 |
|
return $container->set(self::ZAPHEUS_ROUTER, $zapheus); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|