xpdo/om/xpdoobject.class.php
- package
- xpdo
- subpackage
- om
- Classes
- xPDOObject
- xPDOSimpleObject
Description
The base persistent xPDO object classes.
This file contains the base persistent object classes, which your user- defined classes will extend when implementing an xPDO object model.
\xPDOObject
- abstract
- This is an abstract class, and is not represented by an actual table; it simply defines the member variables and functions needed for object persistence. All xPDOObject derivatives must define both a PHP 4 style constructor which calls a PHP 5 style __construct() method with the same parameters. This is necessary to allow instantiation of further derived classes without knowing the name of the class ahead of time in PHP 4. Note that this does not meet E_STRICT compliance in PHP 5, but is the only sane way to achieve consistency between the PHP 4 and 5 inheritence models.
- package
- xpdo
- subpackage
- om
- Properties
- $_aggregates
- $_alias
- $_cacheFlag
- $_class
- $_composites
- $_dirty
- $_fieldMeta
- $_fields
- $_lazy
- $_new
- $_options
- $_package
- $_pk
- $_pktype
- $_relatedObjects
- $_table
- $_tableMeta
- $_validated
- $_validationLoaded
- $_validationRules
- $_validator
- $container
- $fieldNames
- $xpdo
- Methods
- __construct
- _getAliases
- _getDataType
- _getPHPType
- _getRelatedObjectsByFK
- _initFields
- _loadCollectionInstance
- _loadFieldData
- _loadInstance
- _loadRows
- _loadValidation
- _saveRelatedObject
- _saveRelatedObjects
- _setRaw
- addMany
- addOne
- addValidationRule
- encode
- fromArray
- fromJSON
- get
- getFKClass
- getFKDefinition
- getFieldName
- getMany
- getOne
- getOption
- getPK
- getPKType
- getPrimaryKey
- getSelectColumns
- getValidator
- isDirty
- isLazy
- isNew
- isValidated
- load
- loadCollection
- loadCollectionGraph
- remove
- removeValidationRules
- save
- set
- setDirty
- setOption
- toArray
- toJSON
- validate
Description
The base persistent xPDO object class.
This is the basis for the entire xPDO object model, and can also be used by a class generator {@link xPDOGenerator}, ultimately allowing custom classes to be user-defined in a web interface and framework-generated at runtime.
Properties
$_aggregates
array $_aggregates = 'array'
An array of aggregate foreign key relationships for the class.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$_alias
string $_alias = 'null'
An alias for this instance of the class.
Details
- string
- visibility
- public
- default
- null
- final
- false
- static
- false
$_cacheFlag
boolean $_cacheFlag = 'true'
Indicates the cacheability of the instance.
Details
- boolean
- visibility
- public
- default
- true
- final
- false
- static
- false
$_class
string $_class = 'null'
The actual class name of an instance.
Details
- string
- visibility
- public
- default
- null
- final
- false
- static
- false
$_composites
array $_composites = 'array'
An array of composite foreign key relationships for the class.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$_dirty
array $_dirty = 'array'
An array of field names that have been modified.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$_fieldMeta
array $_fieldMeta = 'array'
An array of metadata definitions for each field in the class.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$_fields
array $_fields = 'array'
An array of key-value pairs representing the fields of the instance.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$_lazy
array $_lazy = 'array'
An array of field names that have not been loaded from the source.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$_new
boolean $_new = 'true'
Indicates if the instance is transient (and thus new).
Details
- boolean
- visibility
- public
- default
- true
- final
- false
- static
- false
- access
- public
$_options
array $_options = 'array'
A collection of various options that can be used on the instance.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
$_package
string $_package = 'null'
The package the class is a part of.
Details
- string
- visibility
- public
- default
- null
- final
- false
- static
- false
$_pk
string|array $_pk = 'null'
The primary key field (or an array of primary key fields) for this object.
Details
- string|array
- visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$_pktype
string|array $_pktype = 'null'
The php native type of the primary key field.
NOTE: Will be an array if multiple primary keys are specified for the object.
Details
- string|array
- visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$_relatedObjects
array $_relatedObjects = 'array'
An array of object instances related to this object instance.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$_table
string $_table = 'null'
Name of the actual table representing this class.
Details
- string
- visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$_tableMeta
string $_tableMeta = 'null'
An array of meta data for the table.
Details
- string
- visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$_validated
array $_validated = 'array'
An array of field names that have been already validated.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$_validationLoaded
boolean $_validationLoaded = 'false'
Indicates if the validation map has been loaded.
Details
- boolean
- visibility
- public
- default
- false
- final
- false
- static
- false
- access
- public
$_validationRules
array $_validationRules = 'array'
An array of validation rules for this object instance.
Details
- array
- visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$_validator
\xPDOValidator $_validator = 'null'
A validator object responsible for this object instance.
Details
-
\xPDOValidator
- visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$container
string $container = 'null'
Name of the data source container the object belongs to.
Details
- string
- visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$fieldNames
array $fieldNames = 'null'
Names of the fields in the data table, fully-qualified with a table name.
NOTE: For use in table joins to qualify fields with the same name.
Details
- array
- visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$xpdo
Methods
__construct
__construct(
\xPDO $xpdo
)
:
\xPDOObject
Constructor
Do not call the constructor directly; see {@link xPDO::newObject()}.
All derivatives of xPDOObject must redeclare this method, and must call the parent method explicitly before any additional logic is executed, e.g.
public function __construct(xPDO & $xpdo) {
parent :: __construct($xpdo);
// Any additional constructor tasks here
}
Arguments
- $xpdo
- \xPDO
&$xpdo A reference to a valid xPDO instance.
Output
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
_getAliases
_getAliases(
string $class, int $limit
=
0
)
:
array
Find aliases for any defined object relations of the specified class.
Arguments
- $class
- string
The name of the class to find aliases from. - $limit
- int
An optional limit on the number of aliases to return; default is 0, i.e. no limit.
Output
- array
- An array of aliases or an empty array if none are found.
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
_getDataType
_getDataType(
string $key
)
:
string
Gets the database data type for the specified field.
Arguments
- $key
- string
The field name to get the data type for.
Output
- string
- The DB data type of the field.
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
_getPHPType
_getPHPType(
string $key
)
:
string
Gets the php data type for the specified field.
Arguments
- $key
- string
The field name to get the data type for.
Output
- string
- The PHP data type of the field.
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
_getRelatedObjectsByFK
_getRelatedObjectsByFK(
string $alias, mixed $criteria
=
null, boolean|integer $cacheFlag
=
true
)
:
array
Gets related objects by a foreign key and specified criteria.
Arguments
- $alias
- string
The alias representing the relationship. - $criteria
- mixed
An optional xPDO criteria expression. - $cacheFlag
- booleaninteger
Indicates if the saved object(s) should be cached and optionally, by specifying an integer value, for how many seconds before expiring. Overrides the cacheFlag for the object.
Output
- array
- A collection of objects matching the criteria.
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
_initFields
_initFields(
)
:
Initializes the field names with the qualified table name.
Once this is called, you can lookup the qualified name by the field name itself in {@link xPDOObject::$fieldNames}.
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
_loadCollectionInstance
_loadCollectionInstance(
\xPDO $xpdo, array $objCollection, string $className, mixed $criteria, $row, $fromCache, boolean|integer $cacheFlag
=
true
)
:
Responsible for loading an instance into a collection.
Arguments
- $xpdo
- \xPDO
&$xpdo A valid xPDO instance. - $objCollection
- array
&$objCollection The collection to load the instance into. - $className
- string
Name of the class. - $criteria
- mixed
A valid primary key, criteria array, or xPDOCriteria instance. - $row
- $fromCache
- $cacheFlag
- booleaninteger
Indicates if the objects should be cached and optionally, by specifying an integer value, for how many seconds.
Details
- visibility
- public
- final
- false
- static
- true
- static
_loadFieldData
_loadFieldData(
string|array $fields
)
:
Load persistent data from the source for the field(s) indicated.
Arguments
- $fields
- stringarray
A field name or array of field names to load from the data source.
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
_loadInstance
_loadInstance(
\xPDO $xpdo, string $className, \xPDOQuery|string $criteria, array $row
)
:
\xPDOObject
Loads an instance from an associative array.
Arguments
- $xpdo
- \xPDO
&$xpdo A valid xPDO instance. - $className
- string
Name of the class. - $criteria
- \xPDOQuerystring
A valid xPDOQuery instance or relation alias. - $row
- array
The associative array containing the instance data.
Output
- \xPDOObject
- A new xPDOObject derivative representing a data row.
Details
- visibility
- public
- final
- false
- static
- true
- static
_loadRows
_loadRows(
\xPDO $xpdo, string $className, \xPDOCriteria $criteria
)
:
\PDOStatement
Responsible for loading a result set from the database.
Arguments
- $xpdo
- \xPDO
&$xpdo A valid xPDO instance. - $className
- string
Name of the class. - $criteria
- \xPDOCriteria
A valid xPDOCriteria instance.
Output
- \PDOStatement
- A reference to a PDOStatement representing the result set.
Details
- visibility
- public
- final
- false
- static
- true
- static
_loadValidation
_loadValidation(
boolean $reload
=
false
)
:
Used to load validation from the object map.
Arguments
- $reload
- boolean
Indicates if the schema validation rules should be reloaded.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
_saveRelatedObject
_saveRelatedObject(
\xPDOObject $obj, array $fkMeta
)
:
boolean
Save a related object with pending changes.
This function is also responsible for setting foreign keys when new related objects are being saved, as well as local keys when the host object is new and needs the foreign key.
Arguments
- $obj
- \xPDOObject
&$obj A reference to the related object. - $fkMeta
- array
The meta data representing the relation.
Output
- boolean
- True if a related object was dirty and saved successfully.
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
_saveRelatedObjects
_saveRelatedObjects(
)
:
integer
Searches for any related objects with pending changes to save.
Output
- integer
- The number of related objects processed.
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
- uses
- xPDOObject::_saveRelatedObject()
_setRaw
_setRaw(
string $key, mixed $val
)
:
boolean
Set a raw value on a field converted to the appropriate type.
Arguments
- $key
- string
The key identifying the field to set. - $val
- mixed
The value to set.
Output
- boolean
- Returns true if the value was set, false otherwise.
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
addMany
addMany(
mixed $obj, string $alias
)
:
boolean
Adds an object or collection of objects related to this class.
This method adds an object or collection of objects in a one-to- many foreign key relationship with this object to the internal list of related objects. By adding these related objects, you can cascade {@link xPDOObject::save()}, {@link xPDOObject::remove()}, and other operations based on the type of relationships defined.
Arguments
- $obj
- mixed
&$obj A single object or collection of objects to be related to this instance via the intersection class. - $alias
- string
An optional alias, required only for instances where you have more than one relation defined to the same class.
Output
- boolean
- Indicates if the addMany was successful.
Details
- visibility
- public
- final
- false
- static
- false
- see
- xPDOObject::addOne()
- see
- xPDOObject::getOne()
- see
- xPDOObject::getMany()
addOne
addOne(
mixed $obj, string $alias
)
:
boolean
Adds an object related to this instance by a foreign key relationship.
Arguments
- $obj
- mixed
&$obj A single object to be related to this instance. - $alias
- string
The relation alias of the related object (only required if more than one relation exists to the same foreign class).
Output
- boolean
- True if the related object was added to this object.
Details
- visibility
- public
- final
- false
- static
- false
- see
- xPDOObject::getOne()
- see
- xPDOObject::getMany()
- see
- xPDOObject::addMany()
addValidationRule
addValidationRule(
string $field, string $name, string $type, string $rule, array $parameters
=
array
)
:
Add a validation rule to an object field for this instance.
Arguments
- $field
- string
The field key to apply the rule to. - $name
- string
A name to identify the rule. - $type
- string
The type of rule. - $rule
- string
The rule definition. - $parameters
- array
Any input parameters for the rule.
Details
- visibility
- public
- final
- false
- static
- false
encode
encode(
string $source, string $type
=
md5
)
:
string
Encodes a string using the specified algorithm.
NOTE: This implementation currently only implements md5. To implement additional algorithms, override this function in your xPDOObject derivative classes.
Arguments
- $source
- string
The string source to encode. - $type
- string
The type of encoding algorithm to apply, md5 by default.
Output
- string
- The encoded string.
Details
- visibility
- public
- final
- false
- static
- false
fromArray
fromArray(
array $fldarray, string $keyPrefix, boolean $setPrimaryKeys
=
false, boolean $rawValues
=
false, boolean $adhocValues
=
false
)
:
Sets object fields from an associative array of key => value pairs.
Arguments
- $fldarray
- array
An associative array of key => values. - $keyPrefix
- string
Specify an optional prefix to strip from all array keys in fldarray. - $setPrimaryKeys
- boolean
Optional param to set generated primary keys. - $rawValues
- boolean
Optional way to set values without calling the {@link xPDOObject::set()} method. - $adhocValues
- boolean
Optional way to set adhoc values so that all the values of fldarray become object vars.
Details
- visibility
- public
- final
- false
- static
- false
fromJSON
fromJSON(
string $jsonSource, string $keyPrefix, boolean $setPrimaryKeys
=
false, boolean $rawValues
=
false, boolean $adhocValues
=
false
)
:
Sets the object fields from a JSON object string.
Arguments
- $jsonSource
- string
A JSON object string. - $keyPrefix
- string
An optional prefix to strip from the keys. - $setPrimaryKeys
- boolean
Indicates if primary key fields should be set. - $rawValues
- boolean
Indicates if values should be set raw or via {@link xPDOObject::set()}. - $adhocValues
- boolean
Indicates if ad hoc fields should be added to the xPDOObject from the source object.
Details
- visibility
- public
- final
- false
- static
- false
get
get(
string|array $k, string|array $format
=
null, mixed $formatTemplate
=
null
)
:
mixed
Get a field value (or a set of values) by the field key(s) or name(s).
Warning: do not use the $format parameter if retrieving multiple values of different types, as the format string will be applied to all types, most likely with unpredicatable results. Optionally, you can supply an associate array of format strings with the field key as the key for the format array.
Arguments
- $k
- stringarray
A string (or an array of strings) representing the field key or name. - $format
- stringarray
An optional variable (or an array of variables) to format the return value(s). - $formatTemplate
- mixed
An additional optional variable that can be used in formatting the return value(s).
Output
- mixed
- The value(s) of the field(s) requested.
Details
- visibility
- public
- final
- false
- static
- false
getFKClass
getFKClass(
string $k
)
:
Get the name of a class related by foreign key to a specified field key.
This is generally used to lookup classes involved in one-to-one relationships with the current object.
Arguments
- $k
- string
The field name or key to lookup a related class for.
Details
- visibility
- public
- final
- false
- static
- false
getFKDefinition
getFKDefinition(
string $alias
)
:
array
Get a foreign key definition for a specific classname.
This is generally used to lookup classes in a one-to-many relationship with the current object.
Arguments
- $alias
- string
Alias of the related class to lookup a foreign key definition from.
Output
- array
- A foreign key definition.
Details
- visibility
- public
- final
- false
- static
- false
getFieldName
getFieldName(
string $k, string $alias
=
null
)
:
string
Gets a field name as represented in the database container.
This gets the name of the field, fully-qualified by either the object table name or a specified alias, and properly quoted.
Arguments
- $k
- string
The simple name of the field. - $alias
- string
An optional alias for the table in a specific query.
Output
- string
- The name of the field, qualified with the table name or an optional table alias.
Details
- visibility
- public
- final
- false
- static
- false
getMany
getMany(
string $alias, object $criteria
=
null, boolean|integer $cacheFlag
=
true
)
:
array
Gets a collection of objects related by aggregate or composite relations.
Arguments
- $alias
- string
Alias of the foreign class representing the related object. - $criteria
- object
xPDOCriteria object to get the related objects - $cacheFlag
- booleaninteger
Indicates if the objects should be cached and optionally, by specifying an integer value, for how many seconds.
Output
- array
- A collection of related objects or an empty array.
Details
- visibility
- public
- final
- false
- static
- false
- see
- xPDOObject::getOne()
- see
- xPDOObject::addOne()
- see
- xPDOObject::addMany()
getOne
getOne(
string $alias, object $criteria
=
null, boolean|integer $cacheFlag
=
true
)
:
\xPDOObject|null
Gets an object related to this instance by a foreign key relationship.
Use this for 1:? (one:zero-or-one) or 1:1 relationships, which you can distinguish by setting the nullability of the field representing the foreign key.
For all 1:* relationships for this instance, see {@link getMany()}.
Arguments
- $alias
- string
Alias of the foreign class representing the related object. - $criteria
- object
xPDOCriteria object to get the related objects - $cacheFlag
- booleaninteger
Indicates if the object should be cached and optionally, by specifying an integer value, for how many seconds.
Output
- \xPDOObject|null
- The related object or null if no instance exists.
Details
- visibility
- public
- final
- false
- static
- false
- see
- xPDOObject::getMany()
- see
- xPDOObject::addOne()
- see
- xPDOObject::addMany()
getOption
getOption(
string $key, array|null $options
=
null, mixed $default
=
null
)
:
mixed
Get an option value for this instance.
Arguments
- $key
- string
The option key to retrieve a value for. - $options
- arraynull
An optional array to search for a value in first. - $default
- mixed
A default value to return if no value is found; null is the default.
Output
- mixed
- The value of the option or the provided default if it is not set.
Details
- visibility
- public
- final
- false
- static
- false
getPK
getPK(
)
:
mixed
Gets the name (or names) of the primary key field(s) for the object.
Output
- mixed
- The string (or an array of strings) representing the name(s) of the primary key field(s) for this instance.
Details
- visibility
- public
- final
- false
- static
- false
getPKType
getPKType(
)
:
string
Gets the type of the primary key field for the object.
Output
- string
- The type of the primary key field for this instance.
Details
- visibility
- public
- final
- false
- static
- false
getPrimaryKey
getPrimaryKey(
boolean $validateCompound
=
true
)
:
mixed
Gets the value (or values) of the primary key field(s) for the object.
Arguments
- $validateCompound
- boolean
If any of the keys in a compound primary key are empty or null, and the default value is not allowed to be null, do not return an array, instead return null; the default is true
Output
- mixed
- The string (or an array) representing the value(s) of the primary key field(s) for this instance.
Details
- visibility
- public
- final
- false
- static
- false
getSelectColumns
getSelectColumns(
\xPDO $xpdo, string $className, string $tableAlias, string $columnPrefix, array $columns
=
array, boolean $exclude
=
false
)
:
string
Get a set of column names from an xPDOObject for use in SQL queries.
Arguments
- $xpdo
- \xPDO
&$xpdo A reference to an initialized xPDO instance. - $className
- string
The class name to get columns from. - $tableAlias
- string
An optional alias for the table in the query. - $columnPrefix
- string
An optional prefix to prepend to each column name. - $columns
- array
An optional array of field names to include or exclude (include is default behavior). - $exclude
- boolean
Determines if any specified columns should be included or excluded from the set of results.
Output
- string
- A comma-delimited list of the field names for use in a SELECT clause.
Details
- visibility
- public
- final
- false
- static
- true
- static
getValidator
getValidator(
)
:
string|boolean
Get the xPDOValidator class configured for this instance.
Output
- string|boolean
- The xPDOValidator instance or false if it could not be loaded.
Details
- visibility
- public
- final
- false
- static
- false
isDirty
isDirty(
string $key
)
:
boolean
Indicates if an object field has been modified (or never saved).
Arguments
- $key
- string
The field name to check.
Output
- boolean
- True if the field exists and either has been modified or the object is new.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
isLazy
isLazy(
string $key
)
:
boolean
Indicates if the object or specified field is lazy.
Arguments
- $key
- string
Optional key to check for laziness.
Output
- boolean
- True if the field specified or if any field is lazy if no field is specified.
Details
- visibility
- public
- final
- false
- static
- false
isNew
isNew(
)
:
boolean
Indicates if the instance is new, and has not yet been persisted.
Output
- boolean
- True if the object has not been saved or was loaded from the database.
Details
- visibility
- public
- final
- false
- static
- false
isValidated
isValidated(
string $key
)
:
boolean
Indicates if the object or specified field has been validated.
Arguments
- $key
- string
Optional key to check for specific validation.
Output
- boolean
- True if the object or specified field has been fully validated successfully.
Details
- visibility
- public
- final
- false
- static
- false
load
load(
\xPDO $xpdo, string $className, mixed $criteria, boolean|integer $cacheFlag
=
true
)
:
object|null
Load an instance of an xPDOObject or derivative class.
Arguments
- $xpdo
- \xPDO
&$xpdo A valid xPDO instance. - $className
- string
Name of the class. - $criteria
- mixed
A valid primary key, criteria array, or xPDOCriteria instance. - $cacheFlag
- booleaninteger
Indicates if the objects should be cached and optionally, by specifying an integer value, for how many seconds.
Output
- object|null
- An instance of the requested class, or null if it could not be instantiated.
Details
- visibility
- public
- final
- false
- static
- true
- static
loadCollection
loadCollection(
\xPDO $xpdo, string $className, mixed $criteria
=
null, boolean|integer $cacheFlag
=
true
)
:
array
Load a collection of xPDOObject instances.
Arguments
- $xpdo
- \xPDO
&$xpdo A valid xPDO instance. - $className
- string
Name of the class. - $criteria
- mixed
A valid primary key, criteria array, or xPDOCriteria instance. - $cacheFlag
- booleaninteger
Indicates if the objects should be cached and optionally, by specifying an integer value, for how many seconds.
Output
- array
- An array of xPDOObject instances or an empty array if no instances are loaded.
Details
- visibility
- public
- final
- false
- static
- true
- static
loadCollectionGraph
loadCollectionGraph(
\xPDO $xpdo, string $className, string|array $graph, mixed $criteria, boolean|integer $cacheFlag
)
:
array
Load a collection of xPDOObject instances and a graph of related objects.
Arguments
- $xpdo
- \xPDO
&$xpdo A valid xPDO instance. - $className
- string
Name of the class. - $graph
- stringarray
A related object graph in array or JSON format, e.g. array('relationAlias'=>array('subRelationAlias'=>array())) or {"relationAlias":{"subRelationAlias":{}}}. Note that the empty arrays are necessary in order for the relation to be recognized. - $criteria
- mixed
A valid primary key, criteria array, or xPDOCriteria instance. - $cacheFlag
- booleaninteger
Indicates if the objects should be cached and optionally, by specifying an integer value, for how many seconds.
Output
- array
- An array of xPDOObject instances or an empty array if no instances are loaded.
Details
- visibility
- public
- final
- false
- static
- true
- static
remove
remove(
array $ancestors
=
array
)
:
boolean
Remove the persistent instance of an object permanently.
Deletes the persistent object isntance stored in the database when called, including any dependent objects defined by composite foreign key relationships.
Arguments
- $ancestors
- array
Keeps track of classes which have already been removed to prevent loop with circular references.
Output
- boolean
- Returns true on success, false on failure.
Details
- visibility
- public
- final
- false
- static
- false
- todo
- Implement some way to reassign ownership of related composite objects when remove is called, perhaps by passing another object instance as an optional parameter, or creating a separate method.
removeValidationRules
removeValidationRules(
string $field
=
null, array $rules
=
array
)
:
Remove one or more validation rules from this instance.
Arguments
- $field
- string
An optional field name to remove rules from. If not specified or null, all rules from all columns will be removed. - $rules
- array
An optional array of rule names to remove if a single field is specified. If $field is null, this parameter is ignored.
Details
- visibility
- public
- final
- false
- static
- false
save
save(
boolean|integer $cacheFlag
=
null
)
:
boolean
Persist new or changed objects to the database container.
Inserts or updates the database record representing this object and any new or changed related object records. Both aggregate and composite related objects will be saved as appropriate, before or following the save operation on the controlling instance.
Arguments
- $cacheFlag
- booleaninteger
Indicates if the saved object(s) should be cached and optionally, by specifying an integer value, for how many seconds before expiring. Overrides the cacheFlag for the object(s).
Output
- boolean
- Returns true on success, false on failure.
Details
- visibility
- public
- final
- false
- static
- false
set
set(
string $k, mixed $v
=
null, string|\callable $vType
)
:
boolean
Set a field value by the field key or name.
Arguments
- $k
- string
The field key or name. - $v
- mixed
The value to set the field to. - $vType
- string\callable
A string indicating the format of the provided value parameter, or a callable function that should be used to set the field value, overriding the default behavior.
Output
- boolean
- Determines whether the value was set successfully and was determined to be dirty (i.e. different from the previous value).
Details
- visibility
- public
- final
- false
- static
- false
- todo
- Define and implement field validation.
setDirty
setDirty(
string $key
)
:
Add the field to a collection of field keys that have been modified.
This function also clears any validation flag associated with the field.
Arguments
- $key
- string
The key of the field to set dirty.
Details
- visibility
- public
- final
- false
- static
- false
setOption
setOption(
string $key, mixed $value
)
:
Set an option value for this instance.
Arguments
- $key
- string
The option key to set a value for. - $value
- mixed
A value to assign to the option.
Details
- visibility
- public
- final
- false
- static
- false
toArray
toArray(
string $keyPrefix, boolean $rawValues
=
false, boolean $excludeLazy
=
false
)
:
array
Copies the object fields and corresponding values to an associative array.
Arguments
- $keyPrefix
- string
An optional prefix to prepend to the field values. - $rawValues
- boolean
An optional flag indicating if you want the raw values instead of those returned by the {@link xPDOObject::get()} function. - $excludeLazy
- boolean
An option flag indicating if you want to exclude lazy fields from the resulting array; the default behavior is to include them which means the object will query the database for the lazy fields before providing the value.
Output
- array
- An array representation of the object fields/values.
Details
- visibility
- public
- final
- false
- static
- false
toJSON
toJSON(
string $keyPrefix, boolean $rawValues
=
false
)
:
string
Returns a JSON representation of the object.
Arguments
- $keyPrefix
- string
An optional prefix to prepend to the field keys. - $rawValues
- boolean
An optional flag indicating if the field values should be returned raw or via {@link xPDOObject::get()}.
Output
- string
- A JSON string representing the object.
Details
- visibility
- public
- final
- false
- static
- false
validate
validate(
array $options
=
array
)
:
boolean
Validate the field values using an xPDOValidator.
Arguments
- $options
- array
An array of options to pass to the validator.
Output
- boolean
- True if validation was successful.
Details
- visibility
- public
- final
- false
- static
- false
\xPDOSimpleObject
- Extends from
- \xPDOObject
- package
- xpdo
- see
- xpdo/om/mysql/xpdosimpleobject.map.inc.php
- subpackage
- om
Description
Extend to define a class with a native integer primary key field named id.
This is the basis for the entire xPDO object model, and can also be used by a class generator {@link xPDOGenerator}, ultimately allowing custom classes to be user-defined in a web interface and framework-generated at runtime.