8dd2807fb2380b284573593bf76acc5f652ba1d4
[yaffs-website] / vendor / drupal / console / src / Generator / PluginTypeYamlGenerator.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Generator\PluginTypeYamlGenerator.
6  */
7
8 namespace Drupal\Console\Generator;
9
10 use Drupal\Console\Core\Generator\Generator;
11 use Drupal\Console\Extension\Manager;
12
13 class PluginTypeYamlGenerator extends Generator
14 {
15     /**
16      * @var Manager
17      */
18     protected $extensionManager;
19
20     /**
21      * PluginTypeYamlGenerator constructor.
22      *
23      * @param Manager $extensionManager
24      */
25     public function __construct(
26         Manager $extensionManager
27     ) {
28         $this->extensionManager = $extensionManager;
29     }
30
31     /**
32      * Generator for Plugin type with Yaml discovery.
33      *
34      * @param $module
35      * @param $plugin_class
36      * @param $plugin_name
37      * @param $plugin_file_name
38      */
39     public function generate($module, $plugin_class, $plugin_name, $plugin_file_name)
40     {
41         $parameters = [
42             'module' => $module,
43             'plugin_class' => $plugin_class,
44             'plugin_name' => $plugin_name,
45             'plugin_file_name' => $plugin_file_name,
46             'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath()  . '/' . $module . '.services.yml'),
47         ];
48
49         $this->renderFile(
50             'module/src/yaml-plugin-manager.php.twig',
51             $this->extensionManager->getModule($module)->getSourcePath() . '/' . $plugin_class . 'Manager.php',
52             $parameters
53         );
54
55         $this->renderFile(
56             'module/src/yaml-plugin-manager-interface.php.twig',
57             $this->extensionManager->getModule($module)->getSourcePath() . '/' . $plugin_class . 'ManagerInterface.php',
58             $parameters
59         );
60
61         $this->renderFile(
62             'module/plugin-yaml-services.yml.twig',
63             $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.services.yml',
64             $parameters,
65             FILE_APPEND
66         );
67
68         $this->renderFile(
69             'module/plugin.yml.twig',
70             $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.' . $plugin_file_name . '.yml',
71             $parameters
72         );
73     }
74 }