-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGiixController.php
70 lines (63 loc) · 2.29 KB
/
GiixController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace carono\giix;
class GiixController extends BatchController
{
public $modelNamespace = 'app\models';
public $overwrite = true;
public $defaultAction = 'models';
public $interactive = false;
public $template = 'caronoModel';
public $templatePath;
public $generator = 'carono\giix\generators\model\Generator';
public $relationNames = [];
public function init()
{
if (!$this->tablePrefix) {
$this->tablePrefix = \Yii::$app->db->tablePrefix;
}
foreach ($this->tables as &$table) {
$table = preg_replace('#{{%([\w\d\-_]+)}}#', $this->tablePrefix . "$1", $table);
}
foreach ($this->exceptTables as &$table) {
$table = preg_replace('#{{%([\w\d\-_]+)}}#', $this->tablePrefix . "$1", $table);
}
if (key_exists('@common', \Yii::$aliases)) {
if ($this->modelNamespace == 'app\models') {
$this->modelNamespace = 'common\models';
}
if ($this->modelQueryNamespace == 'app\models\query') {
$this->modelQueryNamespace = 'common\models\query';
}
}
}
protected function getYiiConfiguration()
{
$config = parent::getYiiConfiguration();
$name = 'carono-model';
$template = $this->templatePath ? $this->templatePath : '@vendor/carono/yii2-giix/templates/model';
self::addTemplateToGiiGenerator($config, $this->generator, $name, $template);
$config['modules']['gii']['generators'][$name]['relationNames'] = $this->relationNames;
return $config;
}
public static function addTemplateToGiiGenerator(&$config, $generator, $name, $template)
{
self::prepareGii($config);
$config['modules']['gii']['generators'][$name] = [
'class' => $generator,
'templates' => [
'caronoModel' => $template
]
];
}
protected static function prepareGii(&$config)
{
if (!is_array($config['modules']['gii'])) {
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'generators' => []
];
} elseif (isset($config['modules']['gii']['generators'])) {
$config['modules']['gii']['generators'] = [];
}
}
}