protected function offerBranchChoice(Project $project, $projectRoot)
    {
        $environments = $this->api()->getEnvironments($project);
        $currentEnvironment = $this->getCurrentEnvironment($project);
        if ($currentEnvironment) {
            $this->stdErr->writeln("The current environment is " . $this->api()->getEnvironmentLabel($currentEnvironment) . ".");
            $this->stdErr->writeln('');
        }
        $environmentList = [];
        foreach ($environments as $id => $environment) {
            // The $id will be an integer for numeric environment names (as
            // it was assigned to an array key), so it's cast back to a
            // string for this comparison.
            if ($currentEnvironment && (string) $id === $currentEnvironment->id) {
                continue;
            }
            $environmentList[$id] = $this->api()->getEnvironmentLabel($environment, false);
        }
        /** @var \Platformsh\Cli\Local\LocalProject $localProject */
        $localProject = $this->getService('local.project');
        $projectConfig = $localProject->getProjectConfig($projectRoot);
        if (!empty($projectConfig['mapping'])) {
            foreach ($projectConfig['mapping'] as $branch => $id) {
                if (isset($environmentList[$id]) && isset($environmentList[$branch])) {
                    unset($environmentList[$id]);
                    $environmentList[$branch] = sprintf('%s (%s)', $environments[$id]->title, $branch);
                }
            }
        }
        if (!count($environmentList)) {
            $this->stdErr->writeln(sprintf(
                'Use <info>%s branch</info> to create an environment.',
                $this->config()->get('application.executable')
            ));

            return false;
        }

        /** @var \Platformsh\Cli\Service\QuestionHelper $helper */
        $helper = $this->getService('question_helper');

        // If there's more than one choice, present the user with a list.
        if (count($environmentList) > 1) {
            $chooseEnvironmentText = "Enter a number to check out another environment:";

            // The environment ID will be an integer if it was numeric
            // (because PHP does that with array keys), so it's cast back to
            // a string here.
            return (string) $helper->choose($environmentList, $chooseEnvironmentText);
        }

        // If there's only one choice, QuestionHelper::choose() does not
        // interact. But we still need interactive confirmation at this point.
        $environmentId = key($environmentList);
        if ($environmentId !== false) {
            $label = $this->api()->getEnvironmentLabel($environments[$environmentId]);
            if ($helper->confirm(sprintf('Check out environment %s?', $label))) {
                return $environmentId;
            }
        }

        return false;
    }
protected function offerBranchChoice(Project $project, $projectRoot)
    {
        $environments = $this->api()->getEnvironments($project);
        $currentEnvironment = $this->getCurrentEnvironment($project);
        if ($currentEnvironment) {
            $this->stdErr->writeln("The current environment is " . $this->api()->getEnvironmentLabel($currentEnvironment) . ".");
            $this->stdErr->writeln('');
        }
        $environmentList = [];
        foreach ($environments as $id => $environment) {
            // The $id will be an integer for numeric environment names (as
            // it was assigned to an array key), so it's cast back to a
            // string for this comparison.
            if ($currentEnvironment && (string) $id === $currentEnvironment->id) {
                continue;
            }
            $environmentList[$id] = $this->api()->getEnvironmentLabel($environment, false);
        }
        /** @var \Platformsh\Cli\Local\LocalProject $localProject */
        $localProject = $this->getService('local.project');
        $projectConfig = $localProject->getProjectConfig($projectRoot);
        if (!empty($projectConfig['mapping'])) {
            foreach ($projectConfig['mapping'] as $branch => $id) {
                if (isset($environmentList[$id]) && isset($environmentList[$branch])) {
                    unset($environmentList[$id]);
                    $environmentList[$branch] = sprintf('%s (%s)', $environments[$id]->title, $branch);
                }
            }
        }
        if (!count($environmentList)) {
            $this->stdErr->writeln(sprintf(
                'Use <info>%s branch</info> to create an environment.',
                $this->config()->get('application.executable')
            ));

            return false;
        }

        /** @var \Platformsh\Cli\Service\QuestionHelper $helper */
        $helper = $this->getService('question_helper');

        // If there's more than one choice, present the user with a list.
        if (count($environmentList) > 1) {
            $chooseEnvironmentText = "Enter a number to check out another environment:";

            // The environment ID will be an integer if it was numeric
            // (because PHP does that with array keys), so it's cast back to
            // a string here.
            return (string) $helper->choose($environmentList, $chooseEnvironmentText);
        }

        // If there's only one choice, QuestionHelper::choose() does not
        // interact. But we still need interactive confirmation at this point.
        $environmentId = key($environmentList);
        if ($environmentId !== false) {
            $label = $this->api()->getEnvironmentLabel($environments[$environmentId]);
            if ($helper->confirm(sprintf('Check out environment %s?', $label))) {
                return $environmentId;
            }
        }

        return false;
    }
protected function offerBranchChoice ( Project $ project , $ projectRoot ) { $ environments = $ this -> api ( ) -> getEnvironments ( $ project ) ; $ currentEnvironment = $ this -> getCurrentEnvironment ( $ project ) ; if ( $ currentEnvironment ) { $ this -> stdErr -> writeln ( "The current environment is " . $ this -> api ( ) -> getEnvironmentLabel ( $ currentEnvironment ) . "." ) ; $ this -> stdErr -> writeln ( '' ) ; } $ environmentList = [ ] ; foreach ( $ environments as $ id => $ environment ) { // The $id will be an integer for numeric environment names (as // it was assigned to an array key), so it's cast back to a // string for this comparison. if ( $ currentEnvironment && ( string ) $ id === $ currentEnvironment -> id ) { continue ; } $ environmentList [ $ id ] = $ this -> api ( ) -> getEnvironmentLabel ( $ environment , false ) ; } /** @var \Platformsh\Cli\Local\LocalProject $localProject */ $ localProject = $ this -> getService ( 'local.project' ) ; $ projectConfig = $ localProject -> getProjectConfig ( $ projectRoot ) ; if ( ! empty ( $ projectConfig [ 'mapping' ] ) ) { foreach ( $ projectConfig [ 'mapping' ] as $ branch => $ id ) { if ( isset ( $ environmentList [ $ id ] ) && isset ( $ environmentList [ $ branch ] ) ) { unset ( $ environmentList [ $ id ] ) ; $ environmentList [ $ branch ] = sprintf ( '%s (%s)' , $ environments [ $ id ] -> title , $ branch ) ; } } } if ( ! count ( $ environmentList ) ) { $ this -> stdErr -> writeln ( sprintf ( 'Use <info>%s branch</info> to create an environment.' , $ this -> config ( ) -> get ( 'application.executable' ) ) ) ; return false ; } /** @var \Platformsh\Cli\Service\QuestionHelper $helper */ $ helper = $ this -> getService ( 'question_helper' ) ; // If there's more than one choice, present the user with a list. if ( count ( $ environmentList ) > 1 ) { $ chooseEnvironmentText = "Enter a number to check out another environment:" ; // The environment ID will be an integer if it was numeric // (because PHP does that with array keys), so it's cast back to // a string here. return ( string ) $ helper -> choose ( $ environmentList , $ chooseEnvironmentText ) ; } // If there's only one choice, QuestionHelper::choose() does not // interact. But we still need interactive confirmation at this point. $ environmentId = key ( $ environmentList ) ; if ( $ environmentId !== false ) { $ label = $ this -> api ( ) -> getEnvironmentLabel ( $ environments [ $ environmentId ] ) ; if ( $ helper -> confirm ( sprintf ( 'Check out environment %s?' , $ label ) ) ) { return $ environmentId ; } } return false ; }
Prompt the user to select a branch to checkout.

@param Project $project
@param string  $projectRoot

@return string|false
The branch name, or false on failure.
Prompt the user to select a branch to checkout .