Skip to content

Commit 6434eb3

Browse files
committed
Add a ProjectStub class to represent projects in the /me API
1 parent f6555e0 commit 6434eb3

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

src/Model/ProjectStub.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Platformsh\Client\Model;
4+
5+
use Platformsh\Client\Model\Ref\OrganizationRef;
6+
7+
/**
8+
* Stub (meta) information about a Platform.sh project obtained from the /me API.
9+
*
10+
* @property-read string $id
11+
* @property-read string $title
12+
* @property-read string $created_at
13+
* @property-read string $updated_at
14+
* @property-read string $endpoint
15+
* @property-read string $subscription_id
16+
* @property-read string $region
17+
* @property-read string $region_label
18+
* @property-read string $status
19+
*/
20+
class ProjectStub extends ResourceWithReferences
21+
{
22+
protected static $collectionItemsKey = 'projects';
23+
24+
/**
25+
* Returns the full project resource for this stub.
26+
*
27+
* @return Project
28+
*/
29+
public function getProject()
30+
{
31+
$project = Project::get($this->endpoint, '', $this->client);
32+
if ($project === false) {
33+
throw new \RuntimeException('Project not found: ' . $this->endpoint);
34+
}
35+
return $project;
36+
}
37+
38+
/**
39+
* Returns detailed information about the project's organization, if known.
40+
*
41+
* @return OrganizationRef|null
42+
*/
43+
public function getOrganizationInfo()
44+
{
45+
if (isset($this->data['organization_id']) && isset($this->data['ref:organizations'][$this->data['organization_id']])) {
46+
return $this->data['ref:organizations'][$this->data['organization_id']];
47+
}
48+
return null;
49+
}
50+
}

0 commit comments

Comments
 (0)