public function __construct($url, $statusCode = 302, $error = null, $errorDescription = null, $state = null) { if (empty($url)) { throw new InvalidArgumentException('Cannot redirect to an empty URL.'); } $query = array(); if (!is_null($error)) { $query['error'] = $error; } if (!is_null($errorDescription)) { $query['error_description'] = $errorDescription; } if (!is_null($state)) { $query['state'] = $state; } if (count($query) > 0) { $parts = parse_url($url); $sep = isset($parts['query']) && count($parts['query']) > 0 ? '&' : '?'; $url = $url . $sep . http_build_query($query); } $httpHeaders = array('Location' => $url); parent::__construct(array(), $statusCode, $httpHeaders); if (!$this->isRedirection()) { throw new InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $statusCode)); } }
public function __construct($statusCode, $error, $errorDescription) { $responseParameters = array('error' => $error, 'error_description' => $errorDescription); $httpHeaders = array('Cache-Control' => 'no-store'); parent::__construct($responseParameters, $statusCode, $httpHeaders); if (!$this->isClientError() && !$this->isServerError()) { throw new InvalidArgumentException(sprintf('The HTTP status code is not an error ("%s" given).', $statusCode)); } }
public function __construct($statusCode, $error, $errorDescription, $errorUri = null) { $parameters = array('error' => $error, 'error_description' => $errorDescription); if (!is_null($errorUri)) { if (strlen($errorUri) > 0 && $errorUri[0] == '#') { // we are referencing an oauth bookmark (for brevity) $errorUri = 'http://tools.ietf.org/html/draft-ietf-oauth-v2-31' . $errorUri; } $parameters['error_uri'] = $errorUri; } $httpHeaders = array('Cache-Control' => 'no-store'); parent::__construct($parameters, $statusCode, $httpHeaders); if (!$this->isClientError() && !$this->isServerError()) { throw new InvalidArgumentException(sprintf('The HTTP status code is not an error ("%s" given).', $statusCode)); } }