public function run() { self::setup(); //Process route SilkRequest::handle_request(); $config = silk()->get('config'); if ($config['debug']) { echo SilkProfiler::get_instance()->report(); } }
/** * Saves the ORM'd object back to the database. First it calls the validation method to make * sure that all validation passes. If successful, it then determines if this is a new record * or updated record and INSERTs or UPDATEs accordingly. * * Updated records are only saved if they have been changed (dirty flag is set). If you're doing * any low level changes to the $params array directly, you should set the dirty flag to true * to make sure any changes are saved. * * @return boolean Whether or not the save was successful or not. If it wasn't, check the validation stack for errors. */ function save() { $this->before_validation_caller(); if ($this->_call_validation()) { return false; } $this->before_save_caller(); $db = db(); $table = $this->get_table(); $id_field = $this->id_field; $id = $this->{$id_field}; //Figure out if we need to replace the field from the field mappings $new_map = array_flip($this->field_maps); //Flip the keys, since this is the reverse operation if (array_key_exists($id_field, $new_map)) { $id_field = $new_map[$id_field]; } $fields = $this->get_columns_in_table(); $time = $db->DBTimeStamp(time()); //If we have an id, so an update. //If not, do an insert. if (isset($id) && $id > 0) { SilkProfiler::get_instance()->mark('Before Update'); if ($this->dirty) { SilkProfiler::get_instance()->mark('Dirty Bit True'); $query = "UPDATE {$table} SET "; $midpart = ''; $queryparams = array(); foreach ($fields as $onefield => $obj) { $localname = $onefield; if (array_key_exists($localname, $this->field_maps)) { $localname = $this->field_maps[$localname]; } if ($onefield == $this->modified_date_field) { #$queryparams[] = $time; $midpart .= "{$table}.{$onefield} = {$time}, "; $this->{$onefield} = time(); } else { if ($this->type_field != '' && $this->type_field == $onefield) { $this->{$onefield} = strtolower(get_class($this)); $queryparams[] = strtolower(get_class($this)); $midpart .= "{$table}.{$onefield} = ?, "; } else { if (array_key_exists($localname, $this->params)) { if ($this->params[$localname] instanceof SilkDateTime) { $midpart .= "{$table}.{$onefield} = " . $this->params[$localname]->to_sql_string() . ", "; } else { $queryparams[] = $this->params[$localname]; $midpart .= "{$table}.{$onefield} = ?, "; } } } } } if ($midpart != '') { $midpart = substr($midpart, 0, -2); $query .= $midpart . " WHERE {$table}.{$id_field} = ?"; $queryparams[] = $id; } try { $result = $db->Execute($query, $queryparams) ? true : false; } catch (Exception $e) { $result = false; } if ($result) { $this->dirty = false; SilkProfiler::get_instance()->mark('Dirty Bit Reset'); } $this->after_save_caller($result); return $result; } return true; } else { $new_id = -1; SilkProfiler::get_instance()->mark('Before Insert'); if ($this->sequence != '') { $new_id = $db->GenID(db_prefix() . $this->sequence); $this->{$id_field} = $new_id; } $query = "INSERT INTO {$table} ("; $midpart = ''; $queryparams = array(); foreach ($fields as $onefield => $obj) { $localname = $onefield; if (array_key_exists($localname, $this->field_maps)) { $localname = $this->field_maps[$localname]; } if ($onefield == $this->create_date_field || $onefield == $this->modified_date_field) { $queryparams[] = trim($time, "'"); $midpart .= $onefield . ', '; $this->{$onefield} = time(); } else { if ($this->type_field != '' && $this->type_field == $onefield) { $queryparams[] = strtolower(get_class($this)); $midpart .= $onefield . ', '; $this->{$onefield} = strtolower(get_class($this)); } else { if (array_key_exists($localname, $this->params)) { if (!($new_id == -1 && $localname == $this->id_field)) { if ($this->params[$localname] instanceof SilkDateTime) { $queryparams[] = trim($this->params[$localname]->to_sql_string(), "'"); } else { $queryparams[] = $this->params[$localname]; } $midpart .= $onefield . ', '; } } } } } if ($midpart != '') { $midpart = substr($midpart, 0, -2); $query .= $midpart . ') VALUES ('; $query .= implode(',', array_fill(0, count($queryparams), '?')); $query .= ')'; } try { $result = $db->Execute($query, $queryparams) ? true : false; } catch (Exception $e) { $result = false; } if ($result) { if ($new_id == -1) { $new_id = $db->Insert_ID(); $this->{$id_field} = $new_id; } $this->dirty = false; $this->after_save_caller($result); } return $result; } }
function count_cached_execs($db, $secs2cache, $sql, $inputarray) { SilkProfiler::get_instance()->mark('CACHED:' . $sql); global $CACHED; $CACHED++; }
public function test_me() { SilkProfiler::get_instance()->mark('Test Me -- SilkActsAsTest'); }