forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleGenerator.php
More file actions
103 lines (92 loc) · 2.91 KB
/
Copy pathModuleGenerator.php
File metadata and controls
103 lines (92 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* @file
* Contains \Drupal\AppConsole\Generator\ModuleGenerator.
*/
namespace Drupal\AppConsole\Generator;
class ModuleGenerator extends Generator
{
public function generate(
$module,
$machine_name,
$dir,
$description,
$core,
$package,
$controller,
$composer,
$dependencies,
$tests
) {
$dir .= '/' . $machine_name;
if (file_exists($dir)) {
if (!is_dir($dir)) {
throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" exists but is a file.',
realpath($dir)));
}
$files = scandir($dir);
if ($files != array('.', '..')) {
throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not empty.',
realpath($dir)));
}
if (!is_writable($dir)) {
throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not writable.',
realpath($dir)));
}
}
$parameters = array(
'module' => $module,
'machine_name' => $machine_name,
'type' => 'module',
'core' => $core,
'description' => $description,
'package' => $package,
'dependencies' => $dependencies
);
$this->renderFile(
'module/info.yml.twig',
$dir . '/' . $machine_name . '.info.yml',
$parameters
);
$this->renderFile(
'module/module.twig',
$dir . '/' . $machine_name . '.module',
$parameters
);
if ($composer) {
$this->renderFile(
'module/composer.json.twig',
$dir . '/' . 'composer.json',
$parameters
);
}
if ($controller) {
$class_name = 'DefaultController';
$parameters = array(
'class_name' => $class_name,
'module' => $machine_name,
'method_name' => 'hello',
'class_machine_name' => 'default_controller',
'route' => '/' . $machine_name . '/hello/{name}',
'services' => []
);
$this->renderFile(
'module/src/Controller/controller.php.twig',
$dir . '/src/Controller/' . $class_name . '.php',
$parameters
);
$this->renderFile(
'module/routing-controller.yml.twig',
$dir . '/' . $machine_name . '.routing.yml',
$parameters
);
if ($tests) {
$this->renderFile(
'module/Tests/Controller/controller.php.twig',
$dir . '/Tests/Controller/' . $class_name . 'Test.php',
$parameters
);
}
}
}
}