Security update for permissions_by_term
[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         $libraries,
44         $regions,
45         $breakpoints
46     ) {
47         $dir .= '/' . $machine_name;
48         if (file_exists($dir)) {
49             if (!is_dir($dir)) {
50                 throw new \RuntimeException(
51                     sprintf(
52                         'Unable to generate the bundle as the target directory "%s" exists but is a file.',
53                         realpath($dir)
54                     )
55                 );
56             }
57             $files = scandir($dir);
58             if ($files != ['.', '..']) {
59                 throw new \RuntimeException(
60                     sprintf(
61                         'Unable to generate the bundle as the target directory "%s" is not empty.',
62                         realpath($dir)
63                     )
64                 );
65             }
66             if (!is_writable($dir)) {
67                 throw new \RuntimeException(
68                     sprintf(
69                         'Unable to generate the bundle as the target directory "%s" is not writable.',
70                         realpath($dir)
71                     )
72                 );
73             }
74         }
75
76         $parameters = [
77         'theme' => $theme,
78         'machine_name' => $machine_name,
79         'type' => 'theme',
80         'core' => $core,
81         'description' => $description,
82         'package' => $package,
83         'base_theme' => $base_theme,
84         'global_library' => $global_library,
85         'libraries' => $libraries,
86         'regions' => $regions,
87         'breakpoints' => $breakpoints,
88         ];
89
90         $this->renderFile(
91             'theme/info.yml.twig',
92             $dir . '/' . $machine_name . '.info.yml',
93             $parameters
94         );
95
96         $this->renderFile(
97             'theme/theme.twig',
98             $dir . '/' . $machine_name . '.theme',
99             $parameters
100         );
101
102         if ($libraries) {
103             $this->renderFile(
104                 'theme/libraries.yml.twig',
105                 $dir . '/' . $machine_name . '.libraries.yml',
106                 $parameters
107             );
108         }
109
110         if ($breakpoints) {
111             $this->renderFile(
112                 'theme/breakpoints.yml.twig',
113                 $dir . '/' . $machine_name . '.breakpoints.yml',
114                 $parameters
115             );
116         }
117     }
118 }