diff --git a/src/Command/Generate/ModuleCommand.php b/src/Command/Generate/ModuleCommand.php index dbaa48097..6ce3940d5 100644 --- a/src/Command/Generate/ModuleCommand.php +++ b/src/Command/Generate/ModuleCommand.php @@ -200,18 +200,20 @@ protected function execute(InputInterface $input, OutputInterface $output) $twigTemplate = $input->getOption('twigtemplate'); $this->generator->generate( - $module, - $machineName, - $modulePath, - $description, - $core, - $package, - $moduleFile, - $featuresBundle, - $composer, - $dependencies, - $test, - $twigTemplate + [ + 'module' => $module, + 'machine_name' => $machineName, + 'module_path' => $modulePath, + 'description' => $description, + 'core' => $core, + 'package' => $package, + 'module_file' => $moduleFile, + 'features_bundle' => $featuresBundle, + 'composer' => $composer, + 'dependencies' => $dependencies, + 'test' => $test, + 'twig_template' => $twigTemplate + ] ); return 0; diff --git a/src/Generator/CommandGenerator.php b/src/Generator/CommandGenerator.php index e956ca5f7..292a54803 100644 --- a/src/Generator/CommandGenerator.php +++ b/src/Generator/CommandGenerator.php @@ -46,8 +46,8 @@ public function __construct( /** * {@inheritdoc} */ - public function generate(array $parameters) { - + public function generate(array $parameters) + { $extension = $parameters['extension']; $extensionType = $parameters['extension_type']; $name = $parameters['name']; @@ -57,18 +57,19 @@ public function generate(array $parameters) { $command_key = str_replace(':', '.', $name); - $extensionObject = $this->extensionManager + $extensionInstance = $this->extensionManager ->getDrupalExtension($extensionType, $extension); - $extensionObjectPath = $extensionObject->getPath(); + + $extensionObjectPath = $extensionInstance->getPath(); $parameters = array_merge( - $parameters,[ - 'command_key' => $command_key, - 'tags' => [ 'name' => 'drupal.command' ], - 'class_path' => sprintf('Drupal\%s\Command\%s', $extension, $class), - 'file_exists' => file_exists($extensionObjectPath . '/console.services.yml'), - 'class_generator_path' => sprintf('Drupal\%s\Command\%s', $extension, $class_generator), - ]); + $parameters, [ + 'command_key' => $command_key, + 'tags' => [ 'name' => 'drupal.command' ], + 'class_path' => sprintf('Drupal\%s\Command\%s', $extension, $class), + 'file_exists' => file_exists($extensionObjectPath . '/console.services.yml'), + ] + ); $commandServiceName = $extension . '.' . str_replace(':', '_', $name); $generatorServiceName = $commandServiceName . '_generator'; @@ -86,7 +87,7 @@ public function generate(array $parameters) { $this->renderFile( 'module/src/Command/command.php.twig', - $extensionObject->getCommandDirectory() . $class . '.php', + $extensionInstance->getCommandDirectory() . $class . '.php', $parameters ); @@ -105,12 +106,6 @@ public function generate(array $parameters) { ); if ($generator) { - $this->renderFile( - 'module/src/Generator/generator.php.twig', - $extensionObject->getGeneratorDirectory() . $class_generator . '.php', - $parameters - ); - $parameters = array_merge( $parameters, [ @@ -120,11 +115,15 @@ public function generate(array $parameters) { 'tags' => [ 'name' => 'drupal.generator' ], 'class_path' => sprintf('Drupal\%s\Generator\%s', $extension, $class_generator), 'file_exists' => file_exists($extensionObjectPath . '/console.services.yml'), - 'class_generator' => $class_generator, - 'class_generator_path' => sprintf('Drupal\%s\Generator\%s', $extension, $class_generator), ] ); + $this->renderFile( + 'module/src/Generator/generator.php.twig', + $extensionInstance->getGeneratorDirectory() . $class_generator . '.php', + $parameters + ); + $this->renderFile( 'module/services.yml.twig', $extensionObjectPath .'/console.services.yml', diff --git a/src/Generator/HelpGenerator.php b/src/Generator/HelpGenerator.php index 21076eb89..4dfc583da 100644 --- a/src/Generator/HelpGenerator.php +++ b/src/Generator/HelpGenerator.php @@ -7,6 +7,7 @@ namespace Drupal\Console\Generator; +use Drupal\Console\Core\Generator\GeneratorInterface; use Drupal\Console\Core\Generator\Generator; use Drupal\Console\Core\Generator\GeneratorInterface; use Drupal\Console\Extension\Manager; diff --git a/src/Generator/ModuleGenerator.php b/src/Generator/ModuleGenerator.php index c6ceddb35..3e00131d2 100644 --- a/src/Generator/ModuleGenerator.php +++ b/src/Generator/ModuleGenerator.php @@ -24,56 +24,54 @@ class ModuleGenerator extends Generator implements GeneratorInterface public function generate(array $parameters) { $machineName = $parameters['machine_name']; - $dir = $parameters['dir']; + $modulePath = $parameters['module_path']; $moduleFile = $parameters['module_file']; $featuresBundle = $parameters['features_bundle']; $composer = $parameters['composer']; $test = $parameters['test']; - $twigtemplate = $parameters['twigtemplate']; + $twigTemplate = $parameters['twig_template']; - $dir = ($dir == '/' ? '': $dir) . '/' . $machineName; - if (file_exists($dir)) { - if (!is_dir($dir)) { + $moduleDirectory = ($modulePath == '/' ? '': $modulePath) . '/' . $machineName; + if (file_exists($moduleDirectory)) { + if (!is_dir($moduleDirectory)) { throw new \RuntimeException( sprintf( 'Unable to generate the module as the target directory "%s" exists but is a file.', - realpath($dir) + realpath($moduleDirectory) ) ); } - $files = scandir($dir); + $files = scandir($moduleDirectory); if ($files != ['.', '..']) { throw new \RuntimeException( sprintf( 'Unable to generate the module as the target directory "%s" is not empty.', - realpath($dir) + realpath($moduleDirectory) ) ); } - if (!is_writable($dir)) { + if (!is_writable($moduleDirectory)) { throw new \RuntimeException( sprintf( 'Unable to generate the module as the target directory "%s" is not writable.', - realpath($dir) + realpath($moduleDirectory) ) ); } } - $parameters = [ - 'type' => 'module', - ]; + $parameters['type'] = 'module'; $this->renderFile( 'module/info.yml.twig', - $dir . '/' . $machineName . '.info.yml', + $moduleDirectory . '/' . $machineName . '.info.yml', $parameters ); if (!empty($featuresBundle)) { $this->renderFile( 'module/features.yml.twig', - $dir . '/' . $machineName . '.features.yml', + $moduleDirectory . '/' . $machineName . '.features.yml', [ 'bundle' => $featuresBundle, ] @@ -81,14 +79,13 @@ public function generate(array $parameters) } if ($moduleFile) { - // Generate '.module' file. - $this->createModuleFile($dir, $parameters); + $this->createModuleFile($moduleDirectory, $parameters); } if ($composer) { $this->renderFile( 'module/composer.json.twig', - $dir . '/' . 'composer.json', + $moduleDirectory . '/' . 'composer.json', $parameters ); } @@ -96,53 +93,53 @@ public function generate(array $parameters) if ($test) { $this->renderFile( 'module/src/Tests/load-test.php.twig', - $dir . '/tests/src/Functional/' . 'LoadTest.php', + $moduleDirectory . '/tests/src/Functional/' . 'LoadTest.php', $parameters ); } - if ($twigtemplate) { + if ($twigTemplate) { // If module file is not created earlier, create now. if (!$moduleFile) { // Generate '.module' file. - $this->createModuleFile($dir, $parameters); + $this->createModuleFile($moduleDirectory, $parameters); } $this->renderFile( 'module/module-twig-template-append.twig', - $dir . '/' . $machineName . '.module', + $moduleDirectory . '/' . $machineName . '.module', $parameters, FILE_APPEND ); - $dir .= '/templates/'; - if (file_exists($dir)) { - if (!is_dir($dir)) { + $moduleDirectory .= '/templates/'; + if (file_exists($moduleDirectory)) { + if (!is_dir($moduleDirectory)) { throw new \RuntimeException( sprintf( 'Unable to generate the templates directory as the target directory "%s" exists but is a file.', - realpath($dir) + realpath($moduleDirectory) ) ); } - $files = scandir($dir); + $files = scandir($moduleDirectory); if ($files != ['.', '..']) { throw new \RuntimeException( sprintf( 'Unable to generate the templates directory as the target directory "%s" is not empty.', - realpath($dir) + realpath($moduleDirectory) ) ); } - if (!is_writable($dir)) { + if (!is_writable($moduleDirectory)) { throw new \RuntimeException( sprintf( 'Unable to generate the templates directory as the target directory "%s" is not writable.', - realpath($dir) + realpath($moduleDirectory) ) ); } } $this->renderFile( 'module/twig-template-file.twig', - $dir . str_replace('_', '-', $machineName) . '.html.twig', + $moduleDirectory . str_replace('_', '-', $machineName) . '.html.twig', $parameters ); } diff --git a/templates/module/src/Generator/generator.php.twig b/templates/module/src/Generator/generator.php.twig index 0d3195ce1..00f749668 100644 --- a/templates/module/src/Generator/generator.php.twig +++ b/templates/module/src/Generator/generator.php.twig @@ -1,7 +1,7 @@ {% extends "base/class.php.twig" %} {% block file_path %} -\Drupal\{{extension}}\Generator\{{ class_generator }}. +\Drupal\{{extension}}\Generator\{{ class }}. {% endblock %} {% block namespace_class %} @@ -15,11 +15,11 @@ use Drupal\Console\Core\Generator\GeneratorInterface; {% block class_declaration %} /** - * Class {{ class_generator }} + * Class {{ class_name }} * * @package Drupal\Console\Generator */ -class {{ class_generator }} extends Generator implements GeneratorInterface +class {{ class_name }} extends Generator implements GeneratorInterface {% endblock %} {% block class_methods %}