PHP 클래스 Hive_Model, hive

저자: Woody Gilk ([email protected])
파일 보기 프로젝트 열기: shadowhand/hive

공개 프로퍼티들

프로퍼티 타입 설명
$meta meta instances: name => meta object, ...

보호된 프로퍼티들

프로퍼티 타입 설명
$__changed changed data
$__data loaded data
$__info custom information
$__model model identifier
$__relations relation data
$__state what is model state?

공개 메소드들

메소드 설명
__construct ( ) : void Initializes model fields and loads meta data.
__get ( $name ) : mixed Magic method, called when accessing model properties externally.
__isset ( $name ) : boolean Magic method, called when checking if an model property exists externally.
__set ( $name, $value ) : void Magic method, called when setting model properties externally.
__toString ( ) : string Magic method, called when displaying the model as a string. By default, this method will return a JSON representation of model data.
__unset ( $name ) : void Magic method, called when unsetting model properties externally.
as_array ( ) : array Get the current model data as an array. Changed values are combined with loaded values.
as_json ( ) : string Get the current model data as a JSON string.
changed ( ) : array Get the currently changed data.
create ( Database_Query_Builder_Insert $query = NULL ) Create a new database record from model data.
delete ( Database_Query_Builder_Delete $query = NULL, $limit = 1 ) : integer Delete model data from the database.
deleted ( $state = NULL ) : boolean Get and set the model's "deleted" state.
factory ( $name, array $values = NULL )
info ( $key = NULL, $value = NULL ) : mixed Store any type of information within the model.
init ( ) : Hive_Meta Model meta initialization. Creates and returns a [Hive_Meta] object.
loaded ( $state = NULL ) : boolean Get and set the model's "loaded" state. If a model is loaded, it has loaded data, probably from a database.
loading ( $state = NULL ) : boolean Get and set the model's "loading". If a model is loading, is is prepared to receive unchanged, verified information.
meta ( $model = NULL ) : Hive_Meta Get [Hive_Meta] object for a model. Creates a new singleton if the meta object has not yet been created.
prepared ( $state = NULL ) : boolean Get and set the model's "prepared" state. If a model is prepared, it can be loaded.
query_conditions ( Database_Query_Builder $query ) : object Applies WHERE conditions to a query.
query_delete ( Database_Query_Builder_Delete $query = NULL, $limit = NULL ) : Database_Query_Builder_Delete Returns a DELETE query for the current model data. If no query is given, a new query will be created.
query_insert ( Database_Query_Builder_Insert $query = NULL ) : Database_Query_Builder_Insert Returns a INSERT query for the current model data. If no query is given, a new query will be created.
query_select ( Database_Query_Builder_Select $query = NULL, $limit = NULL ) : Database_Query_Builder_Select Returns a SELECT query for the current model data. If no query is given, a new query will be created.
query_update ( Database_Query_Builder_Update $query = NULL, $limit = NULL ) : Database_Query_Builder_Update Returns a UPDATE query for the current model data. If no query is given, a new query will be created.
read ( Database_Query_Builder_Select $query = NULL, $limit = 1 ) : Database_Result Read model data from the database.
reset ( ) Reset the model to a completely unloaded state. Clears all loaded and changed data and resets the "prepared" and "loaded" states.
save ( ) Update or create the model depending on internal state.
select_list ( $key, $value, Database_Query_Builder_Select $query = NULL ) : array Get a simple key => value array.
total ( Database_Query_Builder_Select $query = NULL ) : integer Get the total number of records matching the current model.
update ( Database_Query_Builder_Update $query = NULL, $limit = 1 ) : integer Update model data in the database.
validate ( $context = NULL, array $data = NULL ) : Validate Validate the current model data. Applies the field label, filters, rules, and callbacks to the data.
values ( $values, $clean = FALSE ) Set multiple values at once. Only values with fields will be used.

메소드 상세

__construct() 공개 메소드

$model = new Model_Foo;
public __construct ( ) : void
리턴 void

__get() 공개 메소드

$value = $model->foo; [!!] If the field does not exist, an exception will be thrown.
public __get ( $name ) : mixed
리턴 mixed

__isset() 공개 메소드

isset($model->foo);
public __isset ( $name ) : boolean
리턴 boolean

__set() 공개 메소드

$model->foo = 'new value'; [!!] If the field does not exist, an exception will be thrown.
public __set ( $name, $value ) : void
리턴 void

__toString() 공개 메소드

echo $model;
public __toString ( ) : string
리턴 string

__unset() 공개 메소드

unset($model->foo); [!!] If the field does not exist, an exception will be thrown.
public __unset ( $name ) : void
리턴 void

as_array() 공개 메소드

$array = $model->as_array();
public as_array ( ) : array
리턴 array

as_json() 공개 메소드

$json = $model->as_json();
public as_json ( ) : string
리턴 string

changed() 공개 메소드

Get changed data $changes = $model->changed(); Save changed data if ($model->changed()) $model->save();
public changed ( ) : array
리턴 array

create() 공개 메소드

Create record from model $model->create();
public create ( Database_Query_Builder_Insert $query = NULL )
$query Database_Query_Builder_Insert

delete() 공개 메소드

Delete model from the database $model->delete(); Delete all records and get the number of rows deleted $total = $model->delete(NULL, FALSE); [!!] Model data will still be intact after deleting and can be accessed for additional processing.
public delete ( Database_Query_Builder_Delete $query = NULL, $limit = 1 ) : integer
$query Database_Query_Builder_Delete
리턴 integer when deleting a single object

deleted() 공개 메소드

Force the model to be deleted $model->deleted(TRUE);
public deleted ( $state = NULL ) : boolean
리턴 boolean when getting

factory() 공개 정적인 메소드

public static factory ( $name, array $values = NULL )
$values array

info() 공개 메소드

Set model information $model->info('foo', $bar); Get model a single bit of information $bar = $model->info('foo'); Get all model information $info = $model->info(); [!!] Information stored here is not stored between requests!
public info ( $key = NULL, $value = NULL ) : mixed
리턴 mixed

init() 공개 정적인 메소드

[!!] __All models must define an init method!__ The init method must set the table name and the fields. public static function init() { $meta = parent::init(); $meta->table = 'people'; $meta->fields += array( 'id' => new Hive_Field_Auto, 'name' => new Hive_Field_String, 'age' => new Hive_Field_Integer, ); return $meta; } Use [Hive::meta] to get the meta instance for a model.
public static init ( ) : Hive_Meta
리턴 Hive_Meta

loaded() 공개 메소드

Force the model to be unloaded $model->loaded(FALSE); [!!] Changing the loaded state to TRUE will cause all changed data to be merged into the currently loaded data.
public loaded ( $state = NULL ) : boolean
리턴 boolean when getting

loading() 공개 메소드

Force the model to be loading $model->loading(TRUE);
public loading ( $state = NULL ) : boolean
리턴 boolean when getting

meta() 공개 정적인 메소드

All of the following will return the same object $meta = Hive::meta('person'); $meta = Hive::meta(new Model_Person); $meta = Model_Person::meta(); [!!] When calling this method within a model, use static::meta($this) or Hive::$meta[$this->__model] for best performance.
public static meta ( $model = NULL ) : Hive_Meta
리턴 Hive_Meta

prepared() 공개 메소드

Set the prepared state $model->prepared(TRUE); Get the prepared state if ($model->prepared()) $model->read();
public prepared ( $state = NULL ) : boolean
리턴 boolean when getting

query_conditions() 공개 메소드

Create a new SELECT query $query = DB::select(); Apply model conditions $model->query_conditions($query);
public query_conditions ( Database_Query_Builder $query ) : object
$query Database_Query_Builder
리턴 object

query_delete() 공개 메소드

$query = $model->query_delete();
public query_delete ( Database_Query_Builder_Delete $query = NULL, $limit = NULL ) : Database_Query_Builder_Delete
$query Database_Query_Builder_Delete
리턴 Database_Query_Builder_Delete

query_insert() 공개 메소드

$query = $model->query_insert();
public query_insert ( Database_Query_Builder_Insert $query = NULL ) : Database_Query_Builder_Insert
$query Database_Query_Builder_Insert
리턴 Database_Query_Builder_Insert

query_select() 공개 메소드

$query = $model->query_select();
public query_select ( Database_Query_Builder_Select $query = NULL, $limit = NULL ) : Database_Query_Builder_Select
$query Database_Query_Builder_Select
리턴 Database_Query_Builder_Select

query_update() 공개 메소드

$query = $model->query_update();
public query_update ( Database_Query_Builder_Update $query = NULL, $limit = NULL ) : Database_Query_Builder_Update
$query Database_Query_Builder_Update
리턴 Database_Query_Builder_Update

read() 공개 메소드

Read model from database $model->read(); Read all records as models $models = $model->read(NULL, FALSE);
public read ( Database_Query_Builder_Select $query = NULL, $limit = 1 ) : Database_Result
$query Database_Query_Builder_Select
리턴 Database_Result when loading a single object

reset() 공개 메소드

$model->reset();
public reset ( )

save() 공개 메소드

This can be replaced... if ($model->loaded()) $model->update(); else $model->create(); with a save call $model->save(); [!!] Your model _must_ be loaded for this to work. A prepared but unloaded model will trigger creation!
public save ( )

select_list() 공개 메소드

$people = $model->select_list('name' => 'age');
public select_list ( $key, $value, Database_Query_Builder_Select $query = NULL ) : array
$query Database_Query_Builder_Select
리턴 array

total() 공개 메소드

$total = $model->total();
public total ( Database_Query_Builder_Select $query = NULL ) : integer
$query Database_Query_Builder_Select
리턴 integer

update() 공개 메소드

Update database from model $model->update(); Update all records and get the number of rows updated $total = $model->update(NULL, FALSE);
public update ( Database_Query_Builder_Update $query = NULL, $limit = 1 ) : integer
$query Database_Query_Builder_Update
리턴 integer when updating a single object

validate() 공개 메소드

A specific list of fields can be specifically validated. If no fields are specified, all fields will be validated. A different data set can be validated instead of the model data. $array = $model->validate(); [!!] If no fields are specified, all fields will be validated.
public validate ( $context = NULL, array $data = NULL ) : Validate
$data array
리턴 Validate

values() 공개 메소드

$model->values($_POST);
public values ( $values, $clean = FALSE )

프로퍼티 상세

$__changed 보호되어 있는 프로퍼티

changed data
protected $__changed

$__data 보호되어 있는 프로퍼티

loaded data
protected $__data

$__info 보호되어 있는 프로퍼티

custom information
protected $__info

$__model 보호되어 있는 프로퍼티

model identifier
protected $__model

$__relations 보호되어 있는 프로퍼티

relation data
protected $__relations

$__state 보호되어 있는 프로퍼티

what is model state?
protected $__state

$meta 공개적으로 정적으로 프로퍼티

meta instances: name => meta object, ...
public static $meta