/** * @throws \Exception */ public function checkAuthentication() { if (!$this->isAuthenticated()) { HttpStatus::setStatus(HttpStatus::STATUS_401_UNAUTHORIZED); header('WWW-Authenticate: Basic realm="Login"'); throw new HttpAuthenticationRequiredException('HTTP authentication was required but not fulfilled.', 1415266170); } }
/** * Sets the location header including the HTTP status header for redirects * * @param string $target The target to use in location header * @param int $httpCode The HTTP code to use * @see \AppZap\PHPFramework\Mvc\HttpStatus */ public function redirect($target, $httpCode = HttpStatus::STATUS_307_TEMPORARY_REDIRECT) { if (php_sapi_name() !== 'cli') { HttpStatus::setStatus($httpCode, [HttpStatus::HEADER_FIELD_LOCATION => $target]); HttpStatus::sendHeaders(); } }
/** * @throws \Exception */ public function handleNotSupportedMethod() { HttpStatus::setStatus(HttpStatus::STATUS_405_METHOD_NOT_ALLOWED, [HttpStatus::HEADER_FIELD_ALLOW => join(', ', $this->getImplementedMethods())]); HttpStatus::sendHeaders(); throw new DispatchingInterruptedException('Request method not allowed', 1415268266); }