PHP Class Model, paris

Author: ndusan
Show file Open project: j4mie/paris Class Usage Examples

Public Properties

Property Type Description
$auto_prefix_models string Set a prefix for model names. This can be a namespace or any other abitrary prefix such as the PEAR naming convention.
$orm ORM The ORM instance used by this model instance to communicate with the database.
$short_table_names boolean Set true to to ignore namespace information when computing table names from class names.

Public Methods

Method Description
__call ( string $name, array $arguments ) : boolean | ORMWrapper Magic method to capture calls to undefined class methods.
__callStatic ( string $method, Array $parameters ) : Array Calls static methods directly on the ORMWrapper
__get ( string $property ) : null | string Magic getter method, allows $model->property access to data.
__isset ( string $property ) : boolean Magic isset method, allows isset($model->property) to work correctly.
__set ( string $property, string $value ) : void Magic setter method, allows $model->property = 'value' access to data.
__unset ( string $property ) : void Magic unset method, allows unset($model->property)
as_array ( ) : Array Wrapper for Idiorm's as_array method.
delete ( ) : null Delete the database row associated with this model instance.
factory ( string $class_name, null | string $connection_name = null ) : ORMWrapper Factory method used to acquire instances of the given class.
get ( string $property ) : string Getter method, allows $model->get('property') access to data
hydrate ( Array $data ) : void Hydrate this model instance with an associative array of data.
id ( ) : integer Get the database ID of this model instance.
is_dirty ( string $property ) : boolean Check whether the given field has changed since the object was created or saved
is_new ( ) : boolean Check whether the model was the result of a call to create() or not
save ( ) : null Save the data associated with this model instance to the database.
set ( string | array $property, string | null $value = null ) : Model Setter method, allows $model->set('property', 'value') access to data.
set_expr ( string | array $property, string | null $value = null ) : Model Setter method, allows $model->set_expr('property', 'value') access to data.
set_orm ( ORM $orm ) : void Set the wrapped ORM instance associated with this Model instance.

Protected Methods

Method Description
_build_foreign_key_name ( string $specified_foreign_key_name, string $table_name ) : string Build a foreign key based on a table name. If the first argument (the specified foreign key column name) is null, returns the second argument (the name of the table) with the default foreign key column suffix appended.
_class_name_to_table_name ( string $class_name ) : string Convert a namespace to the standard PEAR underscore format.
_get_id_column_name ( string $class_name ) : string | null Return the ID column name to use for this class. If it is not set on the class, returns null.
_get_static_property ( string $class_name, string $property, null | string $default = null ) : string Retrieve the value of a static property on a class. If the class or the property does not exist, returns the default value supplied as the third argument (which defaults to null).
_get_table_name ( string $class_name ) : string Static method to get a table name given a class name.
_has_one_or_many ( string $associated_class_name, null | string $foreign_key_name = null, null | string $foreign_key_name_in_current_models_table = null, null | string $connection_name = null ) : ORMWrapper Internal method to construct the queries for both the has_one and has_many methods. These two types of association are identical; the only difference is whether find_one or find_many is used to complete the method chain.
_use_short_table_name ( string $class_name ) : boolean Should short table names, disregarding class namespaces, be computed?
belongs_to ( string $associated_class_name, null | string $foreign_key_name = null, null | string $foreign_key_name_in_associated_models_table = null, null | string $connection_name = null ) Helper method to manage one-to-one and one-to-many relations where the foreign key is on the base table.
has_many ( string $associated_class_name, null | string $foreign_key_name = null, null | string $foreign_key_name_in_current_models_table = null, null | string $connection_name = null ) : ORMWrapper Helper method to manage one-to-many relations where the foreign key is on the associated table.
has_many_through ( string $associated_class_name, null | string $join_class_name = null, null | string $key_to_base_table = null, null | string $key_to_associated_table = null, null | string $key_in_base_table = null, null | string $key_in_associated_table = null, null | string $connection_name = null ) : ORMWrapper Helper method to manage many-to-many relationships via an intermediate model. See README for a full explanation of the parameters.
has_one ( string $associated_class_name, null | string $foreign_key_name = null, null | string $foreign_key_name_in_current_models_table = null, null | string $connection_name = null ) : ORMWrapper Helper method to manage one-to-one relations where the foreign key is on the associated table.

Method Details

__call() public method

In this case we are attempting to convert camel case formatted methods into underscore formatted methods. This allows us to call methods using camel case and remain backwards compatible.
public __call ( string $name, array $arguments ) : boolean | ORMWrapper
$name string
$arguments array
return boolean | ORMWrapper

__callStatic() public static method

Calls static methods directly on the ORMWrapper
public static __callStatic ( string $method, Array $parameters ) : Array
$method string
$parameters Array
return Array

__get() public method

Magic getter method, allows $model->property access to data.
public __get ( string $property ) : null | string
$property string
return null | string

__isset() public method

Magic isset method, allows isset($model->property) to work correctly.
public __isset ( string $property ) : boolean
$property string
return boolean

__set() public method

Magic setter method, allows $model->property = 'value' access to data.
public __set ( string $property, string $value ) : void
$property string
$value string
return void

__unset() public method

Magic unset method, allows unset($model->property)
public __unset ( string $property ) : void
$property string
return void

_build_foreign_key_name() protected static method

Build a foreign key based on a table name. If the first argument (the specified foreign key column name) is null, returns the second argument (the name of the table) with the default foreign key column suffix appended.
protected static _build_foreign_key_name ( string $specified_foreign_key_name, string $table_name ) : string
$specified_foreign_key_name string
$table_name string
return string

_class_name_to_table_name() protected static method

Then convert a class name in CapWords to a table name in lowercase_with_underscores. Finally strip doubled up underscores For example, CarTyre would be converted to car_tyre. And Project\Models\CarTyre would be project_models_car_tyre.
protected static _class_name_to_table_name ( string $class_name ) : string
$class_name string
return string

_get_id_column_name() protected static method

Return the ID column name to use for this class. If it is not set on the class, returns null.
protected static _get_id_column_name ( string $class_name ) : string | null
$class_name string
return string | null

_get_static_property() protected static method

Retrieve the value of a static property on a class. If the class or the property does not exist, returns the default value supplied as the third argument (which defaults to null).
protected static _get_static_property ( string $class_name, string $property, null | string $default = null ) : string
$class_name string
$property string
$default null | string
return string

_get_table_name() protected static method

If the supplied class has a public static property named $_table, the value of this property will be returned. If not, the class name will be converted using the _class_name_to_table_name method method. If Model::$short_table_names == true or public static property $_table_use_short_name == true then $class_name passed to _class_name_to_table_name is stripped of namespace information.
protected static _get_table_name ( string $class_name ) : string
$class_name string
return string

_has_one_or_many() protected method

Internal method to construct the queries for both the has_one and has_many methods. These two types of association are identical; the only difference is whether find_one or find_many is used to complete the method chain.
protected _has_one_or_many ( string $associated_class_name, null | string $foreign_key_name = null, null | string $foreign_key_name_in_current_models_table = null, null | string $connection_name = null ) : ORMWrapper
$associated_class_name string
$foreign_key_name null | string
$foreign_key_name_in_current_models_table null | string
$connection_name null | string
return ORMWrapper

_use_short_table_name() protected static method

$class_property overrides $global_option, unless $class_property is null
protected static _use_short_table_name ( string $class_name ) : boolean
$class_name string
return boolean

as_array() public method

Wrapper for Idiorm's as_array method.
public as_array ( ) : Array
return Array

belongs_to() protected method

Helper method to manage one-to-one and one-to-many relations where the foreign key is on the base table.
protected belongs_to ( string $associated_class_name, null | string $foreign_key_name = null, null | string $foreign_key_name_in_associated_models_table = null, null | string $connection_name = null )
$associated_class_name string
$foreign_key_name null | string
$foreign_key_name_in_associated_models_table null | string
$connection_name null | string

delete() public method

Delete the database row associated with this model instance.
public delete ( ) : null
return null

factory() public static method

The class name should be supplied as a string, and the class should already have been loaded by PHP (or a suitable autoloader should exist). This method actually returns a wrapped ORM object which allows a database query to be built. The wrapped ORM object is responsible for returning instances of the correct class when its find_one or find_many methods are called.
public static factory ( string $class_name, null | string $connection_name = null ) : ORMWrapper
$class_name string
$connection_name null | string
return ORMWrapper

get() public method

Getter method, allows $model->get('property') access to data
public get ( string $property ) : string
$property string
return string

has_many() protected method

Helper method to manage one-to-many relations where the foreign key is on the associated table.
protected has_many ( string $associated_class_name, null | string $foreign_key_name = null, null | string $foreign_key_name_in_current_models_table = null, null | string $connection_name = null ) : ORMWrapper
$associated_class_name string
$foreign_key_name null | string
$foreign_key_name_in_current_models_table null | string
$connection_name null | string
return ORMWrapper

has_many_through() protected method

Helper method to manage many-to-many relationships via an intermediate model. See README for a full explanation of the parameters.
protected has_many_through ( string $associated_class_name, null | string $join_class_name = null, null | string $key_to_base_table = null, null | string $key_to_associated_table = null, null | string $key_in_base_table = null, null | string $key_in_associated_table = null, null | string $connection_name = null ) : ORMWrapper
$associated_class_name string
$join_class_name null | string
$key_to_base_table null | string
$key_to_associated_table null | string
$key_in_base_table null | string
$key_in_associated_table null | string
$connection_name null | string
return ORMWrapper

has_one() protected method

Helper method to manage one-to-one relations where the foreign key is on the associated table.
protected has_one ( string $associated_class_name, null | string $foreign_key_name = null, null | string $foreign_key_name_in_current_models_table = null, null | string $connection_name = null ) : ORMWrapper
$associated_class_name string
$foreign_key_name null | string
$foreign_key_name_in_current_models_table null | string
$connection_name null | string
return ORMWrapper

hydrate() public method

WARNING: The keys in the array MUST match with columns in the corresponding database table. If any keys are supplied which do not match up with columns, the database will throw an error.
public hydrate ( Array $data ) : void
$data Array
return void

id() public method

Get the database ID of this model instance.
public id ( ) : integer
return integer

is_dirty() public method

Check whether the given field has changed since the object was created or saved
public is_dirty ( string $property ) : boolean
$property string
return boolean

is_new() public method

Check whether the model was the result of a call to create() or not
public is_new ( ) : boolean
return boolean

save() public method

Save the data associated with this model instance to the database.
public save ( ) : null
return null

set() public method

Setter method, allows $model->set('property', 'value') access to data.
public set ( string | array $property, string | null $value = null ) : Model
$property string | array
$value string | null
return Model

set_expr() public method

Setter method, allows $model->set_expr('property', 'value') access to data.
public set_expr ( string | array $property, string | null $value = null ) : Model
$property string | array
$value string | null
return Model

set_orm() public method

Set the wrapped ORM instance associated with this Model instance.
public set_orm ( ORM $orm ) : void
$orm ORM
return void

Property Details

$auto_prefix_models public static property

Set a prefix for model names. This can be a namespace or any other abitrary prefix such as the PEAR naming convention.
public static string $auto_prefix_models
return string

$orm public property

The ORM instance used by this model instance to communicate with the database.
public ORM $orm
return ORM

$short_table_names public static property

Set true to to ignore namespace information when computing table names from class names.
public static bool $short_table_names
return boolean