@@ -123,7 +123,7 @@ public function addUser($user, $role, $byUuid = false)
123123 public function setApiUrl ($ url )
124124 {
125125 $ projectUrl = Url::fromString ($ url )->combine ('/projects/ ' . \urlencode ($ this ->id ))->__toString ();
126- $ this ->urlViaGateway = $ projectUrl ;
126+ $ this ->baseUrl = $ this -> urlViaGateway = $ projectUrl ;
127127 }
128128
129129 /**
@@ -213,14 +213,37 @@ public function getEnvironment($id)
213213 */
214214 public function getLink ($ rel , $ absolute = true )
215215 {
216+ /**
217+ * Require the API URL to be set for 'invitations' and 'access'.
218+ *
219+ * These endpoints require the external API proxy or gateway, or may
220+ * require it in the future.
221+ *
222+ * The parent method, via self::makeAbsoluteUrl(), ensures an
223+ * appropriate base URL is used otherwise.
224+ *
225+ * @see setApiUrl()
226+ * @see makeAbsoluteUrl()
227+ */
228+ if ($ rel === 'invitations ' || $ rel === 'access ' ) {
229+ if (!isset ($ this ->urlViaGateway )) {
230+ throw new \RuntimeException ('The API gateway URL must be set ' );
231+ }
232+ }
233+
234+ // Use the HAL links available on the project.
216235 if ($ this ->hasLink ($ rel )) {
217236 return parent ::getLink ($ rel , $ absolute );
218237 }
219238
239+ // If the 'self' link is not present then this might be a project
240+ // stub with an 'endpoint' property.
220241 if ($ rel === 'self ' ) {
221- return $ this ->getProperty ('endpoint ' );
242+ return $ this ->makeAbsoluteUrl ( $ this -> getProperty ('endpoint ' ) );
222243 }
223244
245+ // If the '#ui' link is not present then this might be a project
246+ // stub with a 'uri' property.
224247 if ($ rel === '#ui ' ) {
225248 return $ this ->getProperty ('uri ' );
226249 }
@@ -229,13 +252,6 @@ public function getLink($rel, $absolute = true)
229252 return $ this ->getUri () . '/variables ' ;
230253 }
231254
232- if ($ rel === 'invitations ' ) {
233- if (!isset ($ this ->urlViaGateway )) {
234- throw new \RuntimeException ('The API gateway URL must be set ' );
235- }
236- return rtrim ($ this ->urlViaGateway , '/ ' ) . '/invitations ' ;
237- }
238-
239255 return $ this ->getUri () . '/ ' . ltrim ($ rel , '# ' );
240256 }
241257
0 commit comments