Skip to content

Commit 67012e3

Browse files
committed
Use the separate guzzlehttp/uri-template for templating URLs.
1 parent f754c13 commit 67012e3

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"require": {
3636
"php": "~7.0",
3737
"guzzlehttp/guzzle": "^7.0",
38+
"guzzlehttp/uri-template": "0.2",
3839
"justinrainbow/json-schema": "^5.2"
3940
},
4041
"require-dev": {

src/Common/Api/OperatorTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OpenStack\Common\Resource\ResourceInterface;
1212
use OpenStack\Common\Transport\RequestSerializer;
1313
use Psr\Http\Message\ResponseInterface;
14+
use OpenStack\Common\Transport\Utils;
1415

1516
trait OperatorTrait
1617
{
@@ -109,8 +110,7 @@ protected function sendRequest(Operation $operation, array $userValues = [], boo
109110

110111
$options = (new RequestSerializer())->serializeOptions($operation, $userValues);
111112
$method = $async ? 'requestAsync' : 'request';
112-
$uri = uri_template($operation->getPath(), $userValues);
113-
113+
$uri = Utils::uri_template($operation->getPath(), $userValues);
114114
return $this->client->$method($operation->getMethod(), $uri, $options);
115115
}
116116

src/Common/Transport/Utils.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use function GuzzleHttp\Psr7\uri_for;
88
use Psr\Http\Message\ResponseInterface;
99
use Psr\Http\Message\UriInterface;
10+
use GuzzleHttp\UriTemplate\UriTemplate;
1011

1112
class Utils
1213
{
@@ -80,4 +81,22 @@ public static function appendPath(UriInterface $uri, $path): UriInterface
8081
{
8182
return uri_for(rtrim((string) $uri, '/').'/'.$path);
8283
}
84+
85+
/**
86+
* Expands a URI template
87+
*
88+
* @param string $template URI template
89+
* @param array $variables Template variables
90+
*
91+
* @return string
92+
*/
93+
public static function uri_template($template, array $variables): string
94+
{
95+
if (extension_loaded('uri_template')) {
96+
// @codeCoverageIgnoreStart
97+
return \uri_template($template, $variables);
98+
// @codeCoverageIgnoreEnd
99+
}
100+
return UriTemplate::expand($template, $variables);
101+
}
83102
}

0 commit comments

Comments
 (0)