1
|
|
|
<?php namespace Comodojo\Dispatcher\Router; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Dispatcher\Components\Model as DispatcherClassModel; |
4
|
|
|
use \Comodojo\Dispatcher\Router\Model as Router; |
5
|
|
|
use \Comodojo\Dispatcher\Request\Model as Request; |
6
|
|
|
use \Comodojo\Dispatcher\Response\Model as Response; |
7
|
|
|
use \Comodojo\Dispatcher\Extra\Model as Extra; |
8
|
|
|
use \Comodojo\Dispatcher\Components\Timestamp as TimestampTrait; |
9
|
|
|
use \Comodojo\Exception\DispatcherException; |
10
|
|
|
use \Exception; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @package Comodojo Dispatcher |
14
|
|
|
* @author Marco Giovinazzi <[email protected]> |
15
|
|
|
* @author Marco Castiello <[email protected]> |
16
|
|
|
* @license GPL-3.0+ |
17
|
|
|
* |
18
|
|
|
* LICENSE: |
19
|
|
|
* |
20
|
|
|
* This program is free software: you can redistribute it and/or modify |
21
|
|
|
* it under the terms of the GNU Affero General Public License as |
22
|
|
|
* published by the Free Software Foundation, either version 3 of the |
23
|
|
|
* License, or (at your option) any later version. |
24
|
|
|
* |
25
|
|
|
* This program is distributed in the hope that it will be useful, |
26
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
27
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
28
|
|
|
* GNU Affero General Public License for more details. |
29
|
|
|
* |
30
|
|
|
* You should have received a copy of the GNU Affero General Public License |
31
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
class Route extends DispatcherClassModel { |
35
|
|
|
|
36
|
|
|
use TimestampTrait; |
37
|
|
|
|
38
|
|
|
private $bypass = false; |
|
|
|
|
39
|
|
|
|
40
|
|
|
private $classname = ""; |
41
|
|
|
|
42
|
|
|
private $type = ""; |
43
|
|
|
|
44
|
|
|
private $service = ""; |
45
|
|
|
|
46
|
|
|
private $router = null; |
47
|
|
|
|
48
|
|
|
public function __construct( |
49
|
|
|
Router $router |
50
|
|
|
) { |
51
|
|
|
|
52
|
|
|
parent::__construct($router->configuration(), $router->logger()); |
53
|
|
|
|
54
|
|
|
$this->router = $router; |
55
|
|
|
|
56
|
|
|
$this->setTimestamp(); |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getType() { |
61
|
|
|
|
62
|
|
|
return $this->type; |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function setType($type) { |
67
|
|
|
|
68
|
|
|
$this->type = $type; |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getService() { |
75
|
|
|
|
76
|
|
|
return $this->service; |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function setService($service) { |
81
|
|
|
|
82
|
|
|
$this->service = $service; |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getClassName() { |
89
|
|
|
|
90
|
|
|
return $this->classname; |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setClassName($class) { |
95
|
|
|
|
96
|
|
|
$this->classname = $class; |
97
|
|
|
|
98
|
|
|
return $this; |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getInstance( |
103
|
|
|
Request $request, |
104
|
|
|
Response $response, |
105
|
|
|
Extra $extra |
106
|
|
|
) { |
107
|
|
|
|
108
|
|
|
$class = $this->classname; |
109
|
|
|
|
110
|
|
|
if (class_exists($class)) { |
111
|
|
|
|
112
|
|
|
return new $class( |
113
|
|
|
$this->configuration, |
114
|
|
|
$this->logger, |
115
|
|
|
$request, |
116
|
|
|
$this->router, |
117
|
|
|
$response, |
118
|
|
|
$extra |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
else return null; |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.