[COMPOSER] Added predis/predis and updated packages

This commit is contained in:
Miguel Dantas
2019-08-13 01:31:05 +01:00
committed by Diogo Peralta Cordeiro
parent 50c98d53c9
commit 19d68c9f8e
641 changed files with 58448 additions and 83 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace Http\Client\Common\Plugin;
use Http\Client\Common\Plugin;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
/**
* Prepend a base path to the request URI. Useful for base API URLs like http://domain.com/api.
*
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*/
final class AddPathPlugin implements Plugin
{
/**
* @var UriInterface
*/
private $uri;
/**
* Stores identifiers of the already altered requests.
*
* @var array
*/
private $alteredRequests = [];
/**
* @param UriInterface $uri
*/
public function __construct(UriInterface $uri)
{
if ('' === $uri->getPath()) {
throw new \LogicException('URI path cannot be empty');
}
if ('/' === substr($uri->getPath(), -1)) {
$uri = $uri->withPath(rtrim($uri->getPath(), '/'));
}
$this->uri = $uri;
}
/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
{
$identifier = spl_object_hash((object) $first);
if (!array_key_exists($identifier, $this->alteredRequests)) {
$request = $request->withUri($request->getUri()
->withPath($this->uri->getPath().$request->getUri()->getPath())
);
$this->alteredRequests[$identifier] = $identifier;
}
return $next($request);
}
}