Dynamically handles many centralized object-relational mapping tasks
1.0.0b28 | Updated getColumnName() and getRecordName() to use fText if loaded 2/2/11 |
---|---|
1.0.0b27 | Added links to the detailed documentation for the parameters passed to hooks 11/27/10 |
1.0.0b26 | Added getRelatedClass() for handling related classes in PHP 5.3 namespaces 11/17/10 |
1.0.0b25 | Added support for PHP 5.3 namespaced fActiveRecord classes 11/11/10 |
1.0.0b24 | Backwards Compatibility Break - Callbacks registered via registerRecordSetMethod() should now accept the $method_name in the position where the $pointer parameter used to be passed 9/28/10 |
1.0.0b23 | Added the 'pre::replicate()', 'post::replicate()' and 'cloned::replicate()' hooks 9/7/10 |
1.0.0b22 | Internal Backwards Compatibility Break - changed parseMethod() to not underscorize the subject of the method 8/6/10 |
1.0.0b21 | Fixed some documentation to reflect the API changes from v1.0.0b9 7/14/10 |
1.0.0b20 | Added the ability to register a wildcard active record method for all classes 4/22/10 |
1.0.0b19 | Added the method isClassMappedToTable() 3/30/10 |
1.0.0b18 | Added the post::loadFromIdentityMap() hook 3/14/10 |
1.0.0b17 | Changed enableSchemaCaching() to rely on fDatabaseclearCache() instead of explicitly calling fSQLTranslation::clearCache() 3/9/10 |
1.0.0b16 | Backwards Compatibility Break - renamed addCustomClassToTableMapping() to mapClassToTable(). Added getDatabaseName() and mapClassToDatabase(). Updated code for new fORMDatabase and fORMSchema APIs 10/28/09 |
1.0.0b15 | Added support for fActiveRecord to getRecordName() 10/6/09 |
1.0.0b14 | Updated documentation for registerActiveRecordMethod() to include info about prefix method matches 8/7/09 |
1.0.0b13 | Updated documentation for registerRecordSetMethod() 7/14/09 |
1.0.0b12 | Updated callReflectCallbacks() to accept a class name instead of an object 7/13/09 |
1.0.0b11 | Added registerInspectCallback() and callInspectCallbacks() 7/13/09 |
1.0.0b10 | Fixed a bug with objectify() caching during NULL date/time/timestamp values and breaking further objectification 6/18/09 |
1.0.0b9 | Added caching for performance and changed some method APIs to only allow class names instead of instances 6/15/09 |
1.0.0b8 | Updated documentation to reflect removal of $associate parameter for callbacks passed to registerRecordSetMethod() 6/2/09 |
1.0.0b7 | Added enableSchemaCaching() to replace fORMSchema::enableSmartCaching() 5/4/09 |
1.0.0b6 | Added the ability to pass a class instance to addCustomClassTableMapping() 2/23/09 |
1.0.0b5 | Backwards compatibility break - renamed addCustomTableClassMapping() to addCustomClassTableMapping() and swapped the parameters 1/26/09 |
1.0.0b4 | Fixed a bug with retrieving fActiveRecord methods registered for all classes 1/14/09 |
1.0.0b3 | Fixed a static method callback constant 12/17/08 |
1.0.0b2 | Added replicate() and registerReplicateCallback() for fActiveRecord::replicate() 12/12/08 |
1.0.0b | The initial implementation 8/4/07 |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Calls the hook callbacks for the class and hook specified
void callHookCallbacks( fActiveRecord $object, string $hook, array &$values, array &$old_values, array &$related_records, array &$cache, mixed &$parameter=NULL )
fActiveRecord | $object | The instance of the class to call the hook for |
string | $hook | The hook to call |
array | &$values | The current values of the record |
array | &$old_values | The old values of the record |
array | &$related_records | Records related to the current record |
array | &$cache | The cache array of the record |
mixed | &$parameter | The parameter to send the callback |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Calls all inspect callbacks for the class and column specified
void callInspectCallbacks( string $class, string $column, array &$metadata )
string | $class | The class to inspect the column of |
string | $column | The column to inspect |
array | &$metadata | The associative array of data about the column |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Calls all reflect callbacks for the class passed
void callReflectCallbacks( string $class, array &$signatures, boolean $include_doc_comments )
string | $class | The class to call the callbacks for |
array | &$signatures | The associative array of {method_name} => {signature} |
boolean | $include_doc_comments | If the doc comments should be included in the signature |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Checks to see if any (or a specific) callback has been registered for a specific hook
boolean checkHookCallback( string $class, string $hook, array $callback=NULL )
string | $class | The name of the class |
string | $hook | The hook to check |
array | $callback | The specific callback to check for |
If the specified callback exists
Takes a table and turns it into a class name - uses custom mapping if set
string classize( string $table )
string | $table | The table name |
The class name
Will dynamically create an fActiveRecord-based class for a database table
Normally this would be called from an __autoload() function.
This method will only create classes for tables in the default ORM database.
void defineActiveRecordClass( string $class )
string | $class | The name of the class to create |
Enables caching on the fDatabase, fSQLTranslation and fSchema objects used for the ORM
This method will cache database schema information to the three objects that use it during normal ORM operation: fDatabase, fSQLTranslation and fSchema. To allow for schema changes without having to manually clear the cache, all cached information will be cleared if any fUnexpectedException objects are thrown.
This method should be called right after fORMDatabase::attach().
void enableSchemaCaching( fCache $cache, string $database_name='default', string $key_token=NULL )
fCache | $cache | The object to cache schema information to |
string | $database_name | The database to enable caching for |
string | $key_token | This is a token that is used in cache keys to prevent conflicts for server-wide caches - when non-NULL the document root is used |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Returns a matching callback for the class and method specified
The callback returned will be determined by the following logic:
1. If an exact callback has been defined for the method, it will be returned 2. If a callback in the form {prefix}* has been defined that matches the method, it will be returned 3. NULL will be returned
string|null getActiveRecordMethod( string $class, string $method )
string | $class | The name of the class |
string | $method | The method to get the callback for |
The callback for the method or NULL if none exists - see method description for details
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Takes a class name or class and returns the class name
string getClass( mixed $class )
mixed | $class | The object to get the name of, or possibly a string already containing the class |
The class name
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Returns the column name
The default column name is the result of calling fGrammar::humanize() on the column.
string getColumnName( string $class, string $column )
string | $class | The class name the column is part of |
string | $column | The database column |
The column name for the column specified
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Returns the name for the database used by the class specified
string getDatabaseName( string $class )
string | $class | The class name to get the database name for |
The name of the database to use
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Returns the record name for a class
The default record name is the result of calling fGrammar::humanize() on the class.
string getRecordName( string $class )
string | $class | The class name to get the record name of |
The record name for the class specified
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Returns a matching callback for the method specified
The callback returned will be determined by the following logic:
1. If an exact callback has been defined for the method, it will be returned 2. If a callback in the form {action}* has been defined that matches the method, it will be returned 3. NULL will be returned
string|null getRecordSetMethod( string $method )
string | $method | The method to get the callback for |
The callback for the method or NULL if none exists - see method description for details
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Takes a class name and related class name and ensures the related class has the appropriate namespace prefix
string getRelatedClass( string $class, string $related_class )
string | $class | The primary class |
string | $related_class | The related class name |
The related class name, with the appropriate namespace prefix
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Checks if a class has been mapped to a table
boolean isClassMappedToTable( mixed $class )
mixed | $class | The name of the class |
If the class has been mapped to a table
Sets a class to use a database other than the "default"
Multiple database objects can be attached for the ORM by passing a unique $name to the attach() method.
void mapClassToDatabase( mixed $class, string $database_name )
mixed | $class | The name of the class, or an instance of it |
string | $database_name | The name given to the database when passed to attach() |
Allows non-standard class to table mapping
By default, all database tables are assumed to be plural nouns in underscore_notation and all class names are assumed to be singular nouns in UpperCamelCase. This method allows arbitrary class to table mapping.
void mapClassToTable( mixed $class, string $table )
mixed | $class | The name of the class, or an instance of it |
string | $table | The name of the database table |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Takes a scalar value and turns it into an object if applicable
mixed objectify( string $class, string $column, mixed $value )
string | $class | The class name of the class the column is part of |
string | $column | The database column |
mixed | $value | The value to possibly objectify |
The scalar or object version of the value, depending on the column type and column options
Allows overriding of default column names
By default a column name is the result of fGrammar::humanize() called on the column.
void overrideColumnName( mixed $class, string $column, string $column_name )
mixed | $class | The class name or instance of the class the column is located in |
string | $column | The database column |
string | $column_name | The name for the column |
Allows overriding of default record names
By default a record name is the result of fGrammar::humanize() called on the class.
void overrideRecordName( mixed $class, string $record_name )
mixed | $class | The class name or instance of the class to override the name of |
string | $record_name | The human version of the record |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Parses a camelCase method name for an action and subject in the form actionSubject()
array parseMethod( string $method )
string | $method | The method name to parse |
An array of 0 => {action}, 1 => {subject}
Registers a callback for an fActiveRecord method that falls through to fActiveRecord::__call() or hits a predefined method hook
The callback should accept the following parameters:
void registerActiveRecordMethod( mixed $class, string $method, callback $callback )
mixed | $class | The class name or instance of the class to register for, '*' will register for all classes |
string | $method | The method to hook for - this can be a complete method name or {prefix}* where * will match any column name |
callback | $callback | The callback to execute - see method description for parameter list |
Registers a callback for one of the various fActiveRecord hooks - multiple callbacks can be registered for each hook
The method signature should include the follow parameters:
The 'pre::validate()' and 'post::validate()' hooks have an extra parameter:
The 'pre::replicate()', 'post::replicate()' and 'cloned::replicate()' hooks have an extra parameter:
Below is a list of all valid hooks:
void registerHookCallback( mixed $class, string $hook, callback $callback )
mixed | $class | The class name or instance of the class to hook, '*' will hook all classes |
string | $hook | The hook to register for |
callback | $callback | The callback to register - see the method description for details about the method signature |
Registers a callback to modify the results of fActiveRecord::inspect() methods
void registerInspectCallback( mixed $class, string $column, callback $callback )
mixed | $class | The class name or instance of the class to register for |
string | $column | The column to register for |
callback | $callback | The callback to register. Callback should accept a single parameter by reference, an associative array of the various metadata about a column. |
Registers a callback for when objectify() is called on a specific column
void registerObjectifyCallback( mixed $class, string $column, callback $callback )
mixed | $class | The class name or instance of the class to register for |
string | $column | The column to register for |
callback | $callback | The callback to register. Callback should accept a single parameter, the value to objectify and should return the objectified value. |
Registers a callback for an fRecordSet method that fall through to fRecordSet::__call()
The callback should accept the following parameters:
void registerRecordSetMethod( string $method, callback $callback )
string | $method | The method to hook for |
callback | $callback | The callback to execute - see method description for parameter list |
Registers a callback to modify the results of fActiveRecord::reflect()
Callbacks registered here can override default method signatures and add method signatures, however any methods that are defined in the actual class will override these signatures.
The callback should accept three parameters:
void registerReflectCallback( mixed $class, callback $callback )
mixed | $class | The class name or instance of the class to register for, '*' will register for all classes |
callback | $callback | The callback to register. Callback should accept a three parameters - see method description for details. |
Registers a callback for when a value is replicated for a specific column
void registerReplicateCallback( mixed $class, string $column, callback $callback )
mixed | $class | The class name or instance of the class to register for |
string | $column | The column to register for |
callback | $callback | The callback to register. Callback should accept a single parameter, the value to replicate and should return the replicated value. |
Registers a callback for when scalarize() is called on a specific column
void registerScalarizeCallback( mixed $class, string $column, callback $callback )
mixed | $class | The class name or instance of the class to register for |
string | $column | The column to register for |
callback | $callback | The callback to register. Callback should accept a single parameter, the value to scalarize and should return the scalarized value. |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Takes and value and returns a copy is scalar or a clone if an object
The registerReplicateCallback() allows for custom replication code
mixed replicate( string $class, string $column, mixed $value )
string | $class | The class the column is part of |
string | $column | The database column |
mixed | $value | The value to copy/clone |
The copied/cloned value
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Resets the configuration of the class
void reset( )
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
If the value passed is an object, calls __toString() on it
mixed scalarize( mixed $class, string $column, mixed $value )
mixed | $class | The class name or instance of the class the column is part of |
string | $column | The database column |
mixed | $value | The value to get the scalar value of |
The scalar value of the value
Takes a class name (or class) and turns it into a table name - Uses custom mapping if set
string tablize( string $class )
string | $class | The class name |
The table name