/** * 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; }
/** * {@inheritDoc} */ public function __invoke(ResultInterface $result, $stage = '') { if (!$result->getRequest()->getServerInfo('https') && $stage) { $result->setStatus(Status::MOVED_PERMANENTLY)->setParameter('__REDIRECT_URL__', $this->url ?: $this->getUrl((array) $result->getRequest()->getServerInfo()))->setHandler(function (ResultInterface $result) { header("Location: " . $result->getParameter('__REDIRECT_URL__'), true, Status::MOVED_PERMANENTLY); die; }); // skip rest of the match/dispatch procedure return false; } return true; }