0 follower

Final Class Yiisoft\Yii\Gii\Generator\ActiveRecord\Command

InheritanceYiisoft\Yii\Gii\Generator\ActiveRecord\Command » Yiisoft\Yii\Gii\Generator\AbstractGeneratorCommand
ImplementsYiisoft\Yii\Gii\GeneratorCommandInterface

Protected Properties

Hide inherited properties

Property Type Description Defined By
$template string Yiisoft\Yii\Gii\Generator\AbstractGeneratorCommand

Property Details

Hide inherited properties

$generateGettersSetters public property
$generateRelations public property
$namespace public property
public string $namespace 'App\\Model'
$parentClass public property
public string $parentClass ActiveRecord::class
$propertyVisibility public property
public string $propertyVisibility 'protected'
$table public property
public string $table null
$useRepositoryTrait public property

Method Details

Hide inherited methods

__construct() public method

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);
}

            
getAttributeLabels() public static method

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',
    ];
}

            
getAttributes() public static method

public static array getAttributes ( )

                public static function getAttributes(): array
{
    return [
        'namespace',
        'table',
        'parentClass',
        'template',
        'propertyVisibility',
        'generateGettersSetters',
        'generateRelations',
        'useRepositoryTrait',
    ];
}

            
getHints() public static method

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.',
    ];
}

            
getModelName() public method

public string getModelName ( )

                public function getModelName(): string
{
    return (new Inflector())->tableToClass($this->table);
}

            
getTemplate() public method
public string getTemplate ( )

                public function getTemplate(): string
{
    return $this->template;
}

            
usePrivatePropertiesTrait() public method

public boolean usePrivatePropertiesTrait ( )

                public function usePrivatePropertiesTrait(): bool
{
    return $this->propertyVisibility === 'private';
}