Final Class Yiisoft\Yii\Gii\Generator\ActiveRecord\Property
| Inheritance | Yiisoft\Yii\Gii\Generator\ActiveRecord\Property |
|---|
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $usedInRelation | boolean | Yiisoft\Yii\Gii\Generator\ActiveRecord\Property |
Public Methods
Property Details
Method Details
| public mixed __construct ( \Yiisoft\Db\Schema\Column\ColumnInterface $column ) | ||
| $column | \Yiisoft\Db\Schema\Column\ColumnInterface | |
public function __construct(
private readonly ColumnInterface $column,
) {}
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);
}
| public string getName ( ) |
public function getName(): string
{
return (string) $this->column->getName();
}
| public string getPascalCaseName ( ) |
public function getPascalCaseName(): string
{
return (new Inflector())->toPascalCase($this->getName());
}
| public string getReturnType ( ) |
public function getReturnType(): string
{
$isNullable = !$this->column->isNotNull() || $this->isUninitialized();
return $this->getPhpType($isNullable);
}
| public string getType ( ) |
public function getType(): string
{
$isNullable = !$this->column->isNotNull();
return $this->getPhpType($isNullable);
}
| public boolean hasDefaultValue ( ) |
public function hasDefaultValue(): bool
{
return $this->column->hasDefaultValue()
&& !$this->column->isAutoIncrement()
&& ($this->column->getDefaultValue() !== null || !$this->column->isNotNull());
}
Returns true if the property has a default value as a constant.
| public boolean isDefaultValueConstant ( ) |
public function isDefaultValueConstant(): bool
{
return $this->hasDefaultValue() && $this->isDefaultValueConstantInternal();
}
| public boolean isDefaultValueExpression ( ) |
public function isDefaultValueExpression(): bool
{
return $this->column->getDefaultValue() instanceof Expression;
}
| public boolean isDefaultValueNotConstant ( ) |
public function isDefaultValueNotConstant(): bool
{
return $this->hasDefaultValue() && !$this->isDefaultValueConstantInternal();
}
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();
}
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;
}
Signup or Login in order to comment.