diff src/Generator/Controller/ControllerGenerator.php @ 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/src/Generator/Controller/ControllerGenerator.php	Tue Jun 27 15:32:47 2023 -0400
+++ b/src/Generator/Controller/ControllerGenerator.php	Tue Jun 27 20:16:55 2023 -0400
@@ -7,13 +7,9 @@
 use Wizzard\MagicForger\Replacer;
 use Illuminate\Support\Str;
 
-//use Illuminate\Console\Concerns\CreatesMatchingTest;
-
 #[AsCommand(name: 'mf:controller')]
 class ControllerGenerator extends BaseGenerator
 {
-    //use CreatesMatchingTest;
-
     /**
      * The name and signature of the console command.
      *
@@ -35,46 +31,12 @@
      */
     protected $type = 'Controller';
 
-
     /**
      * Execute the console command.
      */
     public function handle()
     {
-
-
-        // First we need to ensure that the table exists, then we can
-        if (! $this->tableExists($this->getTableInput())) {
-            $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.');
-
-            return false;
-        }
-
-        $name = $this->qualifyClass($this->getTableInput());
-
-        $path = $this->getPath($name);
-
-        $file = $this->getFile($path);
-
-        $file = $this->apply_replacements($file);
-
-
-        // Next, we will generate the path to the location where this class' file should get
-        // written. Then, we will build the class and make the proper replacements on the
-        // file so that it gets the correctly formatted namespace and class name.
-        $path = $this->makeDirectory($path);
-
-        $this->files->put($path, $this->sortImports($file));
-
-        $info = $this->type;
-
-        if (in_array(CreatesMatchingTest::class, class_uses_recursive($this))) {
-            if ($this->handleTestCreation($path)) {
-                $info .= ' and test';
-            }
-        }
-
-        $this->components->info(sprintf('%s [%s] created successfully.', $info, $path));
+        parent::handle();
     }
 
     /**
@@ -99,28 +61,6 @@
             ? $customPath
             : __DIR__.$stub;
     }
-    /**
-     * Parse the class name and format according to the root namespace.
-     *
-     * @param  string  $name
-     * @return string
-     */
-    protected function qualifyClass($name)
-    {
-        $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
-        );
-    }
 
     protected function getClassName($name)
     {
@@ -132,7 +72,7 @@
      *
      * @return string
      */
-    protected function getPath($name)
+    protected function getPath($name = null)
     {
         return str_replace(['App\\', '\\'], ['app/', '/'], $this->getControllerNamespace() . '/' . $this->controller_name($this->getTableInput()) . '.php');
     }