StackFormation\BlueprintFactory::getBlueprintLabels PHP Метод

getBlueprintLabels() публичный Метод

public getBlueprintLabels ( $filter = null )
    public function getBlueprintLabels($filter = null)
    {
        $labels = [];
        foreach ($this->config->getBlueprintNames() as $blueprintName) {
            try {
                $effectiveStackName = $this->getBlueprint($blueprintName)->getStackName();
            } catch (\StackFormation\Exception\InvalidStackNameException $e) {
                $effectiveStackName = '<fg=red>[Invalid stack name "' . $e->getStackName() . '"]</>';
            } catch (\StackFormation\Exception\ValueResolverException $e) {
                $previousException = $e->getPrevious();
                if ($previousException instanceof MissingEnvVarException) {
                    $effectiveStackName = '<fg=red>[Missing env var "' . $previousException->getEnvVar() . '"]</>';
                } else {
                    throw $e;
                }
            }
            $label = $blueprintName;
            if (!is_null($filter) && !Finder::matchWildcard($filter, $label)) {
                continue;
            }
            if ($effectiveStackName != $blueprintName) {
                $label .= " <fg=yellow>(Effective: {$effectiveStackName})</>";
            }
            $labels[] = $label;
        }
        return $labels;
    }

Usage Example

Пример #1
0
 protected function interactAskForBlueprint(InputInterface $input, OutputInterface $output)
 {
     $blueprint = $input->getArgument('blueprint');
     if (empty($blueprint) || strpos($blueprint, '*') !== false || strpos($blueprint, '?') !== false) {
         $choices = $this->blueprintFactory->getBlueprintLabels($blueprint ? $blueprint : null);
         if (count($choices) == 0) {
             throw new \Exception('No matching blueprints found');
         } elseif (count($choices) == 1) {
             $blueprint = end($choices);
         } else {
             $helper = $this->getHelper('question');
             $question = new ChoiceQuestion('Please select a blueprint', $choices);
             $question->setErrorMessage('Blueprint %s is invalid.');
             $blueprint = $helper->ask($input, $output, $question);
         }
         $output->writeln('Selected blueprint: ' . $blueprint);
         list($blueprint) = explode(' ', $blueprint);
     } elseif (!empty($blueprint) && !$this->blueprintFactory->blueprintExists($blueprint)) {
         if ($result = $this->blueprintFactory->findByStackname($blueprint)) {
             $output->writeln('Blueprint reverse match found: <fg=green>' . $result['blueprint'] . '</>');
             $output->writeln('With ENV vars: <fg=green>' . Helper\Div::assocArrayToString($result['envvars']) . '</>');
             $helper = $this->getHelper('question');
             $question = new ConfirmationQuestion("Use this blueprint and set env vars? [y/N] ", false);
             if (!$helper->ask($input, $output, $question)) {
                 throw new \Exception('Operation aborted');
             }
             $blueprint = $result['blueprint'];
             foreach ($result['envvars'] as $var => $value) {
                 $output->writeln("Setting env var: {$var}={$value}");
                 putenv("{$var}={$value}");
             }
         }
     }
     $input->setArgument('blueprint', $blueprint);
     return $blueprint;
 }