| public Yiisoft\Db\Schema\Column\IntegerColumn primaryKey ( boolean $primaryKey = true ) | ||
| $primaryKey | boolean | |
public function primaryKey(bool $primaryKey = true): static
{
$this->primaryKey = $primaryKey;
return $this;
}
| Inheritance | Yiisoft\Db\Schema\Column\IntegerColumn » Yiisoft\Db\Schema\Column\AbstractColumn |
|---|---|
| Implements | Yiisoft\Db\Schema\Column\ColumnInterface |
Represents the schema for an integer column.
| Method | Description | Defined By |
|---|---|---|
| throwWrongTypeException() | Yiisoft\Db\Schema\Column\AbstractColumn |
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT_TYPE | \Yiisoft\Db\Constant\ColumnType::INTEGER | Yiisoft\Db\Schema\Column\IntegerColumn |
| public mixed __construct ( string|null $type = null, boolean $autoIncrement = false, string|null $check = null, string|null $comment = null, boolean $computed = false, string|null $dbType = null, string|null $extra = null, boolean $primaryKey = false, string|null $name = null, boolean|null $notNull = null, Yiisoft\Db\Constraint\ForeignKey|null $reference = null, integer|null $scale = null, integer|null $size = null, boolean $unique = false, boolean $unsigned = false, mixed $args ) | ||
| $type | string|null |
The column's abstract type. |
| $autoIncrement | boolean |
Whether the column is auto-incremental. |
| $check | string|null |
The check constraint for the column. |
| $comment | string|null |
The column's comment. |
| $computed | boolean |
Whether the column is a computed column. |
| $dbType | string|null |
The column's database type. |
| $extra | string|null |
Any extra information that needs to be appended to the column's definition. |
| $primaryKey | boolean |
Whether the column is a primary key. |
| $name | string|null |
The column's name. |
| $notNull | boolean|null |
Whether the column is not nullable. |
| $reference | Yiisoft\Db\Constraint\ForeignKey|null |
The foreign key constraint. |
| $scale | integer|null |
The number of digits to the right of the decimal point. |
| $size | integer|null |
The column's size. |
| $unique | boolean |
Whether the column is unique. |
| $unsigned | boolean |
Whether the column is unsigned. |
| $args | mixed |
Additional arguments to be passed to the constructor. |
public function __construct(
?string $type = null,
private bool $autoIncrement = false,
private ?string $check = null,
private ?string $comment = null,
private bool $computed = false,
private ?string $dbType = null,
private ?string $extra = null,
private bool $primaryKey = false,
private ?string $name = null,
private ?bool $notNull = null,
private ?ForeignKey $reference = null,
private ?int $scale = null,
private ?int $size = null,
private bool $unique = false,
private bool $unsigned = false,
mixed ...$args,
) {
$this->type = $type ?? static::DEFAULT_TYPE;
if (array_key_exists('defaultValue', $args)) {
$this->defaultValue = $args['defaultValue'];
unset($args['defaultValue']);
}
/** @psalm-var array<string, mixed> $args */
foreach ($args as $property => $value) {
if (property_exists($this, $property)) {
$this->$property = $value;
}
}
}
| public Yiisoft\Db\Schema\Column\IntegerColumn autoIncrement ( boolean $autoIncrement = true ) | ||
| $autoIncrement | boolean | |
public function autoIncrement(bool $autoIncrement = true): static
{
$this->autoIncrement = $autoIncrement;
return $this;
}
Defined in: Yiisoft\Db\Schema\Column\AbstractColumn::check()
| public Yiisoft\Db\Schema\Column\IntegerColumn check ( string|null $check ) | ||
| $check | string|null | |
public function check(?string $check): static
{
$this->check = $check;
return $this;
}
| public Yiisoft\Db\Schema\Column\IntegerColumn comment ( string|null $comment ) | ||
| $comment | string|null | |
public function comment(?string $comment): static
{
$this->comment = $comment;
return $this;
}
| public Yiisoft\Db\Schema\Column\IntegerColumn computed ( boolean $computed = true ) | ||
| $computed | boolean | |
public function computed(bool $computed = true): static
{
$this->computed = $computed;
return $this;
}
| public Yiisoft\Db\Schema\Column\IntegerColumn dbType ( string|null $dbType ) | ||
| $dbType | string|null | |
public function dbType(?string $dbType): static
{
$this->dbType = $dbType;
return $this;
}
| public integer|Yiisoft\Db\Expression\ExpressionInterface|null dbTypecast ( mixed $value ) | ||
| $value | mixed | |
public function dbTypecast(mixed $value): int|ExpressionInterface|null
{
/** @var ExpressionInterface|int|null */
return match (gettype($value)) {
GettypeResult::INTEGER => $value,
GettypeResult::NULL => null,
GettypeResult::STRING => $value === '' ? null : (int) $value,
GettypeResult::DOUBLE => (int) $value,
GettypeResult::BOOLEAN => $value ? 1 : 0,
GettypeResult::OBJECT => match (true) {
$value instanceof ExpressionInterface => $value,
$value instanceof BackedEnum => $value->value === '' ? null : (int) $value->value,
$value instanceof DateTimeInterface => $value->getTimestamp(),
$value instanceof Stringable => ($val = (string) $value) === '' ? null : (int) $val,
default => $this->throwWrongTypeException($value::class),
},
default => $this->throwWrongTypeException(gettype($value)),
};
}
| public Yiisoft\Db\Schema\Column\IntegerColumn defaultValue ( mixed $defaultValue ) | ||
| $defaultValue | mixed | |
public function defaultValue(mixed $defaultValue): static
{
$this->defaultValue = $defaultValue;
return $this;
}
Defined in: Yiisoft\Db\Schema\Column\AbstractColumn::extra()
| public Yiisoft\Db\Schema\Column\IntegerColumn extra ( string|null $extra ) | ||
| $extra | string|null | |
public function extra(?string $extra): static
{
$this->extra = $extra;
return $this;
}
| public string|null getComment ( ) |
public function getComment(): ?string
{
return $this->comment;
}
| public mixed getDefaultValue ( ) |
public function getDefaultValue(): mixed
{
return $this->defaultValue ?? null;
}
| public Yiisoft\Db\Constraint\ForeignKey|null getReference ( ) |
public function getReference(): ?ForeignKey
{
return $this->reference;
}
| public boolean hasDefaultValue ( ) |
public function hasDefaultValue(): bool
{
return property_exists($this, 'defaultValue');
}
| public boolean isAutoIncrement ( ) |
public function isAutoIncrement(): bool
{
return $this->autoIncrement;
}
| public boolean isComputed ( ) |
public function isComputed(): bool
{
return $this->computed;
}
| public boolean isPrimaryKey ( ) |
public function isPrimaryKey(): bool
{
return $this->primaryKey;
}
| public boolean isUnsigned ( ) |
public function isUnsigned(): bool
{
return $this->unsigned;
}
| public Yiisoft\Db\Schema\Column\IntegerColumn notNull ( boolean|null $notNull = true ) | ||
| $notNull | boolean|null | |
public function notNull(?bool $notNull = true): static
{
$this->notNull = $notNull;
return $this;
}
Defined in: Yiisoft\Db\Schema\Column\AbstractColumn::null()
| public Yiisoft\Db\Schema\Column\IntegerColumn null ( ) |
public function null(): static
{
$this->notNull = false;
return $this;
}
| public integer|null phpTypecast ( mixed $value ) | ||
| $value | mixed | |
public function phpTypecast(mixed $value): ?int
{
if ($value === null) {
return null;
}
return (int) $value;
}
| public Yiisoft\Db\Schema\Column\IntegerColumn primaryKey ( boolean $primaryKey = true ) | ||
| $primaryKey | boolean | |
public function primaryKey(bool $primaryKey = true): static
{
$this->primaryKey = $primaryKey;
return $this;
}
| public Yiisoft\Db\Schema\Column\IntegerColumn reference ( Yiisoft\Db\Constraint\ForeignKey|null $reference ) | ||
| $reference | Yiisoft\Db\Constraint\ForeignKey|null | |
public function reference(?ForeignKey $reference): static
{
$this->reference = $reference;
return $this;
}
Defined in: Yiisoft\Db\Schema\Column\AbstractColumn::scale()
| public Yiisoft\Db\Schema\Column\IntegerColumn scale ( integer|null $scale ) | ||
| $scale | integer|null | |
public function scale(?int $scale): static
{
$this->scale = $scale;
return $this;
}
Defined in: Yiisoft\Db\Schema\Column\AbstractColumn::size()
| public Yiisoft\Db\Schema\Column\IntegerColumn size ( integer|null $size ) | ||
| $size | integer|null | |
public function size(?int $size): static
{
$this->size = $size;
return $this;
}
| protected never throwWrongTypeException ( string $type ) | ||
| $type | string | |
protected function throwWrongTypeException(string $type): never
{
throw new InvalidArgumentException("Wrong $type value for $this->type column.");
}
Defined in: Yiisoft\Db\Schema\Column\AbstractColumn::type()
| public Yiisoft\Db\Schema\Column\IntegerColumn type ( string $type ) | ||
| $type | string | |
public function type(string $type): static
{
$this->type = $type;
return $this;
}
| public Yiisoft\Db\Schema\Column\IntegerColumn unique ( boolean $unique = true ) | ||
| $unique | boolean | |
public function unique(bool $unique = true): static
{
$this->unique = $unique;
return $this;
}
| public Yiisoft\Db\Schema\Column\IntegerColumn unsigned ( boolean $unsigned = true ) | ||
| $unsigned | boolean | |
public function unsigned(bool $unsigned = true): static
{
$this->unsigned = $unsigned;
return $this;
}
Signup or Login in order to comment.