-
-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new trait ArrayInputTrait, which will parse nested data. Switch m…
…uti value options to array to handle them properly, when receive params through the options (#3712)
- Loading branch information
Showing
2 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains Drupal\Console\Command\Shared\ArrayInputTrait. | ||
*/ | ||
|
||
namespace Drupal\Console\Command\Shared; | ||
|
||
/** | ||
* Class ArrayInputTrait | ||
* | ||
* @package Drupal\Console\Command | ||
*/ | ||
trait ArrayInputTrait | ||
{ | ||
/** | ||
* Parse strings to array '"key":"value","key1":"value1"'. | ||
* | ||
* @param string $inlineInputs | ||
* Input from the user. | ||
* @return array | ||
* Input array. | ||
*/ | ||
public function explodeInlineArray($inlineInputs) | ||
{ | ||
$inputs = []; | ||
foreach ($inlineInputs as $inlineInput) { | ||
$explodeInput = explode(',', $inlineInput); | ||
$parameters = []; | ||
foreach ($explodeInput as $inlineParameter) { | ||
$inlineParameter = trim($inlineParameter); | ||
list($key, $value) = explode(':', $inlineParameter); | ||
$key = rtrim(ltrim($key, '"'), '"'); | ||
$value = rtrim(ltrim($value, '"'), '"'); | ||
if (!empty($value)) { | ||
$parameters[$key] = $value; | ||
} | ||
} | ||
$inputs[] = $parameters; | ||
} | ||
|
||
return $inputs; | ||
} | ||
} |