PHP Class Pheasant\DomainObject

Inheritance: implements ArrayAccess
Datei anzeigen Open project: lox/pheasant Class Usage Examples

Public Methods

Method Description
__callStatic ( $method, $params ) Delegates find calls through to the finder
__construct ( ) The final constructer which initializes the object. Subclasses can implement {@link construct()} instead
__get ( $key ) Magic method, delegates to the schema for getters
__isset ( $key ) Magic method, delegates to the schema
__set ( $key, $value ) Magic method, delegates to the schema for setters
__toString ( ) String coercion. Returns a value like "ClassName[pkcol1=foo,pkcol2=bar]"
changes ( ) : array Returns a key=>val array of properties that have changed since the last save
className ( ) Return the class name of the domain object
clearChanges ( ) Clears the changes array
connection ( ) : Connection Returns the connection object for the domain object.
create ( ) : DomainObject Creates and saves a domain object, var args are passed to the constructor
delete ( ) Deletes the domain object via the associated mapper
diff ( $object ) Returns keys that differ between the two objects
equals ( $object ) Compares the properties of one domain object to that of another
eventHandler ( $e, $obj ) : void Handles events for the domain object, looks for local methods named after the event, e.g beforeSave. The event is passed as a parameter
events ( $events = [] ) : Events Returns the domain objects event collection, optionally registering any passed events
fromArray ( $array = [] ) Creates an instance from an array, bypassing the constructor and setters
get ( $prop ) : mixed Gets a property
has ( $prop ) Whether the object has a property, even if it's null
identity ( ) : Identity Returns an Identity object for the domain object
import ( $records ) : array Creates and saves a array or arrays as domain objects
initialize ( $builder, $pheasant ) Template function for configuring a domain object. Looks for either a tableName() method or a mapper() method, a properties() method and a relationships() method.
isSaved ( ) : boolean Returns whether the object has been saved
load ( $array, $filter = false ) Loads an array of values into the object
lock ( $onChanged = null ) Creates a concurrency lock on the domain object, with an optional closure to execute if the object has changed in the db when the lock finally provided. Closure gets the original and the new object
markSaved ( $value = true ) Change the objects saved state
offsetExists ( $offset ) array object
offsetGet ( $offset )
offsetSet ( $offset, $value )
offsetUnset ( $offset )
override ( $property, $closure ) Defines a closure that is called when the property is accessed.
reload ( ) Reloads the contents of the object
save ( ) Saves the domain object via the associated mapper
saveAfter ( $object ) Register a domain object to be saved after the current domain object is saved
schema ( ) : Schema Returns the Schema registered for this class.
scopes ( ) Returns an array of scope functions
set ( $prop, $value ) Sets a property
toArray ( ) : array Returns the object as an array
transaction ( $closure, $execute = true ) : Transaction Creates a transaction, passes the instance

Protected Methods

Method Description
_defaultConstruct ( ) Default method called without a constructor
_registerDefaultEventHandlers ( ) Sets up the default internal event handlers
mapper ( ) : Mapper Returns the mapper for the object
properties ( ) Returns an array of Property objects
relationships ( ) Returns an array of Relationship objects
tableName ( ) : string Used by the default initialize() method, returns the table name to use

Method Details

__callStatic() public static method

Delegates find calls through to the finder
public static __callStatic ( $method, $params )

__construct() final public method

The final constructer which initializes the object. Subclasses can implement {@link construct()} instead
final public __construct ( )

__get() public method

Magic method, delegates to the schema for getters
public __get ( $key )

__isset() public method

Magic method, delegates to the schema
public __isset ( $key )

__set() public method

Magic method, delegates to the schema for setters
public __set ( $key, $value )

__toString() public method

String coercion. Returns a value like "ClassName[pkcol1=foo,pkcol2=bar]"
public __toString ( )

_defaultConstruct() protected method

Default method called without a constructor
protected _defaultConstruct ( )

_registerDefaultEventHandlers() protected method

Sets up the default internal event handlers

changes() public method

Returns a key=>val array of properties that have changed since the last save
public changes ( ) : array
return array

className() public static method

Return the class name of the domain object
public static className ( )

clearChanges() public method

Clears the changes array
public clearChanges ( )

connection() public static method

This can be overridden on a per-class basis.
public static connection ( ) : Connection
return Connection

create() public static method

Creates and saves a domain object, var args are passed to the constructor
public static create ( ) : DomainObject
return DomainObject

delete() public method

Deletes the domain object via the associated mapper
public delete ( )

diff() public method

Returns keys that differ between the two objects
public diff ( $object )

equals() public method

Compares the properties of one domain object to that of another
public equals ( $object )

eventHandler() public method

Handles events for the domain object, looks for local methods named after the event, e.g beforeSave. The event is passed as a parameter
public eventHandler ( $e, $obj ) : void
return void

events() public method

Returns the domain objects event collection, optionally registering any passed events
public events ( $events = [] ) : Events
return Events

fromArray() public static method

Creates an instance from an array, bypassing the constructor and setters
public static fromArray ( $array = [] )

get() public method

Gets a property
public get ( $prop ) : mixed
return mixed

has() public method

Whether the object has a property, even if it's null
public has ( $prop )

identity() public method

Returns an Identity object for the domain object
public identity ( ) : Identity
return Identity

import() public static method

Creates and saves a array or arrays as domain objects
public static import ( $records ) : array
return array of saved domain objects

initialize() public static method

Template function for configuring a domain object. Looks for either a tableName() method or a mapper() method, a properties() method and a relationships() method.
public static initialize ( $builder, $pheasant )

isSaved() public method

Returns whether the object has been saved
public isSaved ( ) : boolean
return boolean

load() public method

Loads an array of values into the object
public load ( $array, $filter = false )
$filter only processes the keys listed, or false for all

lock() public method

Creates a concurrency lock on the domain object, with an optional closure to execute if the object has changed in the db when the lock finally provided. Closure gets the original and the new object
public lock ( $onChanged = null )

mapper() protected method

Returns the mapper for the object
protected mapper ( ) : Mapper
return Mapper

markSaved() public method

Change the objects saved state
public markSaved ( $value = true )

offsetExists() public method

array object
public offsetExists ( $offset )

offsetGet() public method

public offsetGet ( $offset )

offsetSet() public method

public offsetSet ( $offset, $value )

offsetUnset() public method

public offsetUnset ( $offset )

override() public method

The closure is passed the property and the domain object.
public override ( $property, $closure )

properties() protected method

Returns an array of Property objects
protected properties ( )

relationships() protected method

Returns an array of Relationship objects
protected relationships ( )

reload() public method

Reloads the contents of the object
public reload ( )

save() public method

Saves the domain object via the associated mapper
public save ( )

saveAfter() public method

Register a domain object to be saved after the current domain object is saved
public saveAfter ( $object )

schema() public static method

Returns the Schema registered for this class.
public static schema ( ) : Schema
return Schema

scopes() public static method

Returns an array of scope functions
public static scopes ( )

set() public method

Sets a property
public set ( $prop, $value )

tableName() protected method

Used by the default initialize() method, returns the table name to use
protected tableName ( ) : string
return string

toArray() public method

Returns the object as an array
public toArray ( ) : array
return array

transaction() public method

Creates a transaction, passes the instance
public transaction ( $closure, $execute = true ) : Transaction
return Transaction