PHP Class lazyrecord\schema\DeclareSchema

Inheritance: extends SchemaBase, implements LazyRecord\Schema\SchemaInterface
Datei anzeigen Open project: corneltek/lazyrecord Class Usage Examples

Public Properties

Property Type Description
$collectionInterfaceClasses string[]
$collectionTraitClasses string[]
$enableColumnAccessors
$indexes
$modelInterfaceClasses string[]
$modelTraitClasses string[]
$onDelete
$onUpdate

Public Methods

Method Description
__construct ( array $options = [] ) Constructor of declare schema.
__toString ( )
addCollectionInterface ( $iface ) Implement interface in collection class.
addCollectionTrait ( $traitClass ) : ClassTemplate\ClassTrait Use trait for the model class.
addColumn ( DeclareColumn $column ) : DeclareColumn Add column object into the column list.
addModelInterface ( $iface ) Implement interface in model class.
addModelTrait ( $traitClass ) : ClassTemplate\ClassTrait Use trait for the model class.
addSeed ( string $seed ) Add seed class.
belongsTo ( $accessor, string $foreignClass, string $foreignColumn = 'id', string $selfColumn = null ) define self primary key to foreign key reference.
column ( string $name, string $class = 'LazyRecord\Schema\DeclareColumn' ) : DeclareColumn Define new column object.
dump ( )
export ( )
findPrimaryKey ( ) : string Find primary key from columns.
findPrimaryKeyColumn ( ) : DeclareColumn Find primary key column object from columns.
getClassFileName ( )
getClassName ( )
getCollectionInterfaces ( ) : string[]
getCollectionTraitClasses ( ) : string[]
getColumn ( string $name ) 'getColumn' gets the column object by the given column name.
getColumnLabels ( $includeVirtual = false )
getColumnNames ( boolean $includeVirtual = false ) : string[]
getColumns ( $includeVirtual = false )
getDirectory ( ) : string Get directory from current schema object.
getIndexQueries ( ) : SQLBuilder\Universal\Query\CreateIndexQuery[]
getLabel ( )
getModelClass ( ) : string Get model class name of this schema.
getModelInterfaces ( ) : string[]
getModelTraitClasses ( ) : string[]
getModificationTime ( ) : integer Return the modification time of this schema definition class.
getMsgIds ( )
getPrimaryKey ( ) : string Get the primary key column name.
getReadSourceId ( )
getRelatedClassPath ( string $class ) : string Get the related class file path by the given class name.
getShortClassName ( )
getTable ( ) : string Get the table name of this schema class.
getWriteSourceId ( )
hasColumn ( string $name ) : boolean hasColumn method returns true if a column name is defined.
hasMany ( )
hasOne ( string $accessor, string $foreignClass, string $foreignColumn = null, string $selfColumn ) has-one relationship.
insertColumn ( DeclareColumn $column ) Insert column object at the begining of the column list.
isNewerThanFile ( string $path ) : boolean isNewerThanFile returns true if the schema file is newer than a file.
label ( string $label ) Define schema label.
many ( string $accessor, string $foreignClass, string $foreignColumn, string $selfColumn ) Add has-many relation.
manyToMany ( string $accessor, string $relationId, string $foreignRelationId )
mixin ( string $class, array $options = [] ) Mixin.
onDelete ( string $action ) onDelete defines a software trigger of delete action.
onUpdate ( $action ) onUpdate defines a software trigger of update action.
readFrom ( string $id ) set data source for read.
removeColumn ( $columnName )
requireProxyFileUpdate ( ) : boolean requireProxyFileUpdate returns true if the schema proxy file is out of date.
schema ( )
seeds ( ) : DeclareSchema 'seeds' helps you define seed classes.
table ( string $table ) Define table name.
using ( string $id ) set data source for both write and read.
writeTo ( string $id ) set data source for write.

Protected Methods

Method Description
_classnameToTable ( ) : string Convert current model name to a class name.
_modelClassToLabel ( )
build ( array $options = [] ) Build schema build the schema by running the "schema" method.
disableColumnAccessors ( ) SchemaGenerator generates column accessor methods from the column definition automatically.
getCurrentSchemaClass ( )
helper ( string $helperName, array $arguments = [] ) : BaseHelper Invode helper.
index ( $name, $columns = null, $using = null ) : SQLBuilder\Universal\Query\CreateIndexQuery 'index' method helps you define index queries.
insertAutoIdPrimaryColumn ( string $name = 'id', string $columnType = 'integer' ) Insert a primary key column with auto increment.
resolveSchemaClass ( $class )

Method Details

__construct() public method

The constructor calls build method to build the schema information.
public __construct ( array $options = [] )
$options array

__toString() public method

public __toString ( )

_classnameToTable() protected method

Convert current model name to a class name.
protected _classnameToTable ( ) : string
return string table name

_modelClassToLabel() protected method

protected _modelClassToLabel ( )

addCollectionInterface() public method

Implement interface in collection class.
public addCollectionInterface ( $iface )

addCollectionTrait() public method

Use trait for the model class.
public addCollectionTrait ( $traitClass ) : ClassTemplate\ClassTrait
return ClassTemplate\ClassTrait object

addColumn() public method

Add column object into the column list.
public addColumn ( DeclareColumn $column ) : DeclareColumn
$column DeclareColumn
return DeclareColumn

addModelInterface() public method

Implement interface in model class.
public addModelInterface ( $iface )

addModelTrait() public method

Use trait for the model class.
public addModelTrait ( $traitClass ) : ClassTemplate\ClassTrait
return ClassTemplate\ClassTrait object

addSeed() public method

Add seed class.
public addSeed ( string $seed )
$seed string

belongsTo() public method

comments( post_id => author.comment_id ) $post->publisher
public belongsTo ( $accessor, string $foreignClass, string $foreignColumn = 'id', string $selfColumn = null )
$foreignClass string foreign schema class.
$foreignColumn string foreign reference schema column.
$selfColumn string self column name

build() protected method

The post process find the primary key from the built columns And insert the auto-increment primary is auto_id config is enabled.
protected build ( array $options = [] )
$options array

column() public method

Define new column object.
public column ( string $name, string $class = 'LazyRecord\Schema\DeclareColumn' ) : DeclareColumn
$name string column name
$class string column class name
return DeclareColumn

disableColumnAccessors() protected method

If you don't want these accessors to be generated, you may simply call 'disableColumnAccessors'
protected disableColumnAccessors ( )

dump() public method

public dump ( )

export() public method

public export ( )

findPrimaryKey() public method

This method will be called after building schema information to save the primary key name
public findPrimaryKey ( ) : string
return string primary key

findPrimaryKeyColumn() public method

This method will be called after building schema information to save the primary key name
public findPrimaryKeyColumn ( ) : DeclareColumn
return DeclareColumn

getClassFileName() public method

public getClassFileName ( )

getClassName() public method

public getClassName ( )

getCollectionInterfaces() public method

public getCollectionInterfaces ( ) : string[]
return string[]

getCollectionTraitClasses() public method

public getCollectionTraitClasses ( ) : string[]
return string[]

getColumn() public method

'getColumn' gets the column object by the given column name.
public getColumn ( string $name )
$name string

getColumnLabels() public method

public getColumnLabels ( $includeVirtual = false )

getColumnNames() public method

public getColumnNames ( boolean $includeVirtual = false ) : string[]
$includeVirtual boolean
return string[]

getColumns() public method

public getColumns ( $includeVirtual = false )

getCurrentSchemaClass() protected method

protected getCurrentSchemaClass ( )

getDirectory() public method

Get directory from current schema object.
public getDirectory ( ) : string
return string path

getIndexQueries() public method

public getIndexQueries ( ) : SQLBuilder\Universal\Query\CreateIndexQuery[]
return SQLBuilder\Universal\Query\CreateIndexQuery[]

getLabel() public method

public getLabel ( )

getModelClass() public method

Get model class name of this schema.
public getModelClass ( ) : string
return string model class name

getModelInterfaces() public method

public getModelInterfaces ( ) : string[]
return string[]

getModelTraitClasses() public method

public getModelTraitClasses ( ) : string[]
return string[]

getModificationTime() public method

Return the modification time of this schema definition class.
public getModificationTime ( ) : integer
return integer timestamp

getMsgIds() public method

public getMsgIds ( )

getPrimaryKey() public method

Get the primary key column name.
public getPrimaryKey ( ) : string
return string primary key column name

getReadSourceId() public method

public getReadSourceId ( )

getRelatedClassPath() public method

Get the related class file path by the given class name.
public getRelatedClassPath ( string $class ) : string
$class string the scheam related class name
return string the class filepath.

getShortClassName() public method

public getShortClassName ( )

getTable() public method

Get the table name of this schema class.
public getTable ( ) : string
return string

getWriteSourceId() public method

public getWriteSourceId ( )

hasColumn() public method

hasColumn method returns true if a column name is defined.
public hasColumn ( string $name ) : boolean
$name string
return boolean

hasMany() public method

public hasMany ( )

hasOne() public method

model( post_id => post )
public hasOne ( string $accessor, string $foreignClass, string $foreignColumn = null, string $selfColumn )
$accessor string accessor name.
$foreignClass string foreign schema class
$foreignColumn string foreign schema column
$selfColumn string self schema column

helper() protected method

Invode helper.
protected helper ( string $helperName, array $arguments = [] ) : BaseHelper
$helperName string
$arguments array indexed array, passed to the init function of helper class.
return LazyRecord\Schema\Helper\BaseHelper

index() protected method

'index' method helps you define index queries.
protected index ( $name, $columns = null, $using = null ) : SQLBuilder\Universal\Query\CreateIndexQuery
return SQLBuilder\Universal\Query\CreateIndexQuery

insertAutoIdPrimaryColumn() protected method

Insert a primary key column with auto increment.
protected insertAutoIdPrimaryColumn ( string $name = 'id', string $columnType = 'integer' )
$name string default to 'id'
$columnType string 'int', 'smallint', 'bigint' ...

insertColumn() public method

Insert column object at the begining of the column list.
public insertColumn ( DeclareColumn $column )
$column DeclareColumn

isNewerThanFile() public method

isNewerThanFile returns true if the schema file is newer than a file.
public isNewerThanFile ( string $path ) : boolean
$path string
return boolean

label() public method

Define schema label.
public label ( string $label )
$label string label name

many() public method

TODO: provide a relationship object to handle sush operation, that will be: $this->hasMany('books','id') ->from('App_Model_Book','author_id')
public many ( string $accessor, string $foreignClass, string $foreignColumn, string $selfColumn )
$accessor string accessor name.
$foreignClass string foreign schema class
$foreignColumn string foreign schema column
$selfColumn string self schema column

manyToMany() public method

public manyToMany ( string $accessor, string $relationId, string $foreignRelationId )
$accessor string accessor name.
$relationId string a hasMany relationship.
$foreignRelationId string foreign relation id.

mixin() public method

Availabel mixins $this->mixin('Metadata' , array( options ) ); $this->mixin('I18n');
public mixin ( string $class, array $options = [] )
$class string mixin class name
$options array

onDelete() public method

onDelete defines a software trigger of delete action.
public onDelete ( string $action )
$action string Currently for 'cascade'

onUpdate() public method

onUpdate defines a software trigger of update action.
public onUpdate ( $action )

readFrom() public method

set data source for read.
public readFrom ( string $id )
$id string data source id

removeColumn() public method

public removeColumn ( $columnName )

requireProxyFileUpdate() public method

requireProxyFileUpdate returns true if the schema proxy file is out of date.
public requireProxyFileUpdate ( ) : boolean
return boolean

resolveSchemaClass() protected method

protected resolveSchemaClass ( $class )

schema() public method

public schema ( )

seeds() public method

$this->seeds('User\\Seed','Data\\Seed');
public seeds ( ) : DeclareSchema
return DeclareSchema

table() public method

Define table name.
public table ( string $table )
$table string table name

using() public method

set data source for both write and read.
public using ( string $id )
$id string data source id

writeTo() public method

set data source for write.
public writeTo ( string $id )
$id string data source id

Property Details

$collectionInterfaceClasses public_oe property

public string[] $collectionInterfaceClasses
return string[]

$collectionTraitClasses public_oe property

public string[] $collectionTraitClasses
return string[]

$enableColumnAccessors public_oe property

public $enableColumnAccessors

$indexes public_oe property

public $indexes

$modelInterfaceClasses public_oe property

public string[] $modelInterfaceClasses
return string[]

$modelTraitClasses public_oe property

public string[] $modelTraitClasses
return string[]

$onDelete public_oe property

public $onDelete

$onUpdate public_oe property

public $onUpdate