@@ -67,12 +67,10 @@ protected function request(
6767 throw new ConfigException ('A base URL must be set. ' );
6868 }
6969
70- // merge and overwrite query defaults
7170 if (!empty ($ this ->queryDefaults )) {
7271 $ query = array_merge ($ this ->queryDefaults , $ query );
7372 }
7473
75- // merge and overwrite header defaults
7674 if (!empty ($ this ->headerDefaults )) {
7775 $ headers = array_merge ($ this ->headerDefaults , $ headers );
7876 }
@@ -123,7 +121,7 @@ protected function request(
123121 );
124122 }
125123
126- $ uri = $ this ->createUri ($ path , $ query );
124+ $ uri = $ this ->buildUri ($ path , $ query );
127125 $ request = $ this ->createRequest ($ method , $ uri , $ headers , $ body );
128126
129127 $ response = $ this ->clientBuilder ->getClient ()->sendRequest ($ request );
@@ -247,6 +245,30 @@ protected function addResponseHandler(callable $handler, int $priority = 0): sel
247245 return $ this ;
248246 }
249247
248+ protected function buildPath (string $ path , array $ parameters ): string
249+ {
250+ foreach ($ parameters as $ parameter => $ value ) {
251+ $ path = \str_replace (
252+ \sprintf ('{%s} ' , $ parameter ),
253+ $ value ,
254+ $ path
255+ );
256+ }
257+
258+ return $ path ;
259+ }
260+
261+ private function buildUri (string $ path , array $ query = []): string
262+ {
263+ $ uri = $ this ->reduceDuplicateSlashes ($ this ->baseUrl . $ path );
264+
265+ if (!empty ($ query )) {
266+ $ uri = \sprintf ('%s?%s ' , $ uri , \http_build_query ($ query ));
267+ }
268+
269+ return $ uri ;
270+ }
271+
250272 private function createRequest (
251273 string $ method ,
252274 string $ uri ,
@@ -268,15 +290,4 @@ private function createRequest(
268290
269291 return $ request ;
270292 }
271-
272- private function createUri (string $ path , array $ query = []): string
273- {
274- $ uri = $ this ->reduceDuplicateSlashes ($ this ->baseUrl . $ path );
275-
276- if (!empty ($ query )) {
277- $ uri = \sprintf ('%s?%s ' , $ uri , \http_build_query ($ query ));
278- }
279-
280- return $ uri ;
281- }
282293}
0 commit comments