forked from ashleyhood/php-lxd
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPathTrimEnd.php
More file actions
35 lines (30 loc) · 745 Bytes
/
PathTrimEnd.php
File metadata and controls
35 lines (30 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace Opensaucesystems\Lxd\HttpClient\Plugin;
use Http\Client\Common\Plugin;
use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;
/**
* Prepend the URI with a string.
*
*/
class PathTrimEnd implements Plugin
{
private $trim;
/**
* @param string $trim
*/
public function __construct($trim = '/')
{
$this->trim = $trim;
}
/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
$trimPath = rtrim($request->getUri()->getPath(), $this->trim);
$uri = $request->getUri()->withPath($trimPath);
$request = $request->withUri($uri);
return $next($request);
}
}