mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-11-13 19:33:09 +09:00
Update to laravel 7
This commit is contained in:
@@ -4,80 +4,65 @@ namespace Github\Api;
|
||||
|
||||
use Github\Client;
|
||||
use Github\HttpClient\Message\ResponseMediator;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Abstract class for Api classes.
|
||||
*
|
||||
* @author Joseph Bielawski <stloyd@gmail.com>
|
||||
* @author Graham Campbell <graham@alt-three.com>
|
||||
*/
|
||||
abstract class AbstractApi implements ApiInterface
|
||||
abstract class AbstractApi
|
||||
{
|
||||
/**
|
||||
* The client.
|
||||
* The client instance.
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
protected $client;
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* The requested page (GitHub pagination).
|
||||
* The per page parameter. It is used by the ResultPager.
|
||||
*
|
||||
* @var null|int
|
||||
* @var int|null
|
||||
*/
|
||||
private $page;
|
||||
private $perPage;
|
||||
|
||||
/**
|
||||
* Number of items per page (GitHub pagination).
|
||||
* Create a new API instance.
|
||||
*
|
||||
* @var null|int
|
||||
*/
|
||||
protected $perPage;
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Client $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the client instance.
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
protected function getClient(): Client
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the API version.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getApiVersion(): string
|
||||
{
|
||||
return $this->client->getApiVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function configure()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|int
|
||||
*/
|
||||
public function getPage()
|
||||
{
|
||||
return $this->page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $page
|
||||
*/
|
||||
public function setPage($page)
|
||||
{
|
||||
$this->page = (null === $page ? $page : (int) $page);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|int
|
||||
*/
|
||||
public function getPerPage()
|
||||
{
|
||||
return $this->perPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $perPage
|
||||
*/
|
||||
public function setPerPage($perPage)
|
||||
{
|
||||
$this->perPage = (null === $perPage ? $perPage : (int) $perPage);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -90,20 +75,18 @@ abstract class AbstractApi implements ApiInterface
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
protected function get($path, array $parameters = [], array $requestHeaders = [])
|
||||
protected function get(string $path, array $parameters = [], array $requestHeaders = [])
|
||||
{
|
||||
if (null !== $this->page && !isset($parameters['page'])) {
|
||||
$parameters['page'] = $this->page;
|
||||
}
|
||||
if (null !== $this->perPage && !isset($parameters['per_page'])) {
|
||||
$parameters['per_page'] = $this->perPage;
|
||||
}
|
||||
|
||||
if (array_key_exists('ref', $parameters) && null === $parameters['ref']) {
|
||||
unset($parameters['ref']);
|
||||
}
|
||||
|
||||
if (count($parameters) > 0) {
|
||||
$path .= '?'.http_build_query($parameters);
|
||||
$path .= '?'.http_build_query($parameters, '', '&', PHP_QUERY_RFC3986);
|
||||
}
|
||||
|
||||
$response = $this->client->getHttpClient()->get($path, $requestHeaders);
|
||||
@@ -118,17 +101,15 @@ abstract class AbstractApi implements ApiInterface
|
||||
* @param array $parameters HEAD parameters.
|
||||
* @param array $requestHeaders Request headers.
|
||||
*
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function head($path, array $parameters = [], array $requestHeaders = [])
|
||||
protected function head(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
|
||||
{
|
||||
if (array_key_exists('ref', $parameters) && null === $parameters['ref']) {
|
||||
unset($parameters['ref']);
|
||||
}
|
||||
|
||||
$response = $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters), $requestHeaders);
|
||||
|
||||
return $response;
|
||||
return $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters, '', '&', PHP_QUERY_RFC3986), $requestHeaders);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +121,7 @@ abstract class AbstractApi implements ApiInterface
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
protected function post($path, array $parameters = [], array $requestHeaders = [])
|
||||
protected function post(string $path, array $parameters = [], array $requestHeaders = [])
|
||||
{
|
||||
return $this->postRaw(
|
||||
$path,
|
||||
@@ -158,7 +139,7 @@ abstract class AbstractApi implements ApiInterface
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
protected function postRaw($path, $body, array $requestHeaders = [])
|
||||
protected function postRaw(string $path, $body, array $requestHeaders = [])
|
||||
{
|
||||
$response = $this->client->getHttpClient()->post(
|
||||
$path,
|
||||
@@ -178,7 +159,7 @@ abstract class AbstractApi implements ApiInterface
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
protected function patch($path, array $parameters = [], array $requestHeaders = [])
|
||||
protected function patch(string $path, array $parameters = [], array $requestHeaders = [])
|
||||
{
|
||||
$response = $this->client->getHttpClient()->patch(
|
||||
$path,
|
||||
@@ -198,7 +179,7 @@ abstract class AbstractApi implements ApiInterface
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
protected function put($path, array $parameters = [], array $requestHeaders = [])
|
||||
protected function put(string $path, array $parameters = [], array $requestHeaders = [])
|
||||
{
|
||||
$response = $this->client->getHttpClient()->put(
|
||||
$path,
|
||||
@@ -218,7 +199,7 @@ abstract class AbstractApi implements ApiInterface
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
protected function delete($path, array $parameters = [], array $requestHeaders = [])
|
||||
protected function delete(string $path, array $parameters = [], array $requestHeaders = [])
|
||||
{
|
||||
$response = $this->client->getHttpClient()->delete(
|
||||
$path,
|
||||
@@ -234,9 +215,9 @@ abstract class AbstractApi implements ApiInterface
|
||||
*
|
||||
* @param array $parameters Request parameters
|
||||
*
|
||||
* @return null|string
|
||||
* @return string|null
|
||||
*/
|
||||
protected function createJsonBody(array $parameters)
|
||||
protected function createJsonBody(array $parameters): ?string
|
||||
{
|
||||
return (count($parameters) === 0) ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user