for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Http\Client\Common\Plugin;
use Http\Client\Common\Plugin;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
/**
* Add base path to the request URI. Useful for base API URLs like http://domain.com/api.
*
* @author Sullivan Senechal <[email protected]>
*/
final class AddPathPlugin implements Plugin
{
* @var UriInterface
private $host;
* @param UriInterface $host
public function __construct(UriInterface $host)
if ($host->getPath() === '') {
throw new \LogicException('Host path can not be empty');
}
$this->host = $host;
* {@inheritdoc}
public function handleRequest(RequestInterface $request, callable $next, callable $first)
$request = $request->withUri($request->getUri()
->withPath($this->host->getPath().$request->getUri()->getPath())
);
return $next($request);