PHP Class WordPress\ORM\BaseModel

Author: Brandon Wamboldt ([email protected])
Inheritance: implements WordPress\ORM\ModelInterface
ファイルを表示 Open project: brandonwamboldt/wp-orm Class Usage Examples

Public Methods

Method Description
__call ( string $function, array $arguments ) : mixed Magically handle getters and setters.
__construct ( array $properties = [] ) Constructor.
all ( ) : array Return EVERY instance of this model from the database, with NO filtering.
create ( $properties ) : self Create a new model from the given data.
delete ( ) : boolean Delete the model from the database. Returns true if it was successful or false if it was not.
find_one ( integer $id ) : false | self Find a specific model by it's unique ID.
find_one_by ( string $property, string $value ) : false | self Find a specific model by a given property value.
flatten_props ( array $props ) : array Convert complex objects to strings to insert into the database.
get_primary_key ( ) : string Get the column used as the primary key, defaults to 'id'.
get_table_prefix ( ) : string Return configured table prefix.
primary_key ( ) : integer Return the value of the primary key.
properties ( ) : array Return an array of all the properties for this model. By default, returns every class variable.
query ( ) : Query Start a query to find models matching specific criteria.
save ( ) : integer Save this model to the database. Will create a new record if the ID property isn't set, or update an existing record if the ID property is set.
to_array ( ) : array Get all of the properties of this model as an array.

Method Details

__call() public method

Magically handle getters and setters.
public __call ( string $function, array $arguments ) : mixed
$function string
$arguments array
return mixed

__construct() public method

Constructor.
public __construct ( array $properties = [] )
$properties array

all() public static method

Return EVERY instance of this model from the database, with NO filtering.
public static all ( ) : array
return array

create() public static method

Create a new model from the given data.
public static create ( $properties ) : self
return self

delete() public method

Delete the model from the database. Returns true if it was successful or false if it was not.
public delete ( ) : boolean
return boolean

find_one() public static method

Find a specific model by it's unique ID.
public static find_one ( integer $id ) : false | self
$id integer
return false | self

find_one_by() public static method

Find a specific model by a given property value.
public static find_one_by ( string $property, string $value ) : false | self
$property string
$value string
return false | self

flatten_props() public method

Convert complex objects to strings to insert into the database.
public flatten_props ( array $props ) : array
$props array
return array

get_primary_key() public static method

Get the column used as the primary key, defaults to 'id'.
public static get_primary_key ( ) : string
return string

get_table_prefix() public method

Return configured table prefix.
public get_table_prefix ( ) : string
return string

primary_key() public method

Return the value of the primary key.
public primary_key ( ) : integer
return integer

properties() public method

Return an array of all the properties for this model. By default, returns every class variable.
public properties ( ) : array
return array

query() public static method

Start a query to find models matching specific criteria.
public static query ( ) : Query
return Query

save() public method

Save this model to the database. Will create a new record if the ID property isn't set, or update an existing record if the ID property is set.
public save ( ) : integer
return integer

to_array() public method

Get all of the properties of this model as an array.
public to_array ( ) : array
return array