Security update for Core, with self-updated composer
[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     /**
35      * {@inheritdoc}
36      */
37     public function generate(array $parameters)
38     {
39         $dir = $parameters['dir'];
40         $breakpoints = $parameters['breakpoints'];
41         $libraries = $parameters['libraries'];
42         $machine_name = $parameters['machine_name'];
43         $parameters['type'] = 'theme';
44
45         $dir = ($dir == '/' ? '': $dir) . '/' . $machine_name;
46         if (file_exists($dir)) {
47             if (!is_dir($dir)) {
48                 throw new \RuntimeException(
49                     sprintf(
50                         'Unable to generate the bundle as the target directory "%s" exists but is a file.',
51                         realpath($dir)
52                     )
53                 );
54             }
55             $files = scandir($dir);
56             if ($files != ['.', '..']) {
57                 throw new \RuntimeException(
58                     sprintf(
59                         'Unable to generate the bundle as the target directory "%s" is not empty.',
60                         realpath($dir)
61                     )
62                 );
63             }
64             if (!is_writable($dir)) {
65                 throw new \RuntimeException(
66                     sprintf(
67                         'Unable to generate the bundle as the target directory "%s" is not writable.',
68                         realpath($dir)
69                     )
70                 );
71             }
72         }
73
74         $themePath = $dir . '/' . $machine_name;
75
76         $this->renderFile(
77             'theme/info.yml.twig',
78             $themePath . '.info.yml',
79             $parameters
80         );
81
82         $this->renderFile(
83             'theme/theme.twig',
84             $themePath . '.theme',
85             $parameters
86         );
87
88         if ($libraries) {
89             $this->renderFile(
90                 'theme/libraries.yml.twig',
91                 $themePath . '.libraries.yml',
92                 $parameters
93             );
94         }
95
96         if ($breakpoints) {
97             $this->renderFile(
98                 'theme/breakpoints.yml.twig',
99                 $themePath . '.breakpoints.yml',
100                 $parameters
101             );
102         }
103     }
104 }