@@ -38,6 +38,12 @@ abstract class AbstractService implements ServiceInterface
3838 /** @var string */
3939 protected $ accessTokenEndpoint = '' ;
4040
41+ /** @var array */
42+ protected $ urlPlaceholders = [];
43+
44+ /** @var array */
45+ protected $ urlPlaceholdersEmptyReplaces = [];
46+
4147 /** @var ExtractorFactory */
4248 protected static $ extractorFactory ;
4349
@@ -58,9 +64,7 @@ public function __construct(
5864 $ this ->storage = $ storage ;
5965
6066 if ($ baseApiUrl ) {
61- $ this ->baseApiUri = new Url ($ baseApiUrl );
62- } elseif (is_string ($ this ->baseApiUri )) {
63- $ this ->baseApiUri = new Url ($ this ->baseApiUri );
67+ $ this ->baseApiUri = $ baseApiUrl ;
6468 }
6569
6670 $ this ->initialize ();
@@ -70,15 +74,15 @@ public function initialize()
7074 {
7175 }
7276
73- public function getBaseApiUri ($ clone = true )
77+ public function getBaseApiUri ()
7478 {
7579 if (null === $ this ->baseApiUri ) {
7680 throw new Exception (
7781 'An absolute URI must be passed to ServiceInterface::request as no baseApiUri is set. '
7882 );
7983 }
8084
81- return ! $ clone ? $ this ->baseApiUri : clone $ this ->baseApiUri ;
85+ return new Url ( $ this ->injectPlaceholdersToUri ( $ this ->baseApiUri )) ;
8286 }
8387
8488 /**
@@ -90,7 +94,7 @@ public function getAuthorizationEndpoint()
9094 throw new Exception ('Authorization endpoint isn \'t defined! ' );
9195 }
9296
93- return new Url ($ this ->authorizationEndpoint );
97+ return new Url ($ this ->injectPlaceholdersToUri ( $ this -> authorizationEndpoint ) );
9498 }
9599
96100 /**
@@ -102,7 +106,7 @@ public function getAccessTokenEndpoint()
102106 throw new Exception ('Access token endpoint isn \'t defined! ' );
103107 }
104108
105- return new Url ($ this ->accessTokenEndpoint );
109+ return new Url ($ this ->injectPlaceholdersToUri ( $ this -> accessTokenEndpoint ) );
106110 }
107111
108112 /**
@@ -116,7 +120,7 @@ protected function determineRequestUriFromPath($path)
116120 if ($ path instanceof Url) {
117121 $ uri = $ path ;
118122 } elseif (stripos ($ path , 'http:// ' ) === 0 || stripos ($ path , 'https:// ' ) === 0 ) {
119- $ uri = new Url ($ path );
123+ $ uri = new Url ($ this -> injectPlaceholdersToUri ( $ path) );
120124 } else {
121125 $ path = (string ) $ path ;
122126 $ uri = $ this ->getBaseApiUri ();
@@ -138,6 +142,12 @@ protected function determineRequestUriFromPath($path)
138142 return $ uri ;
139143 }
140144
145+ protected function injectPlaceholdersToUri ($ uri )
146+ {
147+
148+ return Url::replacePlaceholders ($ uri , $ this ->urlPlaceholders , $ this ->urlPlaceholdersEmptyReplaces );
149+ }
150+
141151 /**
142152 * Accessor to the storage adapter to be able to retrieve tokens
143153 *
0 commit comments