Skip to content

Commit

Permalink
Generate controller inline route (#168)
Browse files Browse the repository at this point in the history
* [generate:controller] Fix inlineValueAsArray method.

* [console] Update ShowGenerateChainListener class.
  • Loading branch information
jmolivas committed Jun 10, 2017
1 parent 9f5acea commit 18f5564
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
14 changes: 6 additions & 8 deletions src/Command/Shared/InputTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Class InputTrait
*
* @package Drupal\Console\Core\Command
* @package Drupal\Console\Core\Command\Shared
*/
trait InputTrait
{
Expand All @@ -19,19 +19,17 @@ trait InputTrait
*/
private function inlineValueAsArray($inputValue)
{
$inputArrayValue = [];
$inputAsArray = [];
foreach ($inputValue as $key => $value) {
if (!is_array($value)) {
$separatorIndex = strpos($value, ':');
if (!$separatorIndex) {
try {
$inputAsArray[] = json_decode('[{'.$value.'}]', true)[0];
} catch (\Exception $e) {
continue;
}
$inputKeyItem = substr($value, 0, $separatorIndex);
$inputValueItem = substr($value, $separatorIndex+1);
$inputArrayValue[$key] = [$inputKeyItem => $inputValueItem];
}
}

return $inputArrayValue?$inputArrayValue:$inputValue;
return $inputAsArray?$inputAsArray:$inputValue;
}
}
3 changes: 2 additions & 1 deletion src/EventSubscriber/ShowGenerateChainListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class ShowGenerateChainListener implements EventSubscriberInterface
private $skipOptions = [
'env',
'generate-inline',
'generate-chain'
'generate-chain',
'no-interaction'
];

/**
Expand Down
11 changes: 6 additions & 5 deletions src/EventSubscriber/ShowGenerateInlineListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class ShowGenerateInlineListener implements EventSubscriberInterface
private $skipOptions = [
'env',
'generate-inline',
'generate-chain'
'generate-chain',
'no-interaction'
];

/**
Expand Down Expand Up @@ -115,9 +116,9 @@ public function showGenerateInline(ConsoleTerminateEvent $event)
foreach ($optionValue as $optionItem) {
if (is_array($optionItem)) {
$inlineValue = implode(
' ', array_map(
', ', array_map(
function ($v, $k) {
return $k . ':' . $v;
return '"'.$k . '":"' . $v . '"';
},
$optionItem,
array_keys($optionItem)
Expand All @@ -126,7 +127,7 @@ function ($v, $k) {
} else {
$inlineValue = $optionItem;
}
$inline .= ' --' . $optionName . '="' . $inlineValue . '"';
$inline .= ' --' . $optionName . '=\'' . $inlineValue . '\'';
}
} else {
if (is_bool($optionValue)) {
Expand All @@ -144,7 +145,7 @@ function ($v, $k) {

$io->writeln(
sprintf(
'$ drupal %s %s',
'$ drupal %s %s --no-interaction',
$command_name,
$inline
)
Expand Down

0 comments on commit 18f5564

Please sign in to comment.