Hoa central
Generic.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Router;
38 
47 abstract class Generic implements Router
48 {
54  protected $_rules = [];
55 
61  protected $_rule = null;
62 
68  protected static $_methods = [];
69 
70 
71 
86  abstract protected function _addRule(
87  $visibility,
88  $id,
89  Array $methods,
90  $pattern,
91  $call,
92  $able,
93  Array $variables
94  );
95 
108  public function addRule(
109  $id,
110  Array $methods,
111  $pattern,
112  $call = null,
113  $able = null,
114  Array $variables = []
115  ) {
116  return $this->_addRule(
118  $id,
119  $methods,
120  $pattern,
121  $call,
122  $able,
123  $variables
124  );
125  }
126 
139  public function addPrivateRule(
140  $id,
141  Array $methods,
142  $pattern,$call = null,
143  $able = null,
144  Array $variables = []
145  ) {
146  return $this->_addRule(
148  $id,
149  $methods,
150  $pattern,
151  $call,
152  $able,
153  $variables
154  );
155  }
156 
174  public function __call($name, $arguments)
175  {
176  if ('_' === $name[0]) {
177  $name = substr($name, 1);
178  $method = 'addPrivateRule';
179  } else {
180  $method = 'addRule';
181  }
182 
183  if ('any' === $name) {
184  array_unshift($arguments, static::$_methods);
185  } else {
186  array_unshift($arguments, explode('_', $name));
187  }
188 
189  $handle = $arguments[0];
190  $arguments[0] = $arguments[1];
191  $arguments[1] = $handle;
192 
193  return call_user_func_array([$this, $method], $arguments);
194  }
195 
202  public function removeRule($id)
203  {
204  unset($this->_rules[$id]);
205 
206  return;
207  }
208 
215  public function ruleExists($id)
216  {
217  return isset($this->_rules[$id]);
218  }
219 
225  public function getRules()
226  {
227  return $this->_rules;
228  }
229 
237  public function getRule($id)
238  {
239  if (false === $this->ruleExists($id)) {
240  throw new Exception('Rule %s does not exist.', 0, $id);
241  }
242 
243  return $this->_rules[$id];
244  }
245 
251  public function &getTheRule()
252  {
253  return $this->_rule;
254  }
255 }
static $_methods
Definition: Generic.php:68
__call($name, $arguments)
Definition: Generic.php:174
const VISIBILITY_PUBLIC
Definition: Router.php:56
addRule($id, Array $methods, $pattern, $call=null, $able=null, Array $variables=[])
Definition: Generic.php:108
const VISIBILITY_PRIVATE
Definition: Router.php:63
_addRule($visibility, $id, Array $methods, $pattern, $call, $able, Array $variables)
addPrivateRule($id, Array $methods, $pattern, $call=null, $able=null, Array $variables=[])
Definition: Generic.php:139