* protected $table = array( * 'name' => 'images', // the name of this database table * 'temporary' => FALSE, // is this table a temporary one? * 'check_exists' => TRUE, // can/do we perform checks to see if this table exists for creates/drops? * * // table joins, eg: this table joins its own column 'user_id' on to the column users.user_id * 'joins' => array( * 'user_id' => array( * 'table' => 'users', * 'column' => 'user_id', * ), * ), * 'engine' => '', // the engine that this table uses, eg: myisam or innodb * 'charset' => '', // the charset of the table, eg: utf8 * 'auto_increment' => 1, // where to start auto incrementing from * ); * */ protected $table = array(); /** * The column name of this tables primary key, if any. */ protected $primary; /** * A multidimensional array of all of the column names to their respective properties. * Each column in the array should be formatted as follows: * * 'column_name' => array( * 'type' => '', // int, tinyint, bigint, integer, number, char, varchar, text, blob * // decimal, float, etc. * 'length' => 0, // eg: the '255' in varchar(255) or the '10' in int(10) * 'signed' => FALSE, // whether or not this column is signed, FALSE = unsigned * 'auto_increment' => TRUE, // does this column auto increment? * 'null' => FALSE, // FALSE = not null * 'default' => '', // the default value of this column * ), * * Note: only put the keys/values that apply to the column. */ protected $fields = array(); /** * A multidimensional array of this tables keys. Each key should be formatted as follows: * * 'column_name' => array( * 'primary' => FALSE, // true/false for if this is a primary key * * // if this is a foreign key, it must be formatted like * 'foreign' => array( * 'references' => array( * 'table' => 'table_name', * 'column' => 'column_name', * ), * 'on_delete' => 'no action', * 'on_update' => 'no action', * ) * ), * */ protected $keys = array(); /** * An array of check constraints * eg: 'column_id <> 0' */ protected $checks = array(); /** * Generic function to validate values against the info set in the $fields * array. * @see ModelDefinition::$fields * @see Record::save() * @param array $keys A reference to an array of column names to check. * @param array $vals A reference to an array of column values to check/enforce proper type. */ final public function validate(&$keys, &$vals) { foreach($keys as $i => $column) { if(isset($this->fields[$column])) { switch(strtolower($this->fields[$column]['type'])) { case 'float': case 'double': case 'decimal': $vals[$i] = (float)$vals[$i]; break; case 'number': case 'int': case 'integer': case 'bigint': case 'tinyint': $vals[$i] = (int)$vals[$i]; break; } if(isset($this->fields[$column]['signed']) && !$this->fields[$column]['signed']) { $vals[$i] = abs($vals[$i]); } } else { unset($keys[$i], $vals[$i]); } } } }