/** * Recurse through the Routes until a match is found. * * When called multiple times (in a loop for instance) * this method will return a new matching route until * all routes have been processed. * * Once exhausted this function returns false and the * internal pointer is reset so the Router can be used * again. * * @return bool|Proem\Routing\Route\Payload */ public function route() { if ($route = $this->routes->current()) { $this->routes->next(); $route->process($this->request); if ($route->isMatch() && $route->getPayload()->isPopulated()) { if ($route->hasCallback()) { return $route->call($this->request); } return $route->getPayload(); } else { return $this->route(); } } $this->routes->rewind(); return false; }
/** * Send the HTTP headers to the client. * * @param bool $include_content_length Optionaly disable the Content-Length header. */ public function sendHeaders($include_content_length = true) { if (headers_sent()) { return; } if ($include_content_length) { $this->headers->set('Content-Length', $this->length); } if (in_array($this->httpStatus, [204, 304])) { $this->headers->remove('Content-Type'); } header(sprintf('HTTP/%s %s %s', $this->httpVersion, $this->getHttpStatus(), $this->getHttpStatus(true))); foreach ($this->headers->all() as $index => $value) { header(sprintf('%s: %s', $index, $value)); } }