]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 24 May 2019 16:37:28 +0000 (18:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 24 May 2019 16:37:28 +0000 (18:37 +0200)
src/CubistBackpackServiceProvider.php
src/app/Console/Commands/CubistCommand.php [new file with mode: 0644]
src/app/Console/Commands/GenerateCommand.php [new file with mode: 0644]
src/app/Console/Commands/MagicCubistCommand.php [deleted file]
src/app/Console/Commands/MigrateCommand.php [new file with mode: 0644]
src/app/Magic/Models/CubistMagicModelAbstract.php

index 4f247594739b2b5d40dee5e7416fed5ce7eeb459..2d6f5474bda04cc871b1fa835829694b5b862c7d 100644 (file)
@@ -2,7 +2,8 @@
 
 namespace Cubist\Backpack;
 
-use Cubist\Backpack\app\Console\Commands\MagicCubistCommand;
+use app\Console\Command\MigrateCommand;
+use Cubist\Backpack\app\Console\Commands\GenerateCommand;
 use Illuminate\Support\ServiceProvider;
 use Route;
 
@@ -47,6 +48,6 @@ class CubistBackpackServiceProvider extends ServiceProvider
 //        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
 //        $loader->alias('Template', \Backpack\Settings\app\Models\Template::class);
 
-        $this->commands([MagicCubistCommand::class]);
+        $this->commands([GenerateCommand::class, MigrateCommand::class]);
     }
 }
diff --git a/src/app/Console/Commands/CubistCommand.php b/src/app/Console/Commands/CubistCommand.php
new file mode 100644 (file)
index 0000000..fe525ba
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+
+
+namespace app\Console\Commands;
+
+
+use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
+use Cubist\Util\Files\Files;
+use Cubist\Util\PHP;
+use Illuminate\Console\Command;
+use Symfony\Component\Process\Exception\ProcessFailedException;
+use Symfony\Component\Process\Process;
+
+class CubistCommand extends Command
+{
+
+    /**
+     * Run a SSH command.
+     *
+     * @param string $command The SSH command that needs to be run
+     * @param bool $beforeNotice Information for the user before the command is run
+     * @param bool $afterNotice Information for the user after the command is run
+     *
+     * @return mixed Command-line output
+     */
+    public function executeProcess($command, $beforeNotice = false, $afterNotice = false)
+    {
+        $this->echo('info', $beforeNotice ? ' ' . $beforeNotice : $command);
+
+        $process = new Process($command, null, null, null, 50, null);
+        $process->run(function ($type, $buffer) {
+            if (Process::ERR === $type) {
+                $this->echo('comment', $buffer);
+            } else {
+                $this->echo('line', $buffer);
+            }
+        });
+
+        // executes after the command finishes
+        if (!$process->isSuccessful()) {
+            throw new ProcessFailedException($process);
+        }
+
+        if ($afterNotice) {
+            $this->echo('info', $afterNotice);
+        }
+    }
+
+    /**
+     * Write text to the screen for the user to see.
+     *
+     * @param [string] $type    line, info, comment, question, error
+     * @param [string] $content
+     */
+    public function echo($type, $content)
+    {
+        // skip empty lines
+        if (trim($content)) {
+            $this->{$type}($content);
+        }
+    }
+
+    protected function _handleMagicFolder($callback)
+    {
+        $magic = app_path() . '/Models';
+
+        $iterator = Files::getDirectoryIterator($magic, true);
+        foreach ($iterator as $item) {
+            $this->line('Testing ' . $item);
+            /** @var $item \SplFileInfo */
+            if ($item->isFile() && $item->getExtension() == 'php') {
+                try {
+                    $class = PHP::instanciateClassInFile($item);
+                    if ($class instanceof CubistMagicModelAbstract) {
+                        if (is_callable($callback)) {
+                            call_user_func($callback, $class);
+                        }
+                    }
+                } catch (\Exception $e) {
+                }
+            }
+        }
+    }
+}
diff --git a/src/app/Console/Commands/GenerateCommand.php b/src/app/Console/Commands/GenerateCommand.php
new file mode 100644 (file)
index 0000000..54ba587
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+namespace Cubist\Backpack\app\Console\Commands;
+
+use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
+use Cubist\Backpack\app\Magic\Util;
+use Cubist\Util\Files\Files;
+use Cubist\Util\PHP;
+
+class GenerateCommand extends CubistCommand
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'cubist:magic:generate';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Generate Controllers, Requests, Routes, migrations according to magic';
+
+    protected $_routes = [];
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->_handleMagicFolder([$this, '_generate']);
+        $this->_writeRoutes();
+
+        //Artisan::call('cache:clear');
+        //Artisan::call('optimize');
+        $this->executeProcess('composer dump-autoload');
+    }
+
+    protected function _writeRoutes()
+    {
+        $routesDir = base_path() . '/routes/backpack';
+        if (!file_exists($routesDir)) {
+            mkdir($routesDir, 0777, true);
+        }
+        $stub = file_get_contents(Util::getStubPath() . '/routes.stub');
+        $stub = str_replace('_CUSTOM_', implode("\n", $this->_routes), $stub);
+
+        file_put_contents($routesDir . '/custom.php', $stub);
+    }
+
+    /**
+     * @param $model CubistMagicModelAbstract
+     */
+    public function _generate($model)
+    {
+        $this->line('Generate code of ' . get_class($model));
+        $model->generateCode();
+        $this->_routes[] = 'CRUD::resource(\'' . $model->getOption('name') . '\', \'' . $model->getControllerClass() . '\');';
+    }
+
+}
+
+
diff --git a/src/app/Console/Commands/MagicCubistCommand.php b/src/app/Console/Commands/MagicCubistCommand.php
deleted file mode 100644 (file)
index 344c012..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-<?php
-
-namespace Cubist\Backpack\app\Console\Commands;
-
-use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
-use Cubist\Backpack\app\Magic\Util;
-use Cubist\Util\Files\Files;
-use Cubist\Util\PHP;
-use Illuminate\Console\Command;
-use Symfony\Component\Process\Exception\ProcessFailedException;
-use Symfony\Component\Process\Process;
-
-class MagicCubistCommand extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'cubist:magic:generate';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = 'Generate Controllers, Requests, Routes, migrations according to magic';
-
-    protected $_routes = [];
-
-    /**
-     * Execute the console command.
-     *
-     * @return mixed
-     */
-    public function handle()
-    {
-        $magic = app_path() . '/Models';
-        // Find cubistmagic directories
-
-        if (file_exists($magic)) {
-            $this->_handleMagicFolder($magic);
-        } else {
-            $this->line('No magic folder at ' . $magic);
-        }
-        $this->_writeRoutes();
-
-        //Artisan::call('cache:clear');
-        //Artisan::call('optimize');
-        $this->executeProcess('composer dump-autoload');
-    }
-
-    protected function _writeRoutes()
-    {
-        $routesDir = base_path() . '/routes/backpack';
-        if (!file_exists($routesDir)) {
-            mkdir($routesDir, 0777, true);
-        }
-        $stub = file_get_contents(Util::getStubPath() . '/routes.stub');
-        $stub = str_replace('_CUSTOM_', implode("\n", $this->_routes), $stub);
-
-        file_put_contents($routesDir . '/custom.php', $stub);
-    }
-
-    protected function _handleMagicFolder($folder)
-    {
-        $this->line('Handling folder ' . $folder);
-        $iterator = Files::getDirectoryIterator($folder, true);
-        foreach ($iterator as $item) {
-            $this->line('Testing ' . $item);
-            /** @var $item \SplFileInfo */
-            if ($item->isFile() && $item->getExtension() == 'php') {
-                try {
-                    $class = PHP::instanciateClassInFile($item);
-                    if ($class instanceof CubistMagicModelAbstract) {
-                        $this->line('Generate code of ' . get_class($class));
-                        $class->generateCode();
-                        $this->_routes[] = 'CRUD::resource(\'' . $class->getOption('name') . '\', \'' . $class->getControllerClass() . '\');';
-                    }
-                } catch (\Exception $e) {
-
-                }
-
-            }
-        }
-
-    }
-
-    /**
-     * Run a SSH command.
-     *
-     * @param string $command The SSH command that needs to be run
-     * @param bool $beforeNotice Information for the user before the command is run
-     * @param bool $afterNotice Information for the user after the command is run
-     *
-     * @return mixed Command-line output
-     */
-    public function executeProcess($command, $beforeNotice = false, $afterNotice = false)
-    {
-        $this->echo('info', $beforeNotice ? ' ' . $beforeNotice : $command);
-
-        $process = new Process($command, null, null, null, 50, null);
-        $process->run(function ($type, $buffer) {
-            if (Process::ERR === $type) {
-                $this->echo('comment', $buffer);
-            } else {
-                $this->echo('line', $buffer);
-            }
-        });
-
-        // executes after the command finishes
-        if (!$process->isSuccessful()) {
-            throw new ProcessFailedException($process);
-        }
-
-        if ($afterNotice) {
-            $this->echo('info', $afterNotice);
-        }
-    }
-
-    /**
-     * Write text to the screen for the user to see.
-     *
-     * @param [string] $type    line, info, comment, question, error
-     * @param [string] $content
-     */
-    public function echo($type, $content)
-    {
-        // skip empty lines
-        if (trim($content)) {
-            $this->{$type}($content);
-        }
-    }
-}
diff --git a/src/app/Console/Commands/MigrateCommand.php b/src/app/Console/Commands/MigrateCommand.php
new file mode 100644 (file)
index 0000000..19b9ae8
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+
+namespace app\Console\Command;
+
+use app\Console\Commands\CubistCommand;
+use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
+
+class MigrateCommand extends CubistCommand
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'cubist:magic:migrate';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Make database migrations for Magic Models';
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->_handleMagicFolder([$this, '_migrate']);
+    }
+
+    /**
+     * @param $model CubistMagicModelAbstract
+     */
+    public function _migrate($model)
+    {
+
+    }
+}
index 8a68f4c26b0043a657b5fdb55e348873a7435c06..a472d5265879f36ccb6615f67d722da473e767cd 100644 (file)
@@ -14,8 +14,6 @@ use Illuminate\Support\Str;
 
 class CubistMagicModelAbstract extends Model
 {
-
-
     use CubistMagicAttribute;
     use CrudTrait;
     use Sluggable, SluggableScopeHelpers;