Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonyZ89 committed Dec 8, 2020
1 parent e94b9ff commit 103bba9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
}
],
"require": {
"php": ">=7.0",
"ext-mbstring": "*",
"yiisoft/yii2": "^2.0.5",
"yiisoft/yii2-faker" : "*",
"yiibr/yii2-br-validator": "^1.0"
Expand Down
13 changes: 13 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
11 changes: 6 additions & 5 deletions src/SeederController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'?")) {
Expand All @@ -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));

Expand Down
5 changes: 2 additions & 3 deletions src/views/createTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ function pluralize($word) {
}

function extractModelName($class) {
$_ = explode('\\', $class);
return array_pop($_);
return last(explode('\\', $class));
}

$vars = [];
Expand Down Expand Up @@ -62,7 +61,7 @@ function run()
}
} ?>

loop(function ($i) <?= count($vars) ? 'use ('. implode(', ', $vars) .') ' : '' ?>{
loop(function ($i) <?= count($vars) ? 'use ('. implode(', ', $vars) .') ' : null ?>{
$this->insert(<?= $modelName ?>::tableName(), [
<?php
$i = 0;
Expand Down

0 comments on commit 103bba9

Please sign in to comment.