1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace sample\dev\giiant\generators\model; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Extension of the Giiant model Generator for customization and bug fixes |
7
|
|
|
*/ |
8
|
|
|
class Generator extends \schmunk42\giiant\generators\model\Generator |
9
|
|
|
{ |
10
|
|
|
public $ignoreRelations = ['User']; |
11
|
|
|
public $ignoreRules = ['/\'exist\'/']; // ['/\'user_id\'.*?\'exist\'/']; |
12
|
|
|
public $queryInterfaceNs = 'rhertogh\\Yii2Oauth2Server\\interfaces\\models\\queries'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @inheritDoc |
16
|
|
|
*/ |
17
|
|
|
protected function generateRelations() |
18
|
|
|
{ |
19
|
|
|
$tables = parent::generateRelations(); |
20
|
|
|
|
21
|
|
|
foreach ($tables as $tableName => &$relations) { |
22
|
|
|
foreach ($relations as $relationName => $relationConfig) { |
23
|
|
|
if (in_array($relationConfig[1], $this->ignoreRelations)) { |
24
|
|
|
unset($relations[$relationName]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
// hardcoded fix for https://github.com/yiisoft/yii2-gii/issues/55. |
28
|
|
|
if ( |
29
|
|
|
$tableName === 'oauth2_user_client_scope' |
30
|
|
|
&& $relationName === 'User' |
31
|
|
|
&& $relationConfig[1] === 'Oauth2UserClient' |
32
|
|
|
) { |
33
|
|
|
$relations['UserClient'] = $relations['User']; |
34
|
|
|
unset($relations['User']); |
35
|
|
|
} |
36
|
|
|
if ( |
37
|
|
|
$tableName === 'oauth2_scope' |
38
|
|
|
&& $relationName === 'Users' |
39
|
|
|
&& $relationConfig[1] === 'Oauth2UserClient' |
40
|
|
|
) { |
41
|
|
|
$relations['UserClients'] = $relations['Users']; |
42
|
|
|
unset($relations['Users']); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $tables; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritDoc |
52
|
|
|
*/ |
53
|
|
|
public function generateRules($table) |
54
|
|
|
{ |
55
|
|
|
$rules = parent::generateRules($table); |
56
|
|
|
|
57
|
|
|
foreach ($rules as $key => $rule) { |
58
|
|
|
foreach ($this->ignoreRules as $ignoreRule) { |
59
|
|
|
if (preg_match($ignoreRule, $rule)) { |
60
|
|
|
unset($rules[$key]); |
61
|
|
|
continue 2; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return array_values($rules); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritDoc |
71
|
|
|
*/ |
72
|
|
|
public function generateRelationName($relations, $table, $key, $multiple) |
73
|
|
|
{ |
74
|
|
|
$name = parent::generateRelationName($relations, $table, $key, $multiple); |
75
|
|
|
if (strpos($name, 'Oauth2') === 0) { |
76
|
|
|
$name = substr($name, strlen('Oauth2')); |
77
|
|
|
} |
78
|
|
|
return $name; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|