/** * 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; } }
/** * Get database field definition * @params pdoMap_Mapping_Metadata_Field Field to manage * @returns array of pdoMap_Mapping_Metadata_Field */ public function getMeta(pdoMap_Mapping_Metadata_Field $field) { if ($field->type != 'Boolean') { throw new pdoMap_Database_Fields_Exceptions_BadType($field, 'Boolean'); } return array(pdoMap_Mapping_Metadata_Field::duplicate($field, pdoMap_Mapping_Metadata_Field::FIELD_TYPE_ENUM, null, null, array('value' => array(self::TRUE_ENUM, self::FALSE_ENUM)))); }
/** * Get database field definition * @params pdoMap_Mapping_Metadata_Field Field to manage * @returns array of pdoMap_Mapping_Metadata_Field */ public function getMeta(pdoMap_Mapping_Metadata_Field $field) { if ($field->type != 'Date') { throw new pdoMap_Database_Fields_Exceptions_BadType($field, 'Date'); } return array(pdoMap_Mapping_Metadata_Field::duplicate($field, pdoMap_Mapping_Metadata_Field::FIELD_TYPE_DATE)); }
/** * Get database field definition * @params pdoMap_Mapping_Metadata_Field Field to manage * @returns array of pdoMap_Mapping_Metadata_Field */ public function getMeta(pdoMap_Mapping_Metadata_Field $field) { if ($field->type != 'Text') { throw new pdoMap_Database_Fields_Exceptions_BadType($field, 'Text'); } return array(pdoMap_Mapping_Metadata_Field::duplicate($field, pdoMap_Mapping_Metadata_Field::FIELD_TYPE_TEXT, null, null, array('size' => null))); }
/** * Duplicate a field and change some information */ public static function duplicate(pdoMap_Mapping_Metadata_Field $field, $type = null, $name = null, $bind = null, $options = null) { $ret = new pdoMap_Mapping_Metadata_Field($field->name, $field->bind, $field->type, $field->getOptions()); if (!is_null($type)) { $ret->type = $type; } if (!is_null($name)) { $ret->name = $name; } if (!is_null($bind)) { $ret->bind = $bind; } if (!is_null($options)) { foreach ($options as $key => $value) { $ret->setOption($key, $value); } } return $ret; }
/** * 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_string($value)) { return false; } else { return strlen($value) <= $field->getOption('size'); } }
/** * 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) { return in_array($value, $field->getOption('value')); }
/** * 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 true; } elseif ($value instanceof pdoMap_Mapping_Entity) { return $value->getType() == $field->getOption('adapter'); } else { return false; } }
/** * 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; }