public function getCurrentProject()
{
if (isset($this->currentProject)) {
return $this->currentProject;
}
if (!($projectRoot = $this->getProjectRoot())) {
return false;
}
$project = false;
$config = $this->localProject->getProjectConfig($projectRoot);
if ($config) {
$project = $this->api()->getProject($config['id'], isset($config['host']) ? $config['host'] : null);
// There is a chance that the project isn't available.
if (!$project) {
if (isset($config['host'])) {
$projectUrl = sprintf('https://%s/projects/%s', $config['host'], $config['id']);
$message = "Project not found: " . $projectUrl . "\nThe project probably no longer exists.";
} else {
$message = "Project not found: " . $config['id'] . "\nEither you do not have access to the project or it no longer exists.";
}
throw new ProjectNotFoundException($message);
}
$this->debug('Selecting project ' . $config['id'] . ' based on project root');
}
$this->currentProject = $project;
return $project;
}