PHP Class Model, paris

Author: ndusan
Afficher le fichier Open project: j4mie/paris Class Usage Examples

Méthodes publiques

Свойство 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.

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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
Résultat boolean | ORMWrapper

__callStatic() public static méthode

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

__get() public méthode

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

__isset() public méthode

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

__set() public méthode

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

__unset() public méthode

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

_build_foreign_key_name() protected static méthode

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
Résultat string

_class_name_to_table_name() protected static méthode

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
Résultat string

_get_id_column_name() protected static méthode

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
Résultat string | null

_get_static_property() protected static méthode

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
Résultat string

_get_table_name() protected static méthode

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
Résultat string

_has_one_or_many() protected méthode

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
Résultat ORMWrapper

_use_short_table_name() protected static méthode

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

as_array() public méthode

Wrapper for Idiorm's as_array method.
public as_array ( ) : Array
Résultat Array

belongs_to() protected méthode

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 méthode

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

factory() public static méthode

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
Résultat ORMWrapper

get() public méthode

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

has_many() protected méthode

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
Résultat ORMWrapper

has_many_through() protected méthode

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
Résultat ORMWrapper

has_one() protected méthode

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
Résultat ORMWrapper

hydrate() public méthode

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
Résultat void

id() public méthode

Get the database ID of this model instance.
public id ( ) : integer
Résultat integer

is_dirty() public méthode

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

is_new() public méthode

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

save() public méthode

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

set() public méthode

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
Résultat Model

set_expr() public méthode

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
Résultat Model

set_orm() public méthode

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

Property Details

$auto_prefix_models public_oe static_oe 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
Résultat string

$orm public_oe property

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

$short_table_names public_oe static_oe property

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