foreach ($options as $k => $option) {
if (is_numeric($k)) {
- if ( ! empty($option)) {
+ if (!empty($option)) {
$options[$option] = true;
}
unset($options[$k]);
return $value;
}
- public function validateField($fieldName, $value, IPF_ORM_Record $record = null)
- {
- if ($record instanceof IPF_ORM_Record) {
- $errorStack = $record->getErrorStack();
- } else {
- $record = $this->create();
- $errorStack = new IPF_ORM_Validator_ErrorStack($this->getOption('name'));
- }
-
- if ($value === self::$_null) {
- $value = null;
- } else if ($value instanceof IPF_ORM_Record) {
- $value = $value->getIncremented();
- }
-
- $dataType = $this->getTypeOf($fieldName);
-
- // Validate field type
- if ( ! IPF_ORM_Validator::isValidType($value, $dataType)) {
- $errorStack->add($fieldName, 'type');
- }
- if ($dataType == 'enum') {
- $enumIndex = $this->enumIndex($fieldName, $value);
- if ($enumIndex === false) {
- $errorStack->add($fieldName, 'enum');
- }
- }
-
- // Validate field length
- if ( ! IPF_ORM_Validator::validateLength($value, $dataType, $this->getFieldLength($fieldName))) {
- $errorStack->add($fieldName, 'length');
- }
-
- // Run all custom validators
- foreach ($this->getFieldValidators($fieldName) as $validatorName => $args) {
- if ( ! is_string($validatorName)) {
- $validatorName = $args;
- $args = array();
- }
-
- $validator = IPF_ORM_Validator::getValidator($validatorName);
- $validator->invoker = $record;
- $validator->field = $fieldName;
- $validator->args = $args;
- if ( ! $validator->validate($value)) {
- $errorStack->add($fieldName, $validator);
- }
- }
-
- return $errorStack;
- }
-
public function getColumnCount()
{
return $this->columnCount;
return $validators;
}
- public function getFieldLength($fieldName)
- {
- return $this->_columns[$this->getColumnName($fieldName)]['length'];
- }
-
public function getBoundQueryPart($queryPart)
{
if ( ! isset($this->_options['queryParts'][$queryPart])) {
// if record is persistent only the modified fields will be validated
$fields = $record->exists() ? $record->getModified():$record->getData();
foreach ($fields as $fieldName => $value) {
- $table->validateField($fieldName, $value, $record);
+ $this->validateField($table, $fieldName, $value, $record);
}
}
- public static function validateLength($value, $type, $maximumLength)
+ private function validateField(IPF_ORM_Table $table, $fieldName, $value, IPF_ORM_Record $record)
+ {
+ $errorStack = $record->getErrorStack();
+
+ if ($value === self::$_null) {
+ $value = null;
+ } else if ($value instanceof IPF_ORM_Record) {
+ $value = $value->getIncremented();
+ }
+
+ $dataType = $table->getTypeOf($fieldName);
+
+ // Validate field type
+ if (!IPF_ORM_Validator::isValidType($value, $dataType)) {
+ $errorStack->add($fieldName, 'type');
+ }
+
+ if ($dataType == 'enum') {
+ $enumIndex = $table->enumIndex($fieldName, $value);
+ if ($enumIndex === false) {
+ $errorStack->add($fieldName, 'enum');
+ }
+ }
+
+ // Validate field length
+ $definition = $table->getDefinitionOf($fieldName);
+ if (!$this->validateLength($value, $dataType, $definition['length'])) {
+ $errorStack->add($fieldName, 'length');
+ }
+
+ // Run all custom validators
+ foreach ($table->getFieldValidators($fieldName) as $validatorName => $args) {
+ if (!is_string($validatorName)) {
+ $validatorName = $args;
+ $args = array();
+ }
+
+ $validator = IPF_ORM_Validator::getValidator($validatorName);
+ $validator->invoker = $record;
+ $validator->field = $fieldName;
+ $validator->args = $args;
+ if (!$validator->validate($value)) {
+ $errorStack->add($fieldName, $validator);
+ }
+ }
+
+ return $errorStack;
+ }
+
+ public function validateLength($value, $type, $maximumLength)
{
if ($type == 'timestamp' || $type == 'integer' || $type == 'enum') {
return true;
}
}
}
+