0 follower

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

InheritanceYiisoft\Yii\Gii\Generator\ActiveRecord\Property

Property Details

Hide inherited properties

$usedInRelation public property
public boolean $usedInRelation false

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Db\Schema\Column\ColumnInterface $column )
$column \Yiisoft\Db\Schema\Column\ColumnInterface

                public function __construct(
    private readonly ColumnInterface $column,
) {}

            
getDefaultValue() public method

Returns the PHP representation of the default value for use in generated code.

public string getDefaultValue ( )

                public function getDefaultValue(): string
{
    $defaultValue = $this->column->getDefaultValue();
    if ($defaultValue instanceof Expression) {
        return sprintf(
            'new Expression(%s, %s)',
            var_export($defaultValue->expression, true),
            $defaultValue->params === []
                ? '[]'
                : VarDumper::create($defaultValue->params)->export(false),
        );
    }
    return VarDumper::create($defaultValue)->export(false);
}

            
getName() public method

public string getName ( )

                public function getName(): string
{
    return (string) $this->column->getName();
}

            
getPascalCaseName() public method

public string getPascalCaseName ( )

                public function getPascalCaseName(): string
{
    return (new Inflector())->toPascalCase($this->getName());
}

            
getReturnType() public method

public string getReturnType ( )

                public function getReturnType(): string
{
    $isNullable = !$this->column->isNotNull() || $this->isUninitialized();
    return $this->getPhpType($isNullable);
}

            
getType() public method

public string getType ( )

                public function getType(): string
{
    $isNullable = !$this->column->isNotNull();
    return $this->getPhpType($isNullable);
}

            
hasDefaultValue() public method

public boolean hasDefaultValue ( )

                public function hasDefaultValue(): bool
{
    return $this->column->hasDefaultValue()
        && !$this->column->isAutoIncrement()
        && ($this->column->getDefaultValue() !== null || !$this->column->isNotNull());
}

            
isDefaultValueConstant() public method

Returns true if the property has a default value as a constant.

public boolean isDefaultValueConstant ( )

                public function isDefaultValueConstant(): bool
{
    return $this->hasDefaultValue() && $this->isDefaultValueConstantInternal();
}

            
isDefaultValueExpression() public method

public boolean isDefaultValueExpression ( )

                public function isDefaultValueExpression(): bool
{
    return $this->column->getDefaultValue() instanceof Expression;
}

            
isDefaultValueNotConstant() public method

public boolean isDefaultValueNotConstant ( )

                public function isDefaultValueNotConstant(): bool
{
    return $this->hasDefaultValue() && !$this->isDefaultValueConstantInternal();
}

            
isUninitialized() public method

Returns true if the property can be uninitialized.

This happens when the property is auto-increment or has no default value.

public boolean isUninitialized ( )

                public function isUninitialized(): bool
{
    return $this->column->isAutoIncrement() || !$this->isDefaultValueConstant();
}

            
shouldUseSetMethod() public method

Returns true if setter should use ActiveRecord::set() method.

This is needed for primary keys and columns used in relationships.

public boolean shouldUseSetMethod ( )

                public function shouldUseSetMethod(): bool
{
    return $this->column->isPrimaryKey() || $this->usedInRelation;
}