Version 1
[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     public function generate(
15         $profile,
16         $machine_name,
17         $profile_path,
18         $description,
19         $core,
20         $dependencies,
21         $distribution
22     ) {
23         $dir = $profile_path . '/' . $machine_name;
24
25         if (file_exists($dir)) {
26             if (!is_dir($dir)) {
27                 throw new \RuntimeException(
28                     sprintf(
29                         'Unable to generate the profile as the target directory "%s" exists but is a file.',
30                         realpath($dir)
31                     )
32                 );
33             }
34             $files = scandir($dir);
35             if ($files != ['.', '..']) {
36                 throw new \RuntimeException(
37                     sprintf(
38                         'Unable to generate the profile as the target directory "%s" is not empty.',
39                         realpath($dir)
40                     )
41                 );
42             }
43             if (!is_writable($dir)) {
44                 throw new \RuntimeException(
45                     sprintf(
46                         'Unable to generate the profile as the target directory "%s" is not writable.',
47                         realpath($dir)
48                     )
49                 );
50             }
51         }
52
53         $parameters = [
54           'profile' => $profile,
55           'machine_name' => $machine_name,
56           'type' => 'profile',
57           'core' => $core,
58           'description' => $description,
59           'dependencies' => $dependencies,
60           'distribution' => $distribution,
61         ];
62
63         $this->renderFile(
64             'profile/info.yml.twig',
65             $dir . '/' . $machine_name . '.info.yml',
66             $parameters
67         );
68
69         $this->renderFile(
70             'profile/profile.twig',
71             $dir . '/' . $machine_name . '.profile',
72             $parameters
73         );
74
75         $this->renderFile(
76             'profile/install.twig',
77             $dir . '/' . $machine_name . '.install',
78             $parameters
79         );
80     }
81 }