Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Generator / ModuleFileGenerator.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Generator\ModuleFileGenerator.
6  */
7
8 namespace Drupal\Console\Generator;
9
10 use Drupal\Console\Core\Generator\Generator;
11
12 /**
13  * Class ModuleFileGenerator
14  *
15  * @package Drupal\Console\Generator
16  */
17 class ModuleFileGenerator extends Generator
18 {
19     /**
20      * @param $machine_name
21      * @param $file_path
22      */
23     public function generate(
24         $machine_name,
25         $file_path
26     ) {
27         $dir = $file_path .'/'. $machine_name. '.module';
28       
29         if (file_exists($dir)) {
30             if (!is_dir($dir)) {
31                 throw new \RuntimeException(
32                     sprintf(
33                         'Unable to generate the .module file , it already exist at "%s"',
34                         realpath($dir)
35                     )
36                 );
37             }
38         }
39
40         $parameters = [
41           'machine_name' => $machine_name,
42           'file_path' => $file_path ,
43         ];
44
45         if ($machine_name) {
46             $this->renderFile(
47                 'module/module-file.twig',
48                 $file_path . '/' . $machine_name . '.module',
49                 $parameters
50             );
51         }
52     }
53 }