_addRule( Router::VISIBILITY_PUBLIC, $id, $methods, $pattern, $call, $able, $variables ); } /** * Add a private rule. * * @param string $id ID. * @param array $methods HTTP methods allowed by the rule. * @param string $pattern Pattern (on-subdomain@on-request). * @param mixed $call Call (first part). * @param mixed $able Able (second part). * @param array $variables Variables (default or additional values). * @return \Hoa\Router\Generic * @throws \Hoa\Router\Exception */ public function addPrivateRule( $id, Array $methods, $pattern,$call = null, $able = null, Array $variables = [] ) { return $this->_addRule( Router::VISIBILITY_PRIVATE, $id, $methods, $pattern, $call, $able, $variables ); } /** * Helper for adding rules. * Methods are concatenated by _. If prefixed by _, it's a private rule. In * addition, the keyword “any” takes place for all methods. * Examples: * get(…) : addRule(…, array('get'), …); * get_post(…) : addRule(…, array('get', 'post'), …); * post_get(…) : same that above; * _get(…) : addPrivateRule(…, array('get'), …); * any(…) : addRule(…, array(), …); * head_delete(…): addRule(…, array('head', 'delete'), …). * * @param string $name Please, see API documentation. * @param array $arguments Arguments for add*Rule() methods. * @return \Hoa\Router\Generic * @throws \Hoa\Router\Exception */ public function __call($name, $arguments) { if ('_' === $name[0]) { $name = substr($name, 1); $method = 'addPrivateRule'; } else { $method = 'addRule'; } if ('any' === $name) { array_unshift($arguments, static::$_methods); } else { array_unshift($arguments, explode('_', $name)); } $handle = $arguments[0]; $arguments[0] = $arguments[1]; $arguments[1] = $handle; return call_user_func_array([$this, $method], $arguments); } /** * Remove a rule. * * @param string $id ID. * @return void */ public function removeRule($id) { unset($this->_rules[$id]); return; } /** * Check whether a rule exists. * * @param string $id ID. * @return bool */ public function ruleExists($id) { return isset($this->_rules[$id]); } /** * Get all rules. * * @return array */ public function getRules() { return $this->_rules; } /** * Get a specific rule. * * @param string $id ID. * @return array * @throws \Hoa\Router\Exception */ public function getRule($id) { if (false === $this->ruleExists($id)) { throw new Exception('Rule %s does not exist.', 0, $id); } return $this->_rules[$id]; } /** * Get the selected rule after routing. * * @return array */ public function &getTheRule() { return $this->_rule; } }