Version 1
[yaffs-website] / vendor / drupal / console / src / Generator / ThemeGenerator.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Generator\ThemeGenerator.
6  */
7
8 namespace Drupal\Console\Generator;
9
10 use Drupal\Console\Core\Generator\Generator;
11 use Drupal\Console\Extension\Manager;
12
13 /**
14  *
15  */
16 class ThemeGenerator extends Generator
17 {
18     /**
19      * @var Manager
20      */
21     protected $extensionManager;
22
23     /**
24      * AuthenticationProviderGenerator constructor.
25      *
26      * @param Manager $extensionManager
27      */
28     public function __construct(
29         Manager $extensionManager
30     ) {
31         $this->extensionManager = $extensionManager;
32     }
33
34     public function generate(
35         $theme,
36         $machine_name,
37         $dir,
38         $description,
39         $core,
40         $package,
41         $base_theme,
42         $global_library,
43         $regions,
44         $breakpoints
45     ) {
46         $dir .= '/' . $machine_name;
47         if (file_exists($dir)) {
48             if (!is_dir($dir)) {
49                 throw new \RuntimeException(
50                     sprintf(
51                         'Unable to generate the bundle as the target directory "%s" exists but is a file.',
52                         realpath($dir)
53                     )
54                 );
55             }
56             $files = scandir($dir);
57             if ($files != ['.', '..']) {
58                 throw new \RuntimeException(
59                     sprintf(
60                         'Unable to generate the bundle as the target directory "%s" is not empty.',
61                         realpath($dir)
62                     )
63                 );
64             }
65             if (!is_writable($dir)) {
66                 throw new \RuntimeException(
67                     sprintf(
68                         'Unable to generate the bundle as the target directory "%s" is not writable.',
69                         realpath($dir)
70                     )
71                 );
72             }
73         }
74
75         $parameters = [
76         'theme' => $theme,
77         'machine_name' => $machine_name,
78         'type' => 'theme',
79         'core' => $core,
80         'description' => $description,
81         'package' => $package,
82         'base_theme' => $base_theme,
83         'global_library' => $global_library,
84         'regions' => $regions,
85         'breakpoints' => $breakpoints,
86         ];
87
88         $this->renderFile(
89             'theme/info.yml.twig',
90             $dir . '/' . $machine_name . '.info.yml',
91             $parameters
92         );
93
94         $this->renderFile(
95             'theme/theme.twig',
96             $dir . '/' . $machine_name . '.theme',
97             $parameters
98         );
99
100         if ($breakpoints) {
101             $this->renderFile(
102                 'theme/breakpoints.yml.twig',
103                 $dir . '/' . $machine_name . '.breakpoints.yml',
104                 $parameters
105             );
106         }
107     }
108 }