Version 1
[yaffs-website] / vendor / drupal / console-core / src / Generator / InitGenerator.php
diff --git a/vendor/drupal/console-core/src/Generator/InitGenerator.php b/vendor/drupal/console-core/src/Generator/InitGenerator.php
new file mode 100644 (file)
index 0000000..ff8d3fc
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\Console\Core\Generator\InitGenerator.
+ */
+namespace Drupal\Console\Core\Generator;
+
+/**
+ * Class InitGenerator
+ * @package Drupal\Console\Core\Generator
+ */
+class InitGenerator extends Generator
+{
+    /**
+     * @param string  $userHome
+     * @param string  $executableName
+     * @param boolean $override
+     * @param string  $destination
+     * @param array   $configParameters
+     */
+    public function generate(
+        $userHome,
+        $executableName,
+        $override,
+        $destination,
+        $configParameters
+    ) {
+        $configParameters = array_map(
+            function ($item) {
+                if (is_bool($item)) {
+                    return $item?"true":"false";
+                }
+                return $item;
+            },
+            $configParameters
+        );
+
+        $configFile = $userHome . 'config.yml';
+        if ($destination) {
+            $configFile = $destination.'config.yml';
+        }
+
+        if (file_exists($configFile) && $override) {
+            copy(
+                $configFile,
+                $configFile . '.old'
+            );
+        }
+
+        $this->renderFile(
+            'core/init/config.yml.twig',
+            $configFile,
+            $configParameters
+        );
+
+        if ($executableName) {
+            $parameters = [
+                'executable' => $executableName,
+            ];
+
+            $this->renderFile(
+                'core/autocomplete/console.rc.twig',
+                $userHome . 'console.rc',
+                $parameters
+            );
+
+            $this->renderFile(
+                'core/autocomplete/console.fish.twig',
+                $userHome . 'drupal.fish',
+                $parameters
+            );
+        }
+    }
+}