diff examples/ExampleGenerator.php.stub @ 4:a20439b1c9d3

Added Model generator and other updates.
author luka
date Tue, 27 Jun 2023 20:16:55 -0400
parents 6468684362c2
children b0b2e79ad8e6
line wrap: on
line diff
--- a/examples/ExampleGenerator.php.stub	Tue Jun 27 15:32:47 2023 -0400
+++ b/examples/ExampleGenerator.php.stub	Tue Jun 27 20:16:55 2023 -0400
@@ -1,17 +1,15 @@
 <?php
 
-namespace App\Console\Commands;
+namespace Wizzard\MagicForger\Generator\Controller;
 
 use Symfony\Component\Console\Attribute\AsCommand;
 use Wizzard\MagicForger\Generator\BaseGenerator;
 use Wizzard\MagicForger\Replacer;
-//use Illuminate\Console\Concerns\CreatesMatchingTest;
+use Illuminate\Support\Str;
 
 #[AsCommand(name: 'mf:{{ Command Name }}')]
 class {{ Class Name }}Generator extends BaseGenerator
 {
-    //use CreatesMatchingTest;
-
     /**
      * The name and signature of the console command.
      *
@@ -33,7 +31,6 @@
      */
     protected $type = '{{ Class Name }}';
 
-
     /**
      * Execute the console command.
      */
@@ -49,7 +46,7 @@
      */
     protected function getStub()
     {
-        return $this->resolveStubPath('/stubs/seeder.stub');
+        return $this->resolveStubPath('/stubs/{{ Command Name }}.stub');
     }
 
     /**
@@ -64,27 +61,20 @@
             ? $customPath
             : __DIR__.$stub;
     }
+
+    protected function getClassName($name)
+    {
+        return $this->{{ Command Name }}_name($name);
+    }
+
     /**
-     * Parse the class name and format according to the root namespace.
+     * Get the stub file for the generator.
      *
-     * @param  string  $name
      * @return string
      */
-    protected function qualifyClass($name)
+    protected function getPath($name = null)
     {
-        $name = ltrim($name, '\\/');
-
-        $name = str_replace('/', '\\', $name);
-
-        $rootNamespace = $this->rootNamespace();
-
-        if (Str::startsWith($name, $rootNamespace)) {
-            return $name;
-        }
-
-        return $this->qualifyClass(
-            $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name
-        );
+        return str_replace(['App\\', '\\'], ['app/', '/'], $this->get{{ Class Name }}Namespace() . '/' . $this->{{ Command Name }}_name($this->getTableInput()) . '.php');
     }
 }