Exemple #1
0
        throw new DbException('Database model ' . get_called_class() . ': can\'t find field `' . $field . '` in the schema');
    }
    public function __set($field, $value)
    {
        debug('DbModel::__set(' . $field . ', ' . var_export($value, true) . ')');
        $schema = self::get_schema();
        if (!array_key_exists($field, $schema)) {
            throw new DbException('Database model ' . get_called_class() . ': can\'t find field `' . $field . '` in the schema');
        }
        if ($field == $this->get_primary_key()) {
            throw new DbException('Can\'t assign a value to the primary key of the object');
        }
        if (!$schema[$field]->can_assign_value($value)) {
            warning('Can\'t assign this value to ' . get_called_class() . '::' . $field . ':');
            html_var_dump($value);
            throw new InvalidValueException('Can\'t assign this value to ' . get_called_class() . '::' . $field . ':');
        }
        $this->fields[$field] = $value;
        return true;
    }
}
DbModel::$connection = new DbConnection();
class DbException extends Exception
{
}
class InvalidValueException extends DbException
{
}
class DbConstraintsException extends DbException
{
}