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