/** * если ранее записали массив, то достаем из строки массив * * @param string $id * @param null $default * @return array|mixed */ public function get($id, $default = NULL) { $data = parent::get($id, $default); $testArray = json_decode($default, true); if (is_array($testArray)) { $data = $testArray; } return $data; }
/** * Gets a Kohana Response from the decorator * cache. If the entry is no longer available * or has expired, it is deleted and no * response is returned. * * // Get a response from the decorator * $response = $decorator->get('foo'); * * @param string key * @return Kohana_Response|boolean */ public function get($key) { return $this->_cache->get($key); }
/** * (non-PHPdoc) * @see modules/auth/classes/kohana/Kohana_Database_Mysql#query() */ public function query($type, $sql, $as_object = FALSE, array $params = NULL) { if (isset($params['caching'])) { $this->_allow_caching = $params['caching']; } if ($this->_allow_caching === TRUE) { list($auto_type, $tags) = $this->_get_tables($sql); } $cache_key = $this->get_prefix('Database::query("' . $sql . '")'); $result = FALSE; // Make sure the database is connected $this->_connection or $this->connect(); if (!empty($this->_config['connection']['persistent']) and $this->_config['connection']['database'] !== Database_MySQL::$_current_databases[$this->_connection_id]) { // Select database on persistent connections $this->_select_db($this->_config['connection']['database']); } $from_cache = TRUE; if ($this->_allow_caching !== TRUE or $type != Database::SELECT or ($result = $this->_cache_instance->get($cache_key)) === NULL) { $from_cache = FALSE; if (!empty($this->_config['profiling'])) { // Benchmark this query for the current instance $benchmark = Profiler::start("Database ({$this->_instance})", $sql); } $result = mysql_query($sql, $this->_connection); // Execute the query if ($result === FALSE) { if (isset($benchmark)) { // This benchmark is worthless Profiler::delete($benchmark); } throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error ( :query )', array(':code' => mysql_errno($this->_connection), ':error' => mysql_error($this->_connection), ':query' => $sql)); } } if (isset($benchmark)) { Profiler::stop($benchmark); } // Set the last query $this->last_query = $sql; if ($type === Database::SELECT) { if (is_resource($result)) { $returned = new Database_MySQL_Result($result, $sql, $as_object, $params); if ($this->_allow_caching === TRUE) { $this->_cache_instance->set_with_tags($cache_key, $returned->as_array(), Kohana::$cache_life, $tags); } } else { $returned = new Database_Result_Cached($result, $sql, $as_object); } return $returned; } else { if ($this->_allow_caching === TRUE) { if (!empty($tags)) { // Сброс кэша foreach ($tags as $tag) { $this->_cache_instance->delete_tag($tag, 0); } } } if ($type === Database::INSERT or $type === Database::REPLACE) { // Return a list of insert id and rows created return array(mysql_insert_id($this->_connection), mysql_affected_rows($this->_connection)); } else { // Return the number of rows affected return mysql_affected_rows($this->_connection); } } return $result; }