protected function applyRulesBySchema()
{
$this->_SchemaRules = array();
foreach ($this->_Schema as $Field => $Properties) {
if (is_scalar($Properties) || $Properties === null) {
// Some code passes a record as a schema so account for that here.
$Properties = array('AutoIncrement' => false, 'AllowNull' => true, 'Type' => 'text', 'Length' => '');
$Properties = (object) $Properties;
}
// Create an array to hold rules for this field
$RuleNames = array();
// Force non-null fields without defaults to be required.
if ($Properties->AllowNull === false && $Properties->Default == '') {
$RuleNames[] = 'Required';
}
// Force other constraints based on field type.
switch ($Properties->Type) {
case 'bit':
case 'bool':
case 'boolean':
$RuleNames[] = 'Boolean';
break;
case 'tinyint':
case 'smallint':
case 'mediumint':
case 'int':
case 'integer':
case 'bigint':
$RuleNames[] = 'Integer';
break;
case 'double':
case 'float':
case 'real':
case 'decimal':
case 'dec':
case 'numeric':
case 'fixed':
$RuleNames[] = 'Decimal';
break;
case 'date':
case 'datetime':
$RuleNames[] = 'Date';
break;
case 'time':
$RuleNames[] = 'Time';
break;
case 'year':
$RuleNames[] = 'Year';
break;
case 'timestamp':
$RuleNames[] = 'Timestamp';
break;
case 'char':
case 'varchar':
case 'tinyblob':
case 'blob':
case 'mediumblob':
case 'longblob':
case 'tinytext':
case 'mediumtext':
case 'text':
case 'longtext':
case 'binary':
case 'varbinary':
if (!in_array($Field, array('Attributes', 'Data', 'Preferences', 'Permissions'))) {
$RuleNames[] = 'String';
}
if ($Properties->Length != '') {
$RuleNames[] = 'Length';
}
break;
case 'enum':
case 'set':
$RuleNames[] = 'Enum';
break;
}
if ($Field == 'Format') {
$RuleNames[] = 'Format';
}
// Assign the rules to the field.
// echo '<div>Field: '.$Field.'</div>';
// print_r($RuleNames);
$this->applyRuleTo($this->_SchemaRules, $Field, $RuleNames);
}
}