Final Class Yiisoft\Yii\Gii\Generator\ActiveRecord\Command
| Inheritance | Yiisoft\Yii\Gii\Generator\ActiveRecord\Command » Yiisoft\Yii\Gii\Generator\AbstractGeneratorCommand |
|---|---|
| Implements | Yiisoft\Yii\Gii\GeneratorCommandInterface |
Public Properties
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $template | string | Yiisoft\Yii\Gii\Generator\AbstractGeneratorCommand |
Public Methods
Property Details
Method Details
| public mixed __construct ( string $table, string $namespace = 'App\\Model', string $parentClass = ActiveRecord::class, string $propertyVisibility = 'protected', boolean $generateGettersSetters = true, boolean $generateRelations = true, boolean $useRepositoryTrait = false, string $template = 'default' ) | ||
| $table | string | |
| $namespace | string | |
| $parentClass | string | |
| $propertyVisibility | string | |
| $generateGettersSetters | boolean | |
| $generateRelations | boolean | |
| $useRepositoryTrait | boolean | |
| $template | string | |
public function __construct(
#[Required]
#[Regex(
pattern: '/^[\w\-.]+$/',
message: 'Invalid table name',
)]
#[TableExistsRule]
public readonly string $table,
#[Required]
#[Regex(
pattern: '/^[a-z_]\w*(?:\\\\[a-z_]\w*)*$/i',
message: 'Invalid namespace',
)]
public readonly string $namespace = 'App\\Model',
#[Required]
#[Regex(
pattern: '/^\\\\?[a-z_]\w*(?:\\\\[a-z_]\w*)*$/i',
message: 'Invalid parent class name',
skipOnEmpty: true,
)]
#[ClassExistsRule(ActiveRecordInterface::class)]
public readonly string $parentClass = ActiveRecord::class,
#[Required]
#[In(['private', 'protected', 'public'])]
public readonly string $propertyVisibility = 'protected',
public readonly bool $generateGettersSetters = true,
public readonly bool $generateRelations = true,
public readonly bool $useRepositoryTrait = false,
string $template = 'default',
) {
parent::__construct($template);
}
| public static array getAttributeLabels ( ) |
public static function getAttributeLabels(): array
{
return [
'namespace' => 'Model namespace',
'parentClass' => 'Parent class',
'table' => 'Table name',
'propertyVisibility' => 'Property visibility',
'generateGettersSetters' => 'Generate getters and setters',
'generateRelations' => 'Generate relations',
'useRepositoryTrait' => 'Use RepositoryTrait',
'template' => 'Template',
];
}
| public static array getAttributes ( ) |
public static function getAttributes(): array
{
return [
'namespace',
'table',
'parentClass',
'template',
'propertyVisibility',
'generateGettersSetters',
'generateRelations',
'useRepositoryTrait',
];
}
| public static array getHints ( ) |
public static function getHints(): array
{
return [
'table' => 'Corresponded table name for the model class.',
'namespace' => 'Namespace for the model class to store it in the related directory.',
'parentClass' => 'Parent active record class for the new model class.',
'propertyVisibility' => 'Visibility for properties: private, protected, or public.',
'generateGettersSetters' => 'Whether to generate getter and setter methods for properties.',
'generateRelations' => 'Whether to generate relation methods based on foreign keys.',
'useRepositoryTrait' => 'Whether to include RepositoryTrait in the generated model.',
];
}
| public string getModelName ( ) |
public function getModelName(): string
{
return (new Inflector())->tableToClass($this->table);
}
| public string getTemplate ( ) |
public function getTemplate(): string
{
return $this->template;
}
| public boolean usePrivatePropertiesTrait ( ) |
public function usePrivatePropertiesTrait(): bool
{
return $this->propertyVisibility === 'private';
}
Signup or Login in order to comment.