|
8 | 8 | use Pantheon\Terminus\Collections\OrganizationUpstreams; |
9 | 9 | use Pantheon\Terminus\Collections\OrganizationUserMemberships; |
10 | 10 | use Pantheon\Terminus\Collections\Workflows; |
| 11 | +use Pantheon\Terminus\Models\OrganizationSiteMembership; |
11 | 12 | use Pantheon\Terminus\Friends\ProfileInterface; |
12 | 13 | use Pantheon\Terminus\Friends\ProfileTrait; |
13 | 14 | use Pantheon\Terminus\Friends\SitesInterface; |
@@ -140,6 +141,39 @@ public function getSiteMemberships() |
140 | 141 | return $this->site_memberships; |
141 | 142 | } |
142 | 143 |
|
| 144 | + /** |
| 145 | + * Fetch a single site membership directly by site ID or name |
| 146 | + * |
| 147 | + * @param string $site_identifier The site ID or name to fetch membership for |
| 148 | + * @return OrganizationSiteMembership |
| 149 | + * @throws \Pantheon\Terminus\Exceptions\TerminusNotFoundException |
| 150 | + */ |
| 151 | + public function getSiteMembership($site_identifier) |
| 152 | + { |
| 153 | + $site_uuid = $site_identifier; |
| 154 | + |
| 155 | + // If the identifier is not a UUID, resolve the name to UUID |
| 156 | + if (!preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', $site_identifier)) { |
| 157 | + $response = $this->request->request("site-names/{$site_identifier}"); |
| 158 | + if (!isset($response['data']->id)) { |
| 159 | + throw new \Pantheon\Terminus\Exceptions\TerminusNotFoundException( |
| 160 | + "Could not find a site identified by {$site_identifier}." |
| 161 | + ); |
| 162 | + } |
| 163 | + $site_uuid = $response['data']->id; |
| 164 | + } |
| 165 | + |
| 166 | + $response = $this->request->request( |
| 167 | + "organizations/{$this->id}/memberships/sites/{$site_uuid}" |
| 168 | + ); |
| 169 | + |
| 170 | + $nickname = \uniqid(__FUNCTION__ . '-'); |
| 171 | + $this->getContainer()->add($nickname, OrganizationSiteMembership::class) |
| 172 | + ->addArgument($response['data']) |
| 173 | + ->addArgument(['organization' => $this]); |
| 174 | + return $this->getContainer()->get($nickname); |
| 175 | + } |
| 176 | + |
143 | 177 | /** |
144 | 178 | * @return OrganizationUpstreams |
145 | 179 | */ |
|
0 commit comments