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