From a6aa7b7d7d10c084d4ee240611d03197cdc2cd83 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 22 May 2019 18:56:48 +0200 Subject: [PATCH] #2783 --- .../Console/Commands/MagicCubistCommand.php | 9 +++--- .../Magic/Models/CubistMagicModelAbstract.php | 28 +++++++++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/app/Console/Commands/MagicCubistCommand.php b/src/app/Console/Commands/MagicCubistCommand.php index c68d31b..434b91c 100644 --- a/src/app/Console/Commands/MagicCubistCommand.php +++ b/src/app/Console/Commands/MagicCubistCommand.php @@ -50,6 +50,7 @@ class MagicCubistCommand extends Command $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') { $class = PHP::instanciateClassInFile($item); @@ -64,15 +65,15 @@ class MagicCubistCommand 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 + * @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); + $this->echo('info', $beforeNotice ? ' ' . $beforeNotice : $command); $process = new Process($command, null, null, null, $this->option('timeout'), null); $process->run(function ($type, $buffer) { diff --git a/src/app/Magic/Models/CubistMagicModelAbstract.php b/src/app/Magic/Models/CubistMagicModelAbstract.php index 0232730..170a36c 100644 --- a/src/app/Magic/Models/CubistMagicModelAbstract.php +++ b/src/app/Magic/Models/CubistMagicModelAbstract.php @@ -3,12 +3,10 @@ namespace Cubist\Backpack\app\Magic\Models; -use Cubist\Backpack\app\Magic\Controllers\CubistMagicController; use Cubist\Backpack\app\Magic\Fields\CubistMagicField; use Illuminate\Database\Eloquent\Model; use Cubist\Backpack\app\Magic\CubistMagicAttribute; use Illuminate\Support\Facades\Route; -use Backpack\CRUD; use Illuminate\Support\Str; class CubistMagicModelAbstract extends Model @@ -21,9 +19,27 @@ class CubistMagicModelAbstract extends Model */ protected $_fields = []; + /** + * @var array + */ + protected $_options = []; + public function __construct(array $attributes = []) { parent::__construct($attributes); + $this->init(); + } + + public function init(){ + + } + + public function getOption($key, $default = null) + { + if (isset($this->_options[$key])) { + return $this->_options[$key]; + } + return $default; } /** @@ -63,9 +79,9 @@ class CubistMagicModelAbstract extends Model protected function _replaceInCode($stub, $dest) { $vars = ['CAMELNAME' => $this->getCamelName(), - 'ROUTEURL' => $this->getAttribute('name'), - 'SINGULAR' => $this->getAttribute('singular', $this->getAttribute('name')), - 'PLURAL' => $this->getAttribute('plural', ''), + 'ROUTEURL' => $this->getOption('name'), + 'SINGULAR' => $this->getOption('singular', $this->getOption('name')), + 'PLURAL' => $this->getOption('plural', ''), 'MODELNAMESPACE' => __NAMESPACE__ . '\\' . get_class($this), 'FIELDS' => var_export($this->_fields, true) ]; @@ -85,6 +101,6 @@ class CubistMagicModelAbstract extends Model public function getCamelName() { - return Str::camel($this->getAttribute('name')); + return Str::camel($this->getOption('name')); } } -- 2.39.5