1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Gii\Generator\ActiveRecord; |
6
|
|
|
|
7
|
|
|
use Yiisoft\ActiveRecord\ActiveRecord; |
|
|
|
|
8
|
|
|
use Yiisoft\Strings\Inflector; |
9
|
|
|
use Yiisoft\Validator\Rule\Regex; |
10
|
|
|
use Yiisoft\Validator\Rule\Required; |
11
|
|
|
use Yiisoft\Yii\Gii\Generator\AbstractGeneratorCommand; |
12
|
|
|
use Yiisoft\Yii\Gii\Validator\TemplateRule; |
13
|
|
|
|
14
|
|
|
final class Command extends AbstractGeneratorCommand |
15
|
|
|
{ |
16
|
|
|
public function __construct( |
17
|
|
|
#[Required] |
18
|
|
|
#[Regex( |
19
|
|
|
pattern: '/^(?:[a-z][a-z0-9]*)(?:\\\\[a-z][a-z0-9]*)*$/i', |
20
|
|
|
message: 'Invalid namespace' |
21
|
|
|
)] |
22
|
|
|
private readonly string $namespace = 'App\\Model', |
23
|
|
|
#[Required] |
24
|
|
|
#[Regex( |
25
|
|
|
pattern: '/^(?:[a-z][a-z0-9]*)(?:\\\\[a-z][a-z0-9]*)*$/i', |
26
|
|
|
message: 'Invalid table name' |
27
|
|
|
)] |
28
|
|
|
private readonly string $tableName = 'user', |
29
|
|
|
#[Regex( |
30
|
|
|
pattern: '/^[a-z\\\\]*$/i', |
31
|
|
|
message: 'Only word characters and backslashes are allowed.', |
32
|
|
|
skipOnEmpty: true, |
33
|
|
|
)] |
34
|
|
|
private readonly string $baseClass = ActiveRecord::class, |
35
|
|
|
#[Required(message: 'A code template must be selected.')] |
36
|
|
|
#[TemplateRule] |
37
|
|
|
protected string $template = 'default', |
38
|
|
|
) { |
39
|
|
|
parent::__construct($template); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getNamespace(): string |
43
|
|
|
{ |
44
|
|
|
return $this->namespace; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getBaseClass(): string |
48
|
|
|
{ |
49
|
|
|
return $this->baseClass; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getTableName(): string |
53
|
|
|
{ |
54
|
|
|
return $this->tableName; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getModelName(): string |
58
|
|
|
{ |
59
|
|
|
return (new Inflector())->tableToClass($this->tableName); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public static function getAttributeLabels(): array |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
'namespace' => 'Controller Namespace', |
66
|
|
|
'tableName' => 'Table name', |
67
|
|
|
'template' => 'Action IDs', |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public static function getHints(): array |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
'controllerClass' => 'This is the name of the controller class to be generated. You should |
75
|
|
|
provide a fully qualified namespaced class (e.g. <code>App\Controller\PostController</code>), |
76
|
|
|
and class name should be in CamelCase ending with the word <code>Controller</code>. Make sure the class |
77
|
|
|
is using the same namespace as specified by your application\'s namespace property.', |
78
|
|
|
'baseClass' => 'This is the class that the new controller class will extend from. Please make sure the class exists and can be autoloaded.', |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public static function getAttributes(): array |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
'namespace', |
86
|
|
|
'tableName', |
87
|
|
|
'template', |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths