Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Shared / ArrayInputTrait.php
diff --git a/vendor/drupal/console/src/Command/Shared/ArrayInputTrait.php b/vendor/drupal/console/src/Command/Shared/ArrayInputTrait.php
new file mode 100644 (file)
index 0000000..a6a0161
--- /dev/null
@@ -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;
+    }
+}