ColumnSchemaBuilder helps to define database schema types using a PHP interface.
See yii\db\SchemaBuilderTrait for more detailed description and usage examples.
Property DetailsThe column after which this column will be added.
SQL string to be appended to column schema definition.
Mapping of abstract column types (keys) to type categories (values).
The CHECK
constraint for the column.
The current database connection. It is used mainly to escape strings safely when building the final column schema string.
Default value of the column.
Whether this column is to be inserted at the beginning of the table.
Whether the column is or not nullable. If this is true
, a NOT NULL
constraint will be added. If this is false
, a NULL
constraint will be added.
Whether the column values should be unique. If this is true
, a UNIQUE
constraint will be added.
Whether the column values should be unsigned. If this is true
, an UNSIGNED
keyword will be added.
Column size or precision definition. This is what goes into the parenthesis after the column type. This can be either a string, an integer or an array. If it is an array, the array values will be joined into a string separated by comma.
The column type definition such as INTEGER, VARCHAR, DATETIME, etc.
Mapping of abstract column types (keys) to type categories (values).
public static array $typeCategoryMap = [Defined in: yii\base\BaseObject::__call()
Calls the named method which is not a class method.
Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.
public function __call($name, $params)
{
throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}
Create a column schema builder instance giving the type and value precision.
public function __construct($type, $length = null, $db = null, $config = [])
{
$this->type = $type;
$this->length = $length;
$this->db = $db;
parent::__construct($config);
}
Defined in: yii\base\BaseObject::__get()
Returns the value of an object property.
Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $object->property;
.
See also __set().
public function __get($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter();
} elseif (method_exists($this, 'set' . $name)) {
throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
}
throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}
public boolean __isset ( $name ) $name string
The property name or the event name
return booleanWhether the named property is set (not null).
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
}
return false;
}
Defined in: yii\base\BaseObject::__set()
Sets value of an object property.
Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $object->property = $value;
.
See also __get().
public function __set($name, $value)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
} else {
throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}
}
Builds the full string for the column's schema.
public function __toString()
{
switch ($this->getTypeCategory()) {
case self::CATEGORY_PK:
$format = '{type}{check}{comment}{append}';
break;
default:
$format = '{type}{length}{notnull}{unique}{default}{check}{comment}{append}';
}
return $this->buildCompleteString($format);
}
Defined in: yii\base\BaseObject::__unset()
Sets an object property to null.
Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($object->property)
.
Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.
See also https://www.php.net/manual/en/function.unset.php.
public function __unset($name)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter(null);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
}
}
Adds an AFTER
constraint to the column.
Note: MySQL, Oracle and Cubrid support only.
public $this after ( $after ) $after stringThe column after which $this column will be added.
public function after($after)
{
$this->after = $after;
return $this;
}
Specify additional SQL to be appended to column definition.
Position modifiers will be appended after column definition in databases that support them.
public function append($sql)
{
$this->append = $sql;
return $this;
}
Builds the after constraint for the column. Defaults to unsupported.
protected function buildAfterString()
{
return '';
}
Builds the custom string that's appended to column definition.
protected function buildAppendString()
{
return $this->append !== null ? ' ' . $this->append : '';
}
Builds the check constraint for the column.
protected function buildCheckString()
{
return $this->check !== null ? " CHECK ({$this->check})" : '';
}
Returns the complete column definition from input format.
protected function buildCompleteString($format)
{
$placeholderValues = [
'{type}' => $this->type,
'{length}' => $this->buildLengthString(),
'{unsigned}' => $this->buildUnsignedString(),
'{notnull}' => $this->buildNotNullString(),
'{unique}' => $this->buildUniqueString(),
'{default}' => $this->buildDefaultString(),
'{check}' => $this->buildCheckString(),
'{comment}' => $this->buildCommentString(),
'{pos}' => $this->isFirst ? $this->buildFirstString() : $this->buildAfterString(),
'{append}' => $this->buildAppendString(),
];
return strtr($format, $placeholderValues);
}
Builds the default value specification for the column.
protected function buildDefaultString()
{
$defaultValue = $this->buildDefaultValue();
if ($defaultValue === null) {
return '';
}
return ' DEFAULT ' . $defaultValue;
}
Return the default value for the column.
protected function buildDefaultValue()
{
if ($this->default === null) {
return $this->isNotNull === false ? 'NULL' : null;
}
switch (gettype($this->default)) {
case 'double':
$defaultValue = StringHelper::floatToString($this->default);
break;
case 'boolean':
$defaultValue = $this->default ? 'TRUE' : 'FALSE';
break;
case 'integer':
case 'object':
$defaultValue = (string) $this->default;
break;
default:
$defaultValue = "'{$this->default}'";
}
return $defaultValue;
}
Builds the first constraint for the column. Defaults to unsupported.
protected function buildFirstString()
{
return '';
}
Builds the length/precision part of the column.
protected function buildLengthString()
{
if ($this->length === null || $this->length === []) {
return '';
}
if (is_array($this->length)) {
$this->length = implode(',', $this->length);
}
return "({$this->length})";
}
Builds the not null constraint for the column.
protected function buildNotNullString()
{
if ($this->isNotNull === true) {
return ' NOT NULL';
} elseif ($this->isNotNull === false) {
return ' NULL';
}
return '';
}
Builds the unique constraint for the column.
protected function buildUniqueString()
{
return $this->isUnique ? ' UNIQUE' : '';
}
Builds the unsigned string for column. Defaults to unsupported.
protected function buildUnsignedString()
{
return '';
}
Defined in: yii\base\BaseObject::canGetProperty()
Returns a value indicating whether a property can be read.
A property is readable if:
$checkVars
is true);See also canSetProperty().
public function canGetProperty($name, $checkVars = true)
{
return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}
Defined in: yii\base\BaseObject::canSetProperty()
Returns a value indicating whether a property can be set.
A property is writable if:
$checkVars
is true);See also canGetProperty().
public boolean canSetProperty ( $name, $checkVars = true ) $name stringThe property name
$checkVars booleanWhether to treat member variables as properties
return booleanWhether the property can be written
public function canSetProperty($name, $checkVars = true)
{
return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}
Sets a CHECK
constraint for the column.
The SQL of the CHECK
constraint to be added.
public function check($check)
{
$this->check = $check;
return $this;
}
Deprecated since 2.0.14. On PHP >=5.5, use ::class
instead.
public static function className()
{
return get_called_class();
}
Specify the default SQL expression for the column.
public function defaultExpression($default)
{
$this->default = new Expression($default);
return $this;
}
Specify the default value for the column.
public function defaultValue($default)
{
if ($default === null) {
$this->null();
}
$this->default = $default;
return $this;
}
Adds an FIRST
constraint to the column.
Note: MySQL, Oracle and Cubrid support only.
public function first()
{
$this->isFirst = true;
return $this;
}
public function getCategoryMap()
{
return static::$typeCategoryMap;
}
Returns the category of the column type.
protected function getTypeCategory()
{
return isset($this->categoryMap[$this->type]) ? $this->categoryMap[$this->type] : null;
}
Defined in: yii\base\BaseObject::hasMethod()
Returns a value indicating whether a method is defined.
The default implementation is a call to php function method_exists()
. You may override this method when you implemented the php magic method __call()
.
public function hasMethod($name)
{
return method_exists($this, $name);
}
Defined in: yii\base\BaseObject::hasProperty()
Returns a value indicating whether a property is defined.
A property is defined if:
$checkVars
is true);See also:
public boolean hasProperty ( $name, $checkVars = true ) $name stringThe property name
$checkVars booleanWhether to treat member variables as properties
return booleanWhether the property is defined
public function hasProperty($name, $checkVars = true)
{
return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}
Defined in: yii\base\BaseObject::init()
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
public function init()
{
}
Adds a NOT NULL
constraint to the column.
public function notNull()
{
$this->isNotNull = true;
return $this;
}
Adds a NULL
constraint to the column.
public function null()
{
$this->isNotNull = false;
return $this;
}
public void setCategoryMap ( $categoryMap ) $categoryMap array
Mapping of abstract column types (keys) to type categories (values).
public function setCategoryMap($categoryMap)
{
static::$typeCategoryMap = $categoryMap;
}
Adds a UNIQUE
constraint to the column.
public function unique()
{
$this->isUnique = true;
return $this;
}
Marks column as unsigned.
public function unsigned()
{
switch ($this->type) {
case Schema::TYPE_PK:
$this->type = Schema::TYPE_UPK;
break;
case Schema::TYPE_BIGPK:
$this->type = Schema::TYPE_UBIGPK;
break;
}
$this->isUnsigned = true;
return $this;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4