/** * Parameter Pairs Routing (PPR) * * /path/index.php/controller/action/id/1/name/nick * * {@inheritDoc} */ protected function match(ResultInterface $result) { $path = trim($result->getRequest()->getServerInfo('path_info'), ' /'); if (count($parts = explode('/', $path)) > 1) { // set status $result->setStatus(Status::OK); // parameters $controller = array_shift($parts); $action = array_shift($parts); if (count($parts) % 2) { $result->setStatus(Status::BAD_REQUEST); return false; } $params = []; foreach ($parts as $i => $val) { if (0 === $i % 2) { $params[$val] = $parts[$i + 1]; } } $result->setParameter($params); $result->setHandler([$controller, $action]); return true; } $result->setStatus(Status::BAD_REQUEST); return false; }
/** * Set collector level handler if result has no handler set yet * * @param ResultInterface $result desc * @return self * @access protected */ protected function setCollectorHandler(ResultInterface $result) { $status = $result->getStatus(); if (is_null($result->getHandler()) && $this->getHandler($status)) { // debug message $this->debug(Message::get(Message::DEBUG_SET_C_HANDLER, get_class($this), $status)); $result->setHandler($this->getHandler($status)); } return $this; }
/** * Query Parameter Routing * * http://servername/path/?r=controller-action-id-1-name-nick * * {@inheritDoc} */ protected function match(ResultInterface $result) { $params = $result->getParameter(); if (isset($params[$this->varname])) { // set status $result->setStatus(Status::OK); // parameters $parts = explode($this->seperator, $params[$this->varname]); $controller = array_shift($parts); $action = array_shift($parts); if (count($parts) % 2) { $result->setStatus(Status::BAD_REQUEST); return false; } $newparam = []; foreach ($parts as $i => $val) { if (0 === $i % 2) { $newparam[$val] = $parts[$i + 1]; } } $result->setParameter($newparam); $result->setHandler([$controller, $action]); return true; } $result->setStatus(Status::BAD_REQUEST); return false; }