Fr3nch13/CakePHP Utilities

SchemaInterface

An interface used by TableSchema objects.

Table of Contents

Methods

addColumn()  : $this
Add a column to the table.
baseColumnType()  : string|null
Returns the base type name for the provided column.
columns()  : array<string|int, string>
Get the column names in the table.
defaultValues()  : array<string, mixed>
Get a hash of columns and their default values.
getColumn()  : array<string, mixed>|null
Get column data in the table.
getColumnType()  : string|null
Returns column type or null if a column does not exist.
getOptions()  : array<string, mixed>
Gets the options for a table.
hasColumn()  : bool
Returns true if a column exists in the schema.
isNullable()  : bool
Check whether a field is nullable
name()  : string
Get the name of the table.
removeColumn()  : $this
Remove a column from the table schema.
setColumnType()  : $this
Sets the type of a column.
setOptions()  : $this
Sets the options for a table.
typeMap()  : array<string, string>
Returns an array where the keys are the column names in the schema and the values the database type they have.

Methods

addColumn()

Add a column to the table.

public addColumn(string $name, array<string, mixed>|string $attrs) : $this

Attributes

Columns can have several attributes:

  • type The type of the column. This should be one of CakePHP's abstract types.
  • length The length of the column.
  • precision The number of decimal places to store for float and decimal types.
  • default The default value of the column.
  • null Whether the column can hold nulls.
  • fixed Whether the column is a fixed length column. This is only present/valid with string columns.
  • unsigned Whether the column is an unsigned column. This is only present/valid for integer, decimal, float columns.

In addition to the above keys, the following keys are implemented in some database dialects, but not all:

  • comment The comment for the column.
Parameters
$name : string

The name of the column

$attrs : array<string, mixed>|string

The attributes for the column or the type name.

Return values
$this

baseColumnType()

Returns the base type name for the provided column.

public baseColumnType(string $column) : string|null

This represent the database type a more complex class is based upon.

Parameters
$column : string

The column name to get the base type from

Return values
string|null

The base type name

columns()

Get the column names in the table.

public columns() : array<string|int, string>
Return values
array<string|int, string>

defaultValues()

Get a hash of columns and their default values.

public defaultValues() : array<string, mixed>
Return values
array<string, mixed>

getColumn()

Get column data in the table.

public getColumn(string $name) : array<string, mixed>|null
Parameters
$name : string

The column name.

Return values
array<string, mixed>|null

Column data or null.

getColumnType()

Returns column type or null if a column does not exist.

public getColumnType(string $name) : string|null
Parameters
$name : string

The column to get the type of.

Return values
string|null

getOptions()

Gets the options for a table.

public getOptions() : array<string, mixed>

Table options allow you to set platform specific table level options. For example the engine type in MySQL.

Return values
array<string, mixed>

An array of options.

hasColumn()

Returns true if a column exists in the schema.

public hasColumn(string $name) : bool
Parameters
$name : string

Column name.

Return values
bool

isNullable()

Check whether a field is nullable

public isNullable(string $name) : bool

Missing columns are nullable.

Parameters
$name : string

The column to get the type of.

Return values
bool

Whether the field is nullable.

name()

Get the name of the table.

public name() : string
Return values
string

removeColumn()

Remove a column from the table schema.

public removeColumn(string $name) : $this

If the column is not defined in the table, no error will be raised.

Parameters
$name : string

The name of the column

Return values
$this

setColumnType()

Sets the type of a column.

public setColumnType(string $name, string $type) : $this
Parameters
$name : string

The column to set the type of.

$type : string

The type to set the column to.

Return values
$this

setOptions()

Sets the options for a table.

public setOptions(array<string, mixed> $options) : $this

Table options allow you to set platform specific table level options. For example the engine type in MySQL.

Parameters
$options : array<string, mixed>

The options to set, or null to read options.

Return values
$this

typeMap()

Returns an array where the keys are the column names in the schema and the values the database type they have.

public typeMap() : array<string, string>
Return values
array<string, string>

        
On this page

Search results