|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Joesama\Pintu\Routings; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
|
6
|
|
|
use Illuminate\Routing\Router; |
|
7
|
|
|
use Joesama\Pintu\Routings\Builder; |
|
8
|
|
|
use Joesama\Pintu\Components\Manager as ComponentManager; |
|
9
|
|
|
|
|
10
|
|
|
class Manager |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Collection of API definition. |
|
14
|
|
|
* |
|
15
|
|
|
* @var ComponentManager |
|
16
|
|
|
*/ |
|
17
|
|
|
private $component; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Default controller namespaces. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $namespace; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initialize routes manager. |
|
28
|
|
|
* |
|
29
|
|
|
* @param ComponentManager $component |
|
30
|
|
|
*/ |
|
31
|
3 |
|
public function __construct(ComponentManager $component) |
|
32
|
|
|
{ |
|
33
|
3 |
|
$this->component = $component; |
|
34
|
3 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Build the routing. |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
2 |
|
public function routingRegistration(Router $router) |
|
42
|
|
|
{ |
|
43
|
2 |
|
$builder = new Builder($router); |
|
44
|
|
|
|
|
45
|
2 |
|
$builder->componentRouting($this->component->getComponent(), $this->getComponentNameSpace()); |
|
46
|
|
|
|
|
47
|
2 |
|
if ($this->component->getLanding()) { |
|
48
|
|
|
$builder->landingRouting($this->getComponentNameSpace()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
2 |
|
$builder->apiRouting($this->component->getApi(), $this->getApiNameSpace()); |
|
52
|
2 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Set default namespace. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string|null $namespace |
|
58
|
|
|
* |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
3 |
|
public function setNameSpace(string $namespace = null) |
|
62
|
|
|
{ |
|
63
|
3 |
|
$this->namespace = $namespace; |
|
64
|
3 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get component controller namespace. |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
3 |
|
public function getComponentNameSpace(): string |
|
72
|
|
|
{ |
|
73
|
3 |
|
if ($this->namespace === null) { |
|
74
|
3 |
|
return Arr::get($this->component->getComponentNameSpace(), 'component'); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
1 |
|
return $this->namespace; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get API controller namespace. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
3 |
|
public function getApiNameSpace(): string |
|
86
|
|
|
{ |
|
87
|
3 |
|
if ($this->namespace === null) { |
|
88
|
3 |
|
return Arr::get($this->component->getComponentNameSpace(), 'api'); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
return $this->namespace; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|