public getEnvironment ( string $id, Platformsh\Client\Model\Project $project, boolean | null $refresh = null, boolean $tryMachineName = false ) : Platformsh\Client\Model\Environment | false | ||
$id | string | The environment ID to load. |
$project | Platformsh\Client\Model\Project | The project. |
$refresh | boolean | null | Whether to refresh the list of environments. |
$tryMachineName | boolean | Whether to retry, treating the ID as a machine name. |
return | Platformsh\Client\Model\Environment | false | The environment, or false if not found. |
public function getEnvironment($id, Project $project, $refresh = null, $tryMachineName = false)
{
// Statically cache not found environments.
static $notFound = [];
$cacheKey = $project->id . ':' . $id . ($tryMachineName ? ':mn' : '');
if (!$refresh && isset($notFound[$cacheKey])) {
return false;
}
$environments = $this->getEnvironments($project, $refresh);
if (isset($environments[$id])) {
return $environments[$id];
}
if ($tryMachineName) {
foreach ($environments as $environment) {
if ($environment->machine_name === $id) {
return $environment;
}
}
}
$notFound[$cacheKey] = true;
return false;
}