Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Generator / ModuleGenerator.php
index f7c2ed0a79c3623bdd5217b714fb4dfb2a2af571..04ea950961a212c59489a42114881f017f8e8948 100644 (file)
@@ -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
             );
         }