b66b0f54ae4cbd867a5438e4cdb896ecac4b1b80
[yaffs-website] / vendor / drupal / console / src / Generator / ProfileGenerator.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Generator\ProfileGenerator.
6  */
7
8 namespace Drupal\Console\Generator;
9
10 use Drupal\Console\Core\Generator\Generator;
11
12 class ProfileGenerator extends Generator
13 {
14     /**
15      * {@inheritdoc}
16      */
17     public function generate(array $parameters)
18     {
19         $dir = $parameters['dir'];
20         $machine_name = $parameters['machine_name'];
21
22         $dir = ($dir == '/' ? '' : $dir) . '/' . $machine_name;
23         if (file_exists($dir)) {
24             if (!is_dir($dir)) {
25                 throw new \RuntimeException(
26                     sprintf(
27                         'Unable to generate the profile as the target directory "%s" exists but is a file.',
28                         realpath($dir)
29                     )
30                 );
31             }
32             $files = scandir($dir);
33             if ($files != ['.', '..']) {
34                 throw new \RuntimeException(
35                     sprintf(
36                         'Unable to generate the profile as the target directory "%s" is not empty.',
37                         realpath($dir)
38                     )
39                 );
40             }
41             if (!is_writable($dir)) {
42                 throw new \RuntimeException(
43                     sprintf(
44                         'Unable to generate the profile as the target directory "%s" is not writable.',
45                         realpath($dir)
46                     )
47                 );
48             }
49         }
50
51         $profilePath = $dir . '/' . $machine_name;
52
53
54         $this->renderFile(
55             'profile/info.yml.twig',
56             $profilePath . '.info.yml',
57             $parameters
58         );
59
60         $this->renderFile(
61             'profile/profile.twig',
62             $profilePath . '.profile',
63             $parameters
64         );
65
66         $this->renderFile(
67             'profile/install.twig',
68             $profilePath . '.install',
69             $parameters
70         );
71     }
72 }