Detailed Description
PersistentObject defines the interface of all persistent objects.
It mainly requires an unique identifier for each instance (ObjectId), tracking of the persistent state, methods for setting and getting values as well as callback methods for lifecycle events.
Definition at line 24 of file PersistentObject.php.
Public Member Functions | |
initialize (array $data) | |
getType () | |
getMapper () | |
getOID () | |
setOID (ObjectId $oid) | |
getState () | |
setState ($state) | |
delete () | |
__clone () | |
copyValues (PersistentObject $object, $copyPkValues=true) | |
mergeValues (PersistentObject $object) | |
clearValues () | |
afterCreate () | |
beforeInsert () | |
afterInsert () | |
afterLoad () | |
beforeUpdate () | |
afterUpdate () | |
beforeDelete () | |
afterDelete () | |
getValue ($name) | |
setValue ($name, $value, $forceSet=false, $trackChange=true) | |
hasValue ($name) | |
removeValue ($name) | |
getValueNames ($excludeTransient=false) | |
validateValues (Message $message) | |
validateValue ($name, $value, Message $message) | |
getChangedValues () | |
getOriginalValues () | |
getIndispensableObjects () | |
getProperty ($name) | |
setProperty ($name, $value) | |
getPropertyNames () | |
getValueProperty ($name, $property) | |
setValueProperty ($name, $property, $value) | |
getValuePropertyNames ($name) | |
getDisplayValue () | |
dump () | |
Public Attributes | |
const | STATE_CLEAN = 0 |
const | STATE_DIRTY = 1 |
const | STATE_NEW = 2 |
const | STATE_DELETED = 3 |
Member Function Documentation
initialize | ( | array | $data | ) |
Initialize the object with a set of data.
This method does not validate, does not change the object's state and does not call any listeners. Any existing data will be overwritten. The data will also be used as base line for tracking changes.
- Parameters
-
$data An associative array with the data to set.
Implemented in PersistentObjectProxy, and DefaultPersistentObject.
getType | ( | ) |
Get the type of the object.
- Returns
- The objects type.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getMapper | ( | ) |
Get the PersistenceMapper of the object.
- Returns
- PersistenceMapper
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getOID | ( | ) |
Get the object id of the PersistentObject.
- Returns
- ObjectId
Implemented in DefaultPersistentObject, PersistentObjectProxy, and NullNode.
setOID | ( | ObjectId | $oid | ) |
Set the object id of the PersistentObject.
- Parameters
-
$oid The PersistentObject's oid.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getState | ( | ) |
Get the object's state:
- Returns
- One of the STATE constant values:
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
setState | ( | $state | ) |
Set the state of the object to one of the STATE constants.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
delete | ( | ) |
Delete the object.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
__clone | ( | ) |
Get a copy of the object (ChangeListeners and Lock are not copied)
- Returns
- PersistentObject
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
copyValues | ( | PersistentObject | $object, |
$copyPkValues = true |
|||
) |
Copy all non-empty values to a given instance (ChangeListeners are triggered)
- Parameters
-
$object PersistentObject instance to copy the values to. $copyPkValues Boolean whether primary key values should be copied
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
mergeValues | ( | PersistentObject | $object | ) |
Copy all values, that don't exist yet from a given instance (ChangeListeners are not triggered)
- Parameters
-
$object PersistentObject instance to copy the values from.
Implemented in DefaultPersistentObject, Node, and PersistentObjectProxy.
clearValues | ( | ) |
Clear all values.
Set each value to null except for the primary key values
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
afterCreate | ( | ) |
This method is called once after creation of this object.
At this time it is not known in the store.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
beforeInsert | ( | ) |
This method is called once before inserting the newly created object into the store.
Implemented in DefaultPersistentObject, PersistentObjectProxy, and AbstractUser.
afterInsert | ( | ) |
This method is called once after inserting the newly created object into the store.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
afterLoad | ( | ) |
This method is called always after loading the object from the store.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
beforeUpdate | ( | ) |
This method is called always before updating the modified object in the store.
Implemented in DefaultPersistentObject, PersistentObjectProxy, and AbstractUser.
afterUpdate | ( | ) |
This method is called always after updating the modified object in the store.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
beforeDelete | ( | ) |
This method is called once before deleting the object from the store.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
afterDelete | ( | ) |
This method is called once after deleting the object from the store.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getValue | ( | $name | ) |
Get the value of a named item.
- Parameters
-
$name The name of the item to query.
- Returns
- The value of the item / null if it doesn't exits.
Implemented in DefaultPersistentObject, PersistentObjectProxy, and Node.
setValue | ( | $name, | |
$value, | |||
$forceSet = false , |
|||
$trackChange = true |
|||
) |
Set the value of a named item if it exists.
- Parameters
-
$name The name of the item to set. $value The value of the item. $forceSet Boolean whether to set the value even if it is already set and to bypass validation (used to notify listeners) (default: false) $trackChange Boolean whether to track the change (change state, notify listeners) or not (default: true) Only set this false, if you know, what you are doing
- Returns
- Boolean whether the operation succeeds or not
Implemented in DefaultPersistentObject, PersistentObjectProxy, AbstractUser, and Node.
hasValue | ( | $name | ) |
Check if the node has a given item.
- Parameters
-
$name The name of the item to query.
- Returns
- Boolean whether the item exists or not.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
removeValue | ( | $name | ) |
Remove a named item.
- Parameters
-
$name The name of the item to remove.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getValueNames | ( | $excludeTransient = false | ) |
Get the names of all items.
- Parameters
-
$excludeTransient Boolean whether to exclude transient values (default: false)
- Returns
- An array of item names.
Implemented in DefaultPersistentObject, PersistentObjectProxy, and Node.
validateValues | ( | Message | $message | ) |
Validate all values by calling PersistentObject::validateValue() Throws a ValidationException in case of invalid data.
- Parameters
-
$message The Message instance used to provide translations.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
validateValue | ( | $name, | |
$value, | |||
Message | $message | ||
) |
Check if data may be set.
The method is also called, when setting a value. Controller may call this method before setting data and saving the object. Throws a ValidationException in case of invalid data.
- Parameters
-
$name The name of the item to set. $value The value of the item. $message The Message instance used to provide translations. The default implementation calls PersistentObject::validateValueAgainstValidateType().
Implemented in DefaultPersistentObject, PersistentObjectProxy, AbstractUser, and AbstractRole.
getChangedValues | ( | ) |
Get the list of changed attributes since creation, loading.
- Returns
- Array of value names
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getOriginalValues | ( | ) |
Get the original data provided to the initialize method.
- Returns
- Associative array with value names as keys and values as values
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getIndispensableObjects | ( | ) |
Get the list of objects that must exist in the store, before this object may be persisted.
Implementing classes may use this method to manage dependencies.
- Returns
- Array of PersistentObject instances
Implemented in DefaultPersistentObject, PersistentObjectProxy, and Node.
getProperty | ( | $name | ) |
Get the value of a named property in the object.
- Parameters
-
$name The name of the property to query.
- Returns
- The value of the property / null if it doesn't exits.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
setProperty | ( | $name, | |
$value | |||
) |
Set the value of a named property in the object.
- Parameters
-
$name The name of the property to set. $value The value of the property to set.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getPropertyNames | ( | ) |
Get the names of all properties in the object.
Properties are either defined by using the PersistentObject::setProperty() method or by the PersistentMapper.
- Returns
- An array consisting of the names.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getValueProperty | ( | $name, | |
$property | |||
) |
Get the value of one property of a named item.
- Parameters
-
$name The name of the item to get its properties. $property The name of the property to get.
- Returns
- The value property/null if not found.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
setValueProperty | ( | $name, | |
$property, | |||
$value | |||
) |
Set the value of one property of a named item.
- Parameters
-
$name The name of the item to set its properties. $property The name of the property to set. $value The value to set on the property.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getValuePropertyNames | ( | $name | ) |
Get the names of all properties of a value in the object.
- Returns
- An array consisting of the names.
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
getDisplayValue | ( | ) |
Get the value of the object used for display.
- Returns
- The value.
Implemented in Node, DefaultPersistentObject, and PersistentObjectProxy.
dump | ( | ) |
Get a string representation of the values of the PersistentObject.
- Returns
- String
Implemented in DefaultPersistentObject, and PersistentObjectProxy.
Member Data Documentation
const STATE_CLEAN = 0 |
Definition at line 26 of file PersistentObject.php.
const STATE_DIRTY = 1 |
Definition at line 27 of file PersistentObject.php.
const STATE_NEW = 2 |
Definition at line 28 of file PersistentObject.php.
const STATE_DELETED = 3 |
Definition at line 29 of file PersistentObject.php.