PHP Class CakeSchema

Inheritance: extends Object
显示文件 Open project: baserproject/basercms Class Usage Examples

Public Properties

Property Type Description
$connection string Connection used for read.
$file string File to write.
$name string Name of the schema.
$path string Path to write location.
$plugin string Plugin name.
$tables array Set of tables.

Public Methods

Method Description
__construct ( array $options = [] ) Constructor
after ( array $event = [] ) : void After callback to be implemented in subclasses.
before ( array $event = [] ) : boolean Before callback to be implemented in subclasses.
build ( array $data ) : void Builds schema object properties.
compare ( array | object $old, array | object $new = null ) : array Compares two sets of schemas.
generateTable ( string $table, array $fields ) : string Generate the schema code for a table.
load ( array $options = [] ) : array Reads database and creates schema tables.
read ( array $options = [] ) : array Reads database and creates schema tables.
write ( array | object $object, array $options = [] ) : mixed Writes schema file from object or options.

Protected Methods

Method Description
_arrayDiffAssoc ( array $array1, array $array2 ) : array Extended array_diff_assoc noticing change from/to NULL values.
_columns ( &$Obj ) : array Formats Schema columns from Model Object.
_compareIndexes ( array $new, array $old ) : mixed Compare two schema indexes.
_compareTableParameters ( array $new, array $old ) : mixed Compare two schema files table Parameters.
_noPrefixTable ( string $prefix, string $table ) : string Trim the table prefix from the full table name, and return the prefix-less table.
_requireFile ( string $path, string $file ) : boolean Attempts to require the schema file specified.
_values ( array $values ) : array Formats Schema columns from Model Object.

Method Details

__construct() public method

Constructor
public __construct ( array $options = [] )
$options array Optional load object properties.

_arrayDiffAssoc() protected method

It behaves almost the same way as array_diff_assoc except for NULL values: if one of the values is not NULL - change is detected. It is useful in situation where one value is strval('') ant other is strval(null) - in string comparing methods this results as EQUAL, while it is not.
protected _arrayDiffAssoc ( array $array1, array $array2 ) : array
$array1 array Base array.
$array2 array Corresponding array checked for equality.
return array Difference as array with array(keys => values) from input array where match was not found.

_columns() protected method

Formats Schema columns from Model Object.
protected _columns ( &$Obj ) : array
return array Formatted columns.

_compareIndexes() protected method

Compare two schema indexes.
protected _compareIndexes ( array $new, array $old ) : mixed
$new array New indexes.
$old array Old indexes.
return mixed False on failure or array of indexes to add and drop.

_compareTableParameters() protected method

Compare two schema files table Parameters.
protected _compareTableParameters ( array $new, array $old ) : mixed
$new array New indexes.
$old array Old indexes.
return mixed False on failure, or an array of parameters to add & drop.

_noPrefixTable() protected method

Trim the table prefix from the full table name, and return the prefix-less table.
protected _noPrefixTable ( string $prefix, string $table ) : string
$prefix string Table prefix.
$table string Full table name.
return string Prefix-less table name.

_requireFile() protected method

Attempts to require the schema file specified.
protected _requireFile ( string $path, string $file ) : boolean
$path string Filesystem path to the file.
$file string Filesystem basename of the file.
return boolean True when a file was successfully included, false on failure.

_values() protected method

Formats Schema columns from Model Object.
protected _values ( array $values ) : array
$values array Options keys(type, null, default, key, length, extra).
return array Formatted values.

after() public method

After callback to be implemented in subclasses.
public after ( array $event = [] ) : void
$event array Schema object properties.
return void

before() public method

Before callback to be implemented in subclasses.
public before ( array $event = [] ) : boolean
$event array Schema object properties.
return boolean Should process continue.

build() public method

Builds schema object properties.
public build ( array $data ) : void
$data array Loaded object properties.
return void

compare() public method

Compares two sets of schemas.
public compare ( array | object $old, array | object $new = null ) : array
$old array | object Schema object or array.
$new array | object Schema object or array.
return array Tables (that are added, dropped, or changed.)

generateTable() public method

Takes a table name and $fields array and returns a completed, escaped variable declaration to be used in schema classes.
public generateTable ( string $table, array $fields ) : string
$table string Table name you want returned.
$fields array Array of field information to generate the table with.
return string Variable declaration for a schema class.

load() public method

Reads database and creates schema tables.
public load ( array $options = [] ) : array
$options array Schema object properties.
return array Set of name and tables.

read() public method

Options - 'connection' - the db connection to use - 'name' - name of the schema - 'models' - a list of models to use, or false to ignore models
public read ( array $options = [] ) : array
$options array Schema object properties.
return array Array indexed by name and tables.

write() public method

Writes schema file from object or options.
public write ( array | object $object, array $options = [] ) : mixed
$object array | object Schema object or options array.
$options array Schema object properties to override object.
return mixed False or string written to file.

Property Details

$connection public_oe property

Connection used for read.
public string $connection
return string

$file public_oe property

File to write.
public string $file
return string

$name public_oe property

Name of the schema.
public string $name
return string

$path public_oe property

Path to write location.
public string $path
return string

$plugin public_oe property

Plugin name.
public string $plugin
return string

$tables public_oe property

Set of tables.
public array $tables
return array