aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/bshaffer/oauth2-server-php/src/OAuth2/Response.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2017-12-18 15:48:49 +0100
committerMario Vavti <mario@mariovavti.com>2017-12-18 15:48:49 +0100
commit439d41b194073285ab97be94253b3f4cb4395e43 (patch)
tree272d4c64ea2d766235ecb41009117b5269f8cdfd /vendor/bshaffer/oauth2-server-php/src/OAuth2/Response.php
parent08a8f195e749a120642f6c486c1dad62a73924d1 (diff)
downloadvolse-hubzilla-439d41b194073285ab97be94253b3f4cb4395e43.tar.gz
volse-hubzilla-439d41b194073285ab97be94253b3f4cb4395e43.tar.bz2
volse-hubzilla-439d41b194073285ab97be94253b3f4cb4395e43.zip
install smarty via composer and update other php libs
Diffstat (limited to 'vendor/bshaffer/oauth2-server-php/src/OAuth2/Response.php')
-rw-r--r--vendor/bshaffer/oauth2-server-php/src/OAuth2/Response.php134
1 files changed, 126 insertions, 8 deletions
diff --git a/vendor/bshaffer/oauth2-server-php/src/OAuth2/Response.php b/vendor/bshaffer/oauth2-server-php/src/OAuth2/Response.php
index fc1e62a98..ccd797ae7 100644
--- a/vendor/bshaffer/oauth2-server-php/src/OAuth2/Response.php
+++ b/vendor/bshaffer/oauth2-server-php/src/OAuth2/Response.php
@@ -2,6 +2,8 @@
namespace OAuth2;
+use InvalidArgumentException;
+
/**
* Class to handle OAuth2 Responses in a graceful way. Use this interface
* to output the proper OAuth2 responses.
@@ -13,12 +15,34 @@ namespace OAuth2;
*/
class Response implements ResponseInterface
{
+ /**
+ * @var string
+ */
public $version;
+
+ /**
+ * @var int
+ */
protected $statusCode = 200;
+
+ /**
+ * @var string
+ */
protected $statusText;
+
+ /**
+ * @var array
+ */
protected $parameters = array();
+
+ /**
+ * @var array
+ */
protected $httpHeaders = array();
+ /**
+ * @var array
+ */
public static $statusTexts = array(
100 => 'Continue',
101 => 'Switching Protocols',
@@ -63,6 +87,11 @@ class Response implements ResponseInterface
505 => 'HTTP Version Not Supported',
);
+ /**
+ * @param array $parameters
+ * @param int $statusCode
+ * @param array $headers
+ */
public function __construct($parameters = array(), $statusCode = 200, $headers = array())
{
$this->setParameters($parameters);
@@ -102,76 +131,128 @@ class Response implements ResponseInterface
return sprintf("%s: %s\n", $name, $value);
}
+ /**
+ * @return int
+ */
public function getStatusCode()
{
return $this->statusCode;
}
+ /**
+ * @param int $statusCode
+ * @param string $text
+ * @throws InvalidArgumentException
+ */
public function setStatusCode($statusCode, $text = null)
{
$this->statusCode = (int) $statusCode;
if ($this->isInvalid()) {
- throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $statusCode));
+ throw new InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $statusCode));
}
$this->statusText = false === $text ? '' : (null === $text ? self::$statusTexts[$this->statusCode] : $text);
}
+ /**
+ * @return string
+ */
public function getStatusText()
{
return $this->statusText;
}
+ /**
+ * @return array
+ */
public function getParameters()
{
return $this->parameters;
}
+ /**
+ * @param array $parameters
+ */
public function setParameters(array $parameters)
{
$this->parameters = $parameters;
}
+ /**
+ * @param array $parameters
+ */
public function addParameters(array $parameters)
{
$this->parameters = array_merge($this->parameters, $parameters);
}
+ /**
+ * @param string $name
+ * @param mixed $default
+ * @return mixed
+ */
public function getParameter($name, $default = null)
{
return isset($this->parameters[$name]) ? $this->parameters[$name] : $default;
}
+ /**
+ * @param string $name
+ * @param mixed $value
+ */
public function setParameter($name, $value)
{
$this->parameters[$name] = $value;
}
+ /**
+ * @param array $httpHeaders
+ */
public function setHttpHeaders(array $httpHeaders)
{
$this->httpHeaders = $httpHeaders;
}
+ /**
+ * @param string $name
+ * @param mixed $value
+ */
public function setHttpHeader($name, $value)
{
$this->httpHeaders[$name] = $value;
}
+ /**
+ * @param array $httpHeaders
+ */
public function addHttpHeaders(array $httpHeaders)
{
$this->httpHeaders = array_merge($this->httpHeaders, $httpHeaders);
}
+ /**
+ * @return array
+ */
public function getHttpHeaders()
{
return $this->httpHeaders;
}
+ /**
+ * @param string $name
+ * @param mixed $default
+ * @return mixed
+ */
public function getHttpHeader($name, $default = null)
{
return isset($this->httpHeaders[$name]) ? $this->httpHeaders[$name] : $default;
}
+ /**
+ * @param string $format
+ * @return mixed
+ * @throws InvalidArgumentException
+ */
public function getResponseBody($format = 'json')
{
switch ($format) {
@@ -187,10 +268,13 @@ class Response implements ResponseInterface
return $xml->asXML();
}
- throw new \InvalidArgumentException(sprintf('The format %s is not supported', $format));
+ throw new InvalidArgumentException(sprintf('The format %s is not supported', $format));
}
+ /**
+ * @param string $format
+ */
public function send($format = 'json')
{
// headers have already been sent by the developer
@@ -215,6 +299,14 @@ class Response implements ResponseInterface
echo $this->getResponseBody($format);
}
+ /**
+ * @param int $statusCode
+ * @param string $error
+ * @param string $errorDescription
+ * @param string $errorUri
+ * @return mixed
+ * @throws InvalidArgumentException
+ */
public function setError($statusCode, $error, $errorDescription = null, $errorUri = null)
{
$parameters = array(
@@ -239,14 +331,24 @@ class Response implements ResponseInterface
$this->addHttpHeaders($httpHeaders);
if (!$this->isClientError() && !$this->isServerError()) {
- throw new \InvalidArgumentException(sprintf('The HTTP status code is not an error ("%s" given).', $statusCode));
+ throw new InvalidArgumentException(sprintf('The HTTP status code is not an error ("%s" given).', $statusCode));
}
}
+ /**
+ * @param int $statusCode
+ * @param string $url
+ * @param string $state
+ * @param string $error
+ * @param string $errorDescription
+ * @param string $errorUri
+ * @return mixed
+ * @throws InvalidArgumentException
+ */
public function setRedirect($statusCode, $url, $state = null, $error = null, $errorDescription = null, $errorUri = null)
{
if (empty($url)) {
- throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
+ throw new InvalidArgumentException('Cannot redirect to an empty URL.');
}
$parameters = array();
@@ -271,15 +373,16 @@ class Response implements ResponseInterface
$this->addHttpHeaders(array('Location' => $url));
if (!$this->isRedirection()) {
- throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $statusCode));
+ throw new InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $statusCode));
}
}
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
/**
* @return Boolean
*
* @api
+ *
+ * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
*/
public function isInvalid()
{
@@ -336,8 +439,11 @@ class Response implements ResponseInterface
return $this->statusCode >= 500 && $this->statusCode < 600;
}
- /*
- * Functions from Symfony2 HttpFoundation - output pretty header
+ /**
+ * Function from Symfony2 HttpFoundation - output pretty header
+ *
+ * @param array $headers
+ * @return string
*/
private function getHttpHeadersAsString($headers)
{
@@ -357,11 +463,23 @@ class Response implements ResponseInterface
return $content;
}
+ /**
+ * Function from Symfony2 HttpFoundation - output pretty header
+ *
+ * @param string $name
+ * @return mixed
+ */
private function beautifyHeaderName($name)
{
return preg_replace_callback('/\-(.)/', array($this, 'beautifyCallback'), ucfirst($name));
}
+ /**
+ * Function from Symfony2 HttpFoundation - output pretty header
+ *
+ * @param array $match
+ * @return string
+ */
private function beautifyCallback($match)
{
return '-'.strtoupper($match[1]);