X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FGenerator%2FModuleGenerator.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FGenerator%2FModuleGenerator.php;h=04ea950961a212c59489a42114881f017f8e8948;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=f7c2ed0a79c3623bdd5217b714fb4dfb2a2af571;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/vendor/drupal/console/src/Generator/ModuleGenerator.php b/vendor/drupal/console/src/Generator/ModuleGenerator.php index f7c2ed0a7..04ea95096 100644 --- a/vendor/drupal/console/src/Generator/ModuleGenerator.php +++ b/vendor/drupal/console/src/Generator/ModuleGenerator.php @@ -16,100 +16,75 @@ use Drupal\Console\Core\Generator\Generator; */ class ModuleGenerator extends Generator { + /** - * @param $module - * @param $machineName - * @param $dir - * @param $description - * @param $core - * @param $package - * @param $moduleFile - * @param $featuresBundle - * @param $composer - * @param $dependencies - * @param $test - * @param $twigtemplate + * {@inheritdoc} */ - public function generate( - $module, - $machineName, - $dir, - $description, - $core, - $package, - $moduleFile, - $featuresBundle, - $composer, - $dependencies, - $test, - $twigtemplate - ) { - $dir .= '/'.$machineName; - if (file_exists($dir)) { - if (!is_dir($dir)) { + public function generate(array $parameters) + { + $machineName = $parameters['machine_name']; + $modulePath = $parameters['module_path']; + $moduleFile = $parameters['module_file']; + $featuresBundle = $parameters['features_bundle']; + $composer = $parameters['composer']; + $test = $parameters['test']; + $twigTemplate = $parameters['twig_template']; + + $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 = [ - 'module' => $module, - 'machine_name' => $machineName, - 'type' => 'module', - 'core' => $core, - 'description' => $description, - 'package' => $package, - 'dependencies' => $dependencies, - 'test' => $test, - 'twigtemplate' => $twigtemplate, - ]; + $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, + 'bundle' => $featuresBundle, ] ); } 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 ); } @@ -117,53 +92,53 @@ class ModuleGenerator extends Generator 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 ); }