ff8d3fc381855e087027542d458e85dc24d7ab93
[yaffs-website] / vendor / drupal / console-core / src / Generator / InitGenerator.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Core\Generator\InitGenerator.
6  */
7 namespace Drupal\Console\Core\Generator;
8
9 /**
10  * Class InitGenerator
11  * @package Drupal\Console\Core\Generator
12  */
13 class InitGenerator extends Generator
14 {
15     /**
16      * @param string  $userHome
17      * @param string  $executableName
18      * @param boolean $override
19      * @param string  $destination
20      * @param array   $configParameters
21      */
22     public function generate(
23         $userHome,
24         $executableName,
25         $override,
26         $destination,
27         $configParameters
28     ) {
29         $configParameters = array_map(
30             function ($item) {
31                 if (is_bool($item)) {
32                     return $item?"true":"false";
33                 }
34                 return $item;
35             },
36             $configParameters
37         );
38
39         $configFile = $userHome . 'config.yml';
40         if ($destination) {
41             $configFile = $destination.'config.yml';
42         }
43
44         if (file_exists($configFile) && $override) {
45             copy(
46                 $configFile,
47                 $configFile . '.old'
48             );
49         }
50
51         $this->renderFile(
52             'core/init/config.yml.twig',
53             $configFile,
54             $configParameters
55         );
56
57         if ($executableName) {
58             $parameters = [
59                 'executable' => $executableName,
60             ];
61
62             $this->renderFile(
63                 'core/autocomplete/console.rc.twig',
64                 $userHome . 'console.rc',
65                 $parameters
66             );
67
68             $this->renderFile(
69                 'core/autocomplete/console.fish.twig',
70                 $userHome . 'drupal.fish',
71                 $parameters
72             );
73         }
74     }
75 }