@@ -216,13 +216,9 @@ public function request(Http\Request $request)
216216 */
217217 public function createRequest ($ method , $ urlPath , array $ parameters = [], array $ headers = [], $ content = NULL )
218218 {
219- $ parameters += $ this ->defaultParameters ;
220- $ this ->substituteUrlParameters ($ urlPath , $ parameters );
219+ $ urlPath = $ this ->expandColonParameters ($ urlPath , $ parameters , $ this ->defaultParameters );
221220
222- $ url = rtrim ($ this ->url , '/ ' ) . '/ ' . trim ($ urlPath , '/ ' );
223- if (count ($ parameters )) {
224- $ url .= '? ' . http_build_query ($ parameters );
225- }
221+ $ url = rtrim ($ this ->url , '/ ' ) . '/ ' . ltrim ($ urlPath , '/ ' );
226222
227223 if ($ content !== NULL && (is_array ($ content ) || is_object ($ content ))) {
228224 $ headers ['Content-Type ' ] = 'application/json; charset=utf-8 ' ;
@@ -339,21 +335,30 @@ public function getUrl()
339335
340336 /**
341337 * @param string
342- * @param array
338+ * @return string
343339 *
344340 * @throws MissingParameterException
345341 */
346- protected function substituteUrlParameters (& $ url , array & $ parameters )
342+ protected function expandColonParameters ( $ url , array $ parameters, array $ defaultParameters )
347343 {
344+ $ parameters += $ defaultParameters ;
345+
348346 $ url = preg_replace_callback ('#(^|/):([^/]+)# ' , function ($ m ) use ($ url , & $ parameters ) {
349347 if (!isset ($ parameters [$ m [2 ]])) {
350348 throw new MissingParameterException ("Missing parameter ' $ m [2 ]' for URL path ' $ url'. " );
351349 }
352-
353350 $ parameter = $ parameters [$ m [2 ]];
354351 unset($ parameters [$ m [2 ]]);
355352 return $ m [1 ] . rawurlencode ($ parameter );
356353 }, $ url );
354+
355+ $ url = rtrim ($ url , '/ ' );
356+
357+ if (count ($ parameters )) {
358+ $ url .= '? ' . http_build_query ($ parameters );
359+ }
360+
361+ return $ url ;
357362 }
358363
359364}
0 commit comments