From 103bba9a1696aca64575fcf5863af5e1a2233baa Mon Sep 17 00:00:00 2001 From: AntonyZ89 Date: Tue, 8 Dec 2020 00:11:22 -0300 Subject: [PATCH] minor fixes --- composer.json | 2 ++ functions.php | 13 +++++++++++++ src/SeederController.php | 11 ++++++----- src/views/createTableSeeder.php | 5 ++--- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index f13bd8b..f54713a 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,8 @@ } ], "require": { + "php": ">=7.0", + "ext-mbstring": "*", "yiisoft/yii2": "^2.0.5", "yiisoft/yii2-faker" : "*", "yiibr/yii2-br-validator": "^1.0" diff --git a/functions.php b/functions.php index 9e7893d..d937bb1 100644 --- a/functions.php +++ b/functions.php @@ -15,4 +15,17 @@ function loop(callable $handle, int $count) } } } + + if (!function_exists('last')) { + /** + * Get the last element from an array. + * + * @param array $array + * @return mixed + */ + function last(array $array) + { + return end($array); + } + } } diff --git a/src/SeederController.php b/src/SeederController.php index 13ffc64..92a2977 100644 --- a/src/SeederController.php +++ b/src/SeederController.php @@ -126,11 +126,12 @@ public function actionCreate($modelName) $this->model = $this->getClass($file); - if ($this->model === null) + if ($this->model === null) { return ExitCode::OK; + } - $_ = explode('\\', ($this->model)::className()); - $className = array_pop($_) . 'TableSeeder'; + $_ = explode('\\', get_class($this->model)); + $className = last($_) . 'TableSeeder'; $file = Yii::getAlias("$this->tablesPath/$className.php"); if ($this->confirm("Create new seeder '$file'?")) { @@ -139,8 +140,8 @@ public function actionCreate($modelName) 'namespace' => $this->tableSeederNamespace, 'table' => ($this->model)::tableName(), 'fields' => $this->generateFields(), - 'modelNamespace' => $modelNamespace, - 'modelName' => $modelName + 'modelName' => array_pop($_), + 'modelNamespace' => implode('\\', $_) ]); FileHelper::createDirectory(Yii::getAlias($this->tablesPath)); diff --git a/src/views/createTableSeeder.php b/src/views/createTableSeeder.php index 48362a4..3a19c4f 100644 --- a/src/views/createTableSeeder.php +++ b/src/views/createTableSeeder.php @@ -23,8 +23,7 @@ function pluralize($word) { } function extractModelName($class) { - $_ = explode('\\', $class); - return array_pop($_); + return last(explode('\\', $class)); } $vars = []; @@ -62,7 +61,7 @@ function run() } } ?> - loop(function ($i) { + loop(function ($i) { $this->insert(::tableName(), [