/** * Validate a value * @params pdoMap_Mapping_Entity Entity to handle * @params pdoMap_Mapping_Metadata_Field Field to manage * @params mixed Value to handle * @returns boolean True if value is valid or false if not */ public function Validate(pdoMap_Mapping_Entity $entity, pdoMap_Mapping_Metadata_Field $field, $value) { if (!is_numeric($value)) { return false; } if ($field->GetOption('unsigned') == 'true') { return $value >= 0; } else { return true; } }
/** * Validate a value * @params pdoMap_Mapping_Entity Entity to handle * @params pdoMap_Mapping_Metadata_Field Field to manage * @params mixed Value to handle * @returns boolean True if value is valid or false if not */ public function Validate(pdoMap_Mapping_Entity $entity, pdoMap_Mapping_Metadata_Field $field, $value) { // CHECK TYPE if (!is_int($value)) { return false; } // CHECK SIZE switch ($field->getOption('size')) { case 'tiny': $max = 255; break; case 'small': $max = 65535; break; case 'medium': $max = 16777215; break; case 'normal': $max = 4294967295.0; case 'big': $max = mt_getrandmax(); // biggest value : 18446744073709551615; break; } if ($field->GetOption('unsigned') != 'true') { $min = -$max - 1; $max = ($max - 1) / 2; } else { $min = 0; } return $value >= $min && $value <= $max; }