Get the current project if the user is in a project directory.
public getCurrentProject ( ) : Platformsh\Client\Model\Project | false | ||
return | Platformsh\Client\Model\Project | false | The current project |
/** * Get the preferred project for autocompletion. * * The project is either defined by an ID that the user has specified in * the command (via the 'id' argument of 'get', or the '--project' option), * or it is determined from the current path. * * @return \Platformsh\Client\Model\Project|false */ protected function getProject() { if (!$this->projects) { return false; } $commandLine = $this->handler->getContext()->getCommandLine(); $currentProjectId = $this->getProjectIdFromCommandLine($commandLine); if (!$currentProjectId && ($currentProject = $this->welcomeCommand->getCurrentProject())) { return $currentProject; } elseif (isset($this->projects[$currentProjectId])) { return $this->projects[$currentProjectId]; } return false; }
/** * Get a list of environment IDs. * * The project is either defined by an ID that the user has specified in * the command (via the 'id' argument of 'get', or the '--project' option), * or it is determined from the current path. * * @return string[] */ public function getEnvironments() { if (!$this->projects) { return []; } $commandLine = $this->handler->getContext()->getCommandLine(); $currentProjectId = $this->getProjectIdFromCommandLine($commandLine); if (!$currentProjectId && ($currentProject = $this->platformCommand->getCurrentProject())) { $project = $currentProject; } elseif (isset($this->projects[$currentProjectId])) { $project = $this->projects[$currentProjectId]; } else { return []; } $environments = $this->platformCommand->getEnvironments($project, false, false); return array_keys($environments); }