fORMValidationstatic classv1.0.0b22
Handles validation for fActiveRecord classes
| 1.0.0b22 | Made the value checking for one-or-more and only-one rules more robust when detecting the absence of a value 12/17/09 |
|---|---|
| 1.0.0b21 | Fixed a bug affecting where conditions with columns that are not null but have a default value 11/3/09 |
| 1.0.0b20 | Updated code for the new fORMDatabase and fORMSchema APIs 10/28/09 |
| 1.0.0b19 | Changed SQL statements to use value placeholders, identifier escaping and schema support 10/22/09 |
| 1.0.0b18 | Fixed checkOnlyOneRule() and checkOneOrMoreRule() to consider blank strings as NULL 8/21/09 |
| 1.0.0b17 | Added @internal methods removeStringReplacement() and removeRegexReplacement() 7/29/09 |
| 1.0.0b16 | Backwards Compatibility Break - renamed addConditionalValidationRule() to addConditionalRule(), addManyToManyValidationRule() to addManyToManyRule(), addOneOrMoreValidationRule() to addOneOrMoreRule(), addOneToManyValidationRule() to addOneToManyRule(), addOnlyOneValidationRule() to addOnlyOneRule(), addValidValuesValidationRule() to addValidValuesRule() 7/13/09 |
| 1.0.0b15 | Added addValidValuesValidationRule() [wb/jt, 2009-07-13] 12/31/69 |
| 1.0.0b14 | Added addStringReplacement() and addRegexReplacement() for simple validation message modification 7/1/09 |
| 1.0.0b13 | Changed reorderMessages() to compare string in a case-insensitive manner 6/30/09 |
| 1.0.0b12 | Updated addConditionalValidationRule() to allow any number of $main_columns, and if any of those have a matching value, the condtional columns will be required 6/30/09 |
| 1.0.0b11 | Fixed a couple of bugs with validating related records 6/26/09 |
| 1.0.0b10 | Fixed UNIQUE constraint checking so it is only done once per constraint, fixed some UTF-8 case sensitivity issues 6/17/09 |
| 1.0.0b9 | Updated code for new fORM API 6/15/09 |
| 1.0.0b8 | Updated code to use new fValidationException::formatField() method 6/4/09 |
| 1.0.0b7 | Updated validateRelated() to use new fORMRelated::validate() method and checkRelatedOneOrMoreRule() to use new $related_records structure 6/2/09 |
| 1.0.0b6 | Changed date/time/timestamp checking from strtotime() to fDate/fTime/fTimestamp for better localization support 6/1/09 |
| 1.0.0b5 | Fixed a bug in checkOnlyOneRule() where no values would not be flagged as an error 4/23/09 |
| 1.0.0b4 | Fixed a bug in checkUniqueConstraints() related to case-insensitive columns 2/15/09 |
| 1.0.0b3 | Implemented proper fix for addManyToManyValidationRule() 12/12/08 |
| 1.0.0b2 | Fixed a bug with addManyToManyValidationRule() 12/8/08 |
| 1.0.0b | The initial implementation 8/4/07 |
Static Methods
::addConditionalRule() public
Adds a conditional rule
If a non-empty value is found in one of the $main_columns, or if specified, a value from the $conditional_values array, all of the $conditional_columns will also be required to have a value.
Signature
void addConditionalRule( mixed $class, string|array $main_columns, mixed $conditional_values, string|array $conditional_columns )
Parameters
| mixed | $class | The class name or instance of the class this rule applies to |
| string|array | $main_columns | The column(s) to check for a value |
| mixed | $conditional_values | If NULL, any value in the main column will trigger the conditional column(s), otherwise the value must match this scalar value or be present in the array of values |
| string|array | $conditional_columns | The column(s) that are to be required |
::addManyToManyRule() public
Add a many-to-many rule that requires at least one related record is associated with the current record
Signature
void addManyToManyRule( mixed $class, string $related_class, string $route=NULL )
Parameters
| mixed | $class | The class name or instance of the class to add the rule for |
| string | $related_class | The name of the related class |
| string | $route | The route to the related class |
::addOneOrMoreRule() public
Adds a one-or-more rule that requires at least one of the columns specified has a value
Signature
void addOneOrMoreRule( mixed $class, array $columns )
Parameters
| mixed | $class | The class name or instance of the class the columns exists in |
| array | $columns | The columns to check |
::addOneToManyRule() public
Add a one-to-many rule that requires at least one related record is associated with the current record
Signature
void addOneToManyRule( mixed $class, string $related_class, string $route=NULL )
Parameters
| mixed | $class | The class name or instance of the class to add the rule for |
| string | $related_class | The name of the related class |
| string | $route | The route to the related class |
::addOnlyOneRule() public
Add an only-one rule that requires exactly one of the columns must have a value
Signature
void addOnlyOneRule( mixed $class, array $columns )
Parameters
| mixed | $class | The class name or instance of the class the columns exists in |
| array | $columns | The columns to check |
::addRegexReplacement() public
Adds a call to preg_replace() for each message
Regex replacement is done after the post::validate() hook, and right before the messages are reordered.
If a message is an empty string after replacement, it will be removed from the list of messages.
Signature
void addRegexReplacement( mixed $class, string $search, string $replace )
Parameters
| mixed | $class | The class name or instance of the class the columns exists in |
| string | $search | The PCRE regex to search for - see http://php.net/pcre for details |
| string | $replace | The string to replace with - all $ and \ are used in back references and must be escaped with a \ when meant literally |
::addStringReplacement() public
Adds a call to str_replace() for each message
String replacement is done after the post::validate() hook, and right before the messages are reordered.
If a message is an empty string after replacement, it will be removed from the list of messages.
Signature
void addStringReplacement( mixed $class, string $search, string $replace )
Parameters
| mixed | $class | The class name or instance of the class the columns exists in |
| string | $search | The string to search for |
| string | $replace | The string to replace with |
::addValidValuesRule() public
Restricts a column to having only a value from the list of valid values
Please note that NULL values are always allowed, even if not listed in the $valid_values array, if the column is not set as NOT NULL.
This functionality can also be accomplished by added a CHECK constraint on the column in the database, or using a MySQL ENUM data type.
Signature
void addValidValuesRule( mixed $class, string $column, array $valid_values )
Parameters
| mixed | $class | The class name or instance of the class this rule applies to |
| string | $column | The column to validate |
| array | $valid_values | The valid values to check - NULL values are always allows if the column is not set to NOT NULL |
::inspect() internal public
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
Adds metadata about features added by this class
Signatures
void inspect( string $class, string $column )
void inspect( array $metadata )
Parameters
| string | $class | The class being inspected |
| string | $column | The column being inspected |
| array | &$metadata | The array of metadata about a column |
::removeRegexReplacement() internal public
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
Removes a regex replacement
Signature
void removeRegexReplacement( mixed $class, string $search, string $replace )
Parameters
| mixed | $class | The class name or instance of the class the columns exists in |
| string | $search | The string to search for |
| string | $replace | The string to replace with |
::removeStringReplacement() internal public
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
Removes a string replacement
Signature
void removeStringReplacement( mixed $class, string $search, string $replace )
Parameters
| mixed | $class | The class name or instance of the class the columns exists in |
| string | $search | The string to search for |
| string | $replace | The string to replace with |
::reorderMessages() internal public
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
Reorders list items in an html string based on their contents
Signature
array reorderMessages( string $class, array $messages )
Parameters
| string | $class | The class to reorder messages for |
| array | $messages | An array of the messages |
Returns
The reordered messages
::replaceMessages() internal public
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 list of messages and performs string and regex replacements on them
Signature
array replaceMessages( string $class, array $messages )
Parameters
| string | $class | The class to reorder messages for |
| array | $messages | The array of messages |
Returns
The new array of messages
::reset() internal public
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
Signature
void reset( )
::setColumnCaseInsensitive() public
Sets a column to be compared in a case-insensitive manner when checking UNIQUE and PRIMARY KEY constraints
Signature
void setColumnCaseInsensitive( mixed $class, string $column )
Parameters
| mixed | $class | The class name or instance of the class the column is located in |
| string | $column | The column to set as case-insensitive |
::setMessageOrder() public
Allows setting the order that the list items in a message will be displayed
All string comparisons during the reordering process are done in a case-insensitive manner.
Signature
void setMessageOrder( mixed $class, array $matches )
Parameters
| mixed | $class | The class name or an instance of the class to set the message order for |
| array | $matches | This should be an ordered array of strings. If a line contains the string it will be displayed in the relative order it occurs in this array. |
::validate() internal public
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
Validates values for an fActiveRecord object against the database schema and any additional rules that have been added
Signature
array validate( fActiveRecord $object, array $values, array $old_values )
Parameters
| fActiveRecord | $object | The instance of the class to validate |
| array | $values | The values to validate |
| array | $old_values | The old values for the record |
Returns
An array of messages
::validateRelated() internal public
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
Validates related records for an fActiveRecord object
Signatures
array validateRelated( fActiveRecord $object )
array validateRelated( array $values, array $related_records )
Parameters
| fActiveRecord | $object | The object to validate |
| array | &$values | The values for the object |
| array | &$related_records | The related records for the object |
Returns
An array of messages
