1 | <?php namespace Comodojo\Dispatcher\Router; |
||
35 | class Table extends AbstractModel { |
||
36 | |||
37 | protected $mode = self::PROTECTDATA; |
||
38 | |||
39 | 1 | public function __construct( |
|
40 | Cache $cache, |
||
41 | Router $router |
||
42 | ) { |
||
43 | |||
44 | 1 | parent::__construct($router->configuration, $router->logger); |
|
45 | |||
46 | 1 | $this->setRaw('routes', []); |
|
47 | 1 | $this->setRaw('router', $router); |
|
48 | 1 | $this->setRaw('parser', new Parser($this->logger)); |
|
49 | 1 | $this->setRaw('cache', new RouterCache($cache)); |
|
50 | |||
51 | 1 | $this->readCache(); |
|
52 | |||
53 | 1 | } |
|
54 | |||
55 | 1 | public function add($route, $type, $class, $parameters = array()) { |
|
56 | |||
57 | 1 | $routeData = $this->get($route); |
|
58 | |||
59 | 1 | if (!is_null($routeData)) { |
|
60 | |||
61 | $routeData->setType($type) |
||
62 | ->setClassName($class) |
||
63 | ->setParameters($parameters); |
||
64 | |||
65 | } else { |
||
66 | |||
67 | 1 | $folders = explode("/", $route); |
|
68 | |||
69 | 1 | $this->register($folders, $type, $class, $parameters); |
|
70 | |||
71 | } |
||
72 | |||
73 | 1 | return $this; |
|
74 | |||
75 | } |
||
76 | |||
77 | 1 | public function get($route) { |
|
78 | |||
79 | 1 | $regex = $this->regex($route); |
|
80 | |||
81 | 1 | if (isset($this->routes[$regex])) |
|
82 | 1 | return $this->routes[$regex]; |
|
83 | else |
||
84 | 1 | return null; |
|
85 | |||
86 | } |
||
87 | |||
88 | 1 | public function regex($route) { |
|
89 | |||
90 | 1 | $folders = explode("/", $route); |
|
91 | |||
92 | 1 | return $this->parser->read($folders); |
|
93 | |||
94 | } |
||
95 | |||
96 | 1 | public function remove($route) { |
|
97 | |||
98 | 1 | $regex = $this->regex($route); |
|
99 | |||
100 | 1 | $routes = $this->routes; |
|
101 | |||
102 | 1 | if (isset($routes[$regex])) { |
|
103 | |||
104 | 1 | unset($routes[$regex]); |
|
105 | |||
106 | 1 | $this->routes = $routes; |
|
107 | |||
108 | 1 | return true; |
|
109 | |||
110 | } |
||
111 | |||
112 | return false; |
||
113 | |||
114 | 1 | } |
|
115 | |||
116 | public function defaultRoute() { |
||
121 | |||
122 | public function load($routes) { |
||
123 | |||
124 | if ( !empty($routes) ) { |
||
125 | |||
126 | foreach( $routes as $name => $route ) { |
||
139 | |||
140 | 1 | private function readCache() { |
|
159 | |||
160 | private function dumpCache() { |
||
173 | |||
174 | // This method add a route to the supported list |
||
175 | 1 | private function register($folders, $type, $class, $parameters) { |
|
199 | |||
200 | } |
||
201 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.