first commit
This commit is contained in:
61
vendor/hanson/foundation-sdk/src/AbstractAPI.php
vendored
Normal file
61
vendor/hanson/foundation-sdk/src/AbstractAPI.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Hanson\Foundation;
|
||||
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
abstract class AbstractAPI
|
||||
{
|
||||
|
||||
/**
|
||||
* Http instance.
|
||||
*
|
||||
* @var Http
|
||||
*/
|
||||
protected $http;
|
||||
|
||||
/**
|
||||
* @return Http
|
||||
*/
|
||||
public function getHttp()
|
||||
{
|
||||
if (is_null($this->http)) {
|
||||
$this->http = new Http();
|
||||
}
|
||||
|
||||
if (count($this->http->getMiddlewares()) === 0) {
|
||||
$this->middlewares();
|
||||
}
|
||||
|
||||
return $this->http;
|
||||
}
|
||||
|
||||
/**
|
||||
* add headers.
|
||||
*
|
||||
* @param $headers
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function headerMiddleware($headers)
|
||||
{
|
||||
return function (callable $handler) use ($headers) {
|
||||
return function (RequestInterface $request, array $options) use ($handler, $headers) {
|
||||
foreach ($headers as $key => $header) {
|
||||
$request = $request->withHeader($key, $header);
|
||||
}
|
||||
|
||||
return $handler($request, $options);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Push guzzle middleware before request.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function middlewares()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user