StackFormation\Helper\Div::assocArrayToString PHP Method

assocArrayToString() public static method

public static assocArrayToString ( array $array, $itemSeparator = '; ', $keyValueSeparator = '=' )
$array array
    public static function assocArrayToString(array $array, $itemSeparator = '; ', $keyValueSeparator = '=')
    {
        $tmp = [];
        foreach ($array as $key => $value) {
            $tmp[] = "{$key}{$keyValueSeparator}{$value}";
        }
        return implode($itemSeparator, $tmp);
    }

Usage Example

 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;
 }
All Usage Examples Of StackFormation\Helper\Div::assocArrayToString