示例#1
0
 /**
  * Configures the environment for testing
  *
  * Does the following:
  *
  * * Loads the phpunit framework (for the web ui)
  * * Restores exception phpunit error handlers (for cli)
  * * registeres an autoloader to load test files
  */
 public static function configure_environment($do_whitelist = TRUE, $do_blacklist = TRUE)
 {
     restore_exception_handler();
     restore_error_handler();
     spl_autoload_register(array('Unittest_tests', 'autoload'));
     Unittest_tests::$cache = ($cache = Kohana::cache('unittest_whitelist_cache')) === NULL ? array() : $cache;
 }
示例#2
0
文件: fragment.php 项目: Normull/core
 /**
  * Delete a cached fragment.
  *
  * @param   string   fragment name
  * @return  void
  */
 public static function delete($name)
 {
     // Set the cache key name
     $cache_key = 'Fragment::cache(' . $name . ')';
     // Invalid the cache
     Kohana::cache($cache_key, NULL, -3600);
 }
示例#3
0
 /**
  * Configures the enviroment for testing
  *
  * Does the following:
  *
  * * Loads the phpunit framework (for the web ui)
  * * Restores exception phpunit error handlers (for cli)
  * * registeres an autoloader to load test files
  */
 public static function configure_enviroment($do_whitelist = TRUE, $do_blacklist = TRUE)
 {
     if (!class_exists('PHPUnit_Util_Filter', FALSE)) {
         // Make sure the PHPUnit classes are available
         require_once 'PHPUnit/Framework.php';
     }
     if (Kohana::$is_cli) {
         restore_exception_handler();
         restore_error_handler();
     }
     spl_autoload_register(array('Kohana_Tests', 'autoload'));
     Kohana_Tests::$cache = ($cache = Kohana::cache('phpunit_whitelist_cache')) === NULL ? array() : $cache;
     $config = Kohana::config('phpunit');
     if ($do_whitelist and $config->use_whitelist) {
         self::whitelist();
     }
     if ($do_blacklist and count($config['blacklist'])) {
         foreach ($config->blacklist as $item) {
             if (is_dir($item)) {
                 PHPUnit_Util_Filter::addDirectoryToFilter($item);
             } else {
                 PHPUnit_Util_Filter::addFileToFilter($item);
             }
         }
     }
 }
示例#4
0
 private static function getResponse($aURL) {
     Retio_Bitly::$_cacheKey = Retio_Bitly::CACHE_PREFIX . substr(md5(Retio_Bitly::$_url), 0, 10) .'_'. Retio_Bitly::$_action;
     
     $data                   = Kohana::cache(Retio_Bitly::$_cacheKey);
     if ($data === NULL) {
         try {
             $rData   = Request::factory($aURL)->execute()->body();
             
             switch (Retio_Bitly::$_config->format) {
                 case 'json':
                     $object = json_decode($rData);
                     $data   = ($object->status_code === 200) ? $object->data : NULL;
                 break;
                 case 'xml':
                     $object = simplexml_load_string($rData);
                     $data   = ($object->status_code === 200) ? $object->data : NULL;
                 break;
                 case 'txt':
                     $data = trim($rData);
                 break;
             }
             
             if ($data != NULL)
                 Kohana::cache(Retio_Bitly::$_cacheKey, $data, Retio_Bitly::CACHE_TIME);
             
         } catch (Exception $e) {
             return FALSE;
         }
     }
     return $data;
 }
示例#5
0
 public function execute($address)
 {
     Geocode_Yahoo::$_cacheKey = Geocode_Yahoo::CACHE_PREFIX . md5($address);
     $data = Kohana::cache(Geocode_Yahoo::$_cacheKey);
     if ($data === NULL) {
         try {
             $request = Geocode_Yahoo::API_URL . '?q=' . urlencode($address) . '&appid=' . $this->api_key . '&flags=' . $this->flags . '&locale=' . $this->locale;
             $sData = Request::factory($request)->execute()->body();
             $data = unserialize($sData);
             if ($data['ResultSet']['Error'] === 0 && $data['ResultSet']['Found'] > 0) {
                 $resultsArray = array();
                 foreach ($data['ResultSet']['Result'] as $k => $result) {
                     $resultsArray[] = array('lat' => (double) $result['latitude'], 'lng' => (double) $result['longitude'], 'zip' => (string) $result['postal'], 'city' => (string) $result['city'], 'state' => (string) $result['state'], 'country' => (string) $result['countrycode'], 'street_house' => (string) $result['street'] . ' ' . $result['house']);
                 }
                 $data = array('dataCount' => $data['ResultSet']['Found'], 'dataArray' => $resultsArray);
                 Kohana::cache(Geocode_Yahoo::$_cacheKey, $data, Geocode_Yahoo::CACHE_TIME);
             } else {
                 return FALSE;
             }
         } catch (Exception $e) {
             return FALSE;
         }
     }
     return $data;
 }
示例#6
0
 /**
  * Load pages from database, static view files,
  * or display 404 error page.
  */
 public function action_load()
 {
     Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Cms_Page::action_load');
     $page = Request::instance()->param('page');
     $page = Security::xss_clean($page);
     // Check if page is in cache
     if (Kohana::$caching === TRUE and $file = Kohana::cache('page_' . $page)) {
         $this->template->content = $file;
         return;
     }
     // Default values
     $contents = NULL;
     $found = FALSE;
     // Check if page is in database
     $db = DB::select('title', 'text')->from('pages')->where('slug', '=', $page)->execute();
     if ($db->count() == 1) {
         $contents = $db->current();
         $contents = $contents['text'];
         $found = TRUE;
     } else {
         if (Kohana::find_file('views', 'static/' . $page)) {
             $contents = new View('static/' . $page);
             $found = TRUE;
         } else {
             Kohana::$log->add(Kohana::ERROR, 'Page controller error loading non-existent page, ' . $page);
             $contents = new View('errors/404');
         }
     }
     if (Kohana::$caching === TRUE and $found) {
         Kohana::cache('page_' . $page, $contents);
     }
     $this->template->content = $contents;
 }
示例#7
0
 /**
  * A slightly modified method for fetching weather results,
  * found at http://www.web-spirit.de/webdesign-tutorial/9/Wetter-auf-eigener-Website-mit-Google-Weather-API
  * @param  string $city
  * @param  string $language
  * @return array
  * @uses   Kohana::cache
  */
 public static function get_data($city, $language = 'de')
 {
     $aReturn = Kohana::cache('weather-api', NULL, 3600);
     if ($aReturn === NULL) {
         $aReturn = array();
         $oXml = simplexml_load_string(utf8_encode(file_get_contents('http://www.google.com/ig/api?weather=' . $city . '&hl=' . $language)));
         $aReturn['city'] = (string) $oXml->weather->forecast_information->city->attributes()->data;
         $aReturn['date'] = (string) $oXml->weather->forecast_information->forecast_date->attributes()->data;
         $aReturn['time'] = (string) $oXml->weather->forecast_information->current_date_time->attributes()->data;
         $aReturn['now']['condition'] = (string) $oXml->weather->current_conditions->condition->attributes()->data;
         $aReturn['now']['temperature'] = (string) $oXml->weather->current_conditions->temp_c->attributes()->data;
         $aReturn['now']['humidity'] = (string) $oXml->weather->current_conditions->humidity->attributes()->data;
         $aReturn['now']['wind'] = (string) $oXml->weather->current_conditions->wind_condition->attributes()->data;
         $aReturn['now']['icon'] = str_replace('/ig/images/weather/', '', $oXml->weather->current_conditions->icon->attributes()->data);
         $i = 1;
         foreach ($oXml->weather->forecast_conditions as $oWeather) {
             $aReturn['days'][$i]['weekday'] = (string) $oWeather->day_of_week->attributes()->data;
             $aReturn['days'][$i]['condition'] = (string) $oWeather->condition->attributes()->data;
             $aReturn['days'][$i]['temperature_min'] = (string) $oWeather->low->attributes()->data;
             $aReturn['days'][$i]['temperature_max'] = (string) $oWeather->high->attributes()->data;
             $aReturn['days'][$i]['icon'] = str_replace('/ig/images/weather/', '', $oWeather->icon->attributes()->data);
             $i++;
         }
         // foreach
         Kohana::cache('weather-api', $aReturn);
     }
     // if
     return $aReturn;
 }
示例#8
0
文件: tests.php 项目: azuya/Wi3
 /**
  * Configures the environment for testing
  *
  * Does the following:
  *
  * * Loads the phpunit framework (for the web ui)
  * * Restores exception phpunit error handlers (for cli)
  * * registeres an autoloader to load test files
  */
 public static function configure_environment($do_whitelist = TRUE, $do_blacklist = TRUE)
 {
     // During a webui request we need to manually load PHPUnit
     if (!class_exists('PHPUnit_Util_Filter', FALSE) and !function_exists('phpunit_autoload')) {
         try {
             include_once 'PHPUnit/Autoload.php';
         } catch (ErrorException $e) {
             include_once 'PHPUnit/Framework.php';
         }
     }
     // Allow PHPUnit to handle exceptions and errors
     if (Kohana::$is_cli) {
         restore_exception_handler();
         restore_error_handler();
     }
     spl_autoload_register(array('Kohana_Tests', 'autoload'));
     Kohana_Tests::$cache = ($cache = Kohana::cache('unittest_whitelist_cache')) === NULL ? array() : $cache;
     // As of PHPUnit v3.5 there are slight differences in the way files are black|whitelisted
     self::$phpunit_v35 = function_exists('phpunit_autoload');
     $config = Kohana::config('unittest');
     if ($do_whitelist and $config->use_whitelist) {
         self::whitelist();
     }
     if ($do_blacklist and count($config['blacklist'])) {
         Kohana_Tests::blacklist($config->blacklist);
     }
 }
示例#9
0
 /**
  * Configures the environment for testing
  *
  * Does the following:
  *
  * * Loads the phpunit framework (for the web ui)
  * * Restores exception phpunit error handlers (for cli)
  * * registeres an autoloader to load test files
  */
 public static function configure_environment($do_whitelist = TRUE, $do_blacklist = TRUE)
 {
     restore_exception_handler();
     restore_error_handler();
     spl_autoload_register(array('Unittest_tests', 'autoload'));
     // As of PHPUnit v3.5 there are slight differences in the way files are black|whitelisted
     self::$phpunit_v35 = function_exists('phpunit_autoload');
     Unittest_tests::$cache = ($cache = Kohana::cache('unittest_whitelist_cache')) === NULL ? array() : $cache;
 }
示例#10
0
 public static function load_fixtures()
 {
     $fixture = Functest_Fixture::instance();
     $import_sql = Kohana::cache(Functest_Tests::FIXTURE_CACHE);
     if ($import_sql) {
         $fixture->replace($import_sql);
     } else {
         $fixture->truncate_all();
         $fixture->execute_import_files(Functest_Tests::fixture_files());
         Kohana::cache(Functest_Tests::FIXTURE_CACHE, $fixture->dump(), Date::HOUR);
     }
 }
示例#11
0
文件: loader.php 项目: ukd1/kohana
 public function offsetExists($group)
 {
     if (!parent::offsetExists($group)) {
         if (($config = Kohana::cache('kohana_config_' . $group)) === NULL) {
             // Load the configuration group
             $config = $this->load($group);
             // Cache the configuration
             Kohana::cache('kohana_config_' . $group, $config);
         }
         // Set the missing configuration
         $this->offsetSet($group, new Kohana_Config($config));
     }
     return TRUE;
 }
示例#12
0
 public function action_cache($keyandext)
 {
     if (substr($keyandext, -3) == 'css') {
         $key = substr($keyandext, 0, -3);
         $this->request->headers['Content-Type'] = 'text/css';
     } elseif (substr($keyandext, -2) == 'js') {
         $key = substr($keyandext, 0, -2);
     } else {
         return;
     }
     $content = Kohana::cache($key);
     //$this->request->headers['Content-Type'] = 'application/javascript';
     $this->request->response = $content;
 }
示例#13
0
文件: REST.php 项目: ChrisCov/HUKD
 public function execute()
 {
     if ($this->_is_cached === true) {
         $cache_key = 'REST-api-result' . $this->_url;
         if (($result = Kohana::cache($cache_key, NULL, $this->_cache_life)) !== NULL) {
             return $this->_as_object ? json_decode($result) : $result;
         } else {
             $result = $this->_execute_request($this->_url);
             Kohana::cache($cache_key, $result, $this->_cache_life);
             return $this->_as_object ? json_decode($result) : $result;
         }
     }
     // get data if caching is disabled
     $result = $this->_execute_request($this->_url);
     return $this->_as_object ? json_decode($result) : $result;
 }
示例#14
0
文件: config.php 项目: ukd1/kohana
 /**
  * Creates a new configuration object for the specified group. When caching
  * is enabled, Kohana_Config will attempt to load the group from the cache.
  *
  * @param   string   group name
  * @param   boolean  cache the group array
  * @return  void
  */
 public function __construct($group, $cache = TRUE)
 {
     // Set the configuration group name
     $this->_configuration_group = $group;
     if ($cache === FALSE) {
         // Load the configuration
         $config = Kohana_Config::load($group);
     } elseif (($config = Kohana::cache(self::CACHE_PREFIX . $group)) === NULL) {
         // Load the configuration, it has not been cached
         $config = Kohana_Config::load($group);
         // Create a cache of the configuration group
         Kohana::cache(self::CACHE_PREFIX . $group, $config);
     }
     // Load the array using the values as properties
     ArrayObject::__construct($config, ArrayObject::ARRAY_AS_PROPS);
 }
示例#15
0
 public function test_load_fixtures()
 {
     global $_functest_test_counter;
     $_functest_test_counter = 0;
     Kohana::cache(Functest_Tests::FIXTURE_CACHE, null, 0);
     Database::instance(Kohana::TESTING)->query(NULL, 'DELETE FROM table1');
     Functest_Tests::load_fixtures();
     $result = Database::instance(Kohana::TESTING)->query(Database::SELECT, 'SELECT * FROM table1');
     $expected = array(array('id' => 1, 'name' => 'test record'));
     $this->assertEquals(1, $_functest_test_counter);
     $this->assertEquals($expected, $result->as_array());
     Database::instance(Kohana::TESTING)->query(NULL, 'DELETE FROM table1');
     Functest_Tests::load_fixtures();
     $result = Database::instance(Kohana::TESTING)->query(Database::SELECT, 'SELECT * FROM table1');
     $this->assertEquals($expected, $result->as_array());
     $this->assertEquals(1, $_functest_test_counter, 'Should load the sql from the cache. so the counter is not incremented');
 }
示例#16
0
 public function before()
 {
     //J'ai préféré utiliser la fonction Kohana::cache plutôt que le module Cache
     if (Kohana::cache('sidebar_categories') == NULL) {
         $sidebar_categories = ORM::factory('Category')->order_by('post_count', 'DESC')->find_all();
         Kohana::cache('sidebar_categories', $sidebar_categories->cached(), 60 * 60);
         // 60s * 60s = 1 heure
     }
     View::set_global('sidebar_categories', Kohana::cache('sidebar_categories'));
     if (Kohana::cache('sidebar_posts') == NULL) {
         $sidebar_posts = ORM::factory('Post')->order_by('created', 'DESC')->order_by('id', 'DESC')->limit(2)->find_all();
         Kohana::cache('sidebar_posts', $sidebar_posts->cached(), 60 * 60);
         // 60s * 60s = 1 heure
     }
     View::set_global('sidebar_posts', Kohana::cache('sidebar_posts'));
     if (strrpos($this->request->action(), 'post_') === FALSE) {
         parent::before();
     }
     //pas besoin de créer une vue pour ce cas
 }
示例#17
0
文件: date.php 项目: Normull/core
 /**
  * Returns the offset (in seconds) between two time zones.
  *
  * @see     http://php.net/timezones
  * @param   string  timezone that to find the offset of
  * @param   string  timezone used as the baseline
  * @return  integer
  */
 public static function offset($remote, $local = NULL)
 {
     if ($local === NULL) {
         // Use the default timezone
         $local = date_default_timezone_get();
     }
     // Set the cache key, matches the method name
     $cache_key = "Date::offset({$remote},{$local})";
     if (($offset = Kohana::cache($cache_key)) === NULL) {
         // Create timezone objects
         $zone_remote = new DateTimeZone($remote);
         $zone_local = new DateTimeZone($local);
         // Create date objects from timezones
         $time_remote = new DateTime('now', $zone_remote);
         $time_local = new DateTime('now', $zone_local);
         // Find the offset
         $offset = $zone_remote->getOffset($time_remote) - $zone_local->getOffset($time_local);
         // Cache the offset
         Kohana::cache($cache_key, $offset);
     }
     return $offset;
 }
示例#18
0
 /**
  * Gets description for instance of [CLI_Task] class.
  * 
  *     $info = CLI_Task_Info::get_info($name);
  * 
  * @param  string|object $name task name or instance of [CLI_Task] class
  * @return array
  */
 public static function get_info($name)
 {
     if (is_object($name)) {
         // Convert object to task name
         $name = CLI_Tasker::class2name($name);
     }
     if (Kohana::$caching) {
         // Create cache key\tag for find task information
         $cache_key = __METHOD__ . '(' . $name . ')';
         // Try load information from cache
         if ($info = Kohana::cache($cache_key)) {
             return $info;
         }
     }
     // Convert task name to class name
     $class = CLI_Tasker::name2class($name);
     // Create task inspector
     $inspector = new ReflectionClass($class);
     // Get class description and convert to display in CLI
     $description = $inspector->getDocComment();
     // Normalize all new lines to `\n`
     $description = str_replace(array("\r\n", "\n"), "\n", $description);
     // Remove the phpdoc open\close tags and split
     $description = array_slice(explode("\n", $description), 1, -1);
     foreach ($description as $i => $line) {
         // Remove all leading whitespace
         $description[$i] = preg_replace('/^\\s*\\* ?/m', '', $line);
     }
     $description = implode(PHP_EOL, $description);
     // Get default options
     $options = (array) $inspector->getProperty('options')->getValue();
     // Combine information in array
     $info = compact('name', 'class', 'description', 'options');
     if (Kohana::$caching) {
         // Cache task information
         Kohana::cache($cache_key, $info, 3600);
     }
     return $info;
 }
示例#19
0
 public function action_index()
 {
     $this->template->content = View::factory('deals/index')->bind('products', $products)->bind('numproducts', $numproducts)->bind('filter_name', $merchant);
     $merchant = '';
     $results_per_page = 0;
     // get url params
     if ($this->request->query('merchant') !== null && $this->request->query('results_per_page') !== null) {
         $merchant = $this->request->query('merchant');
         $results_per_page = $this->request->query('results_per_page');
     }
     $key = Kohana::$config->load('rest')->get('hotukdeals')['api_key'];
     $fmt = Kohana::$config->load('rest')->get('hotukdeals')['api_search_url_fmt'];
     $url = sprintf($fmt, $key, $merchant, $results_per_page);
     $cache_life = Kohana::$config->load('rest')->get('hotukdeals')['cache_life'];
     $cache_key = 'products:' . $url;
     // retrieve cached data from RESTful service
     try {
         if (($products = Kohana::cache($cache_key, NULL, $cache_life)) === NULL) {
             $objects = Helper::factory('REST')->url($url)->as_object()->execute();
             $products = $objects->deals->items;
             foreach ($products as $product) {
                 $product->display_page_url = $this->_get_product_display_page($product->deal_image);
             }
             $products = $this->_remove_expired_products($products);
             $products = $this->_order_by_temperature($products);
             // store retrieved products to cache
             Kohana::cache($cache_key, $products, $cache_life);
         }
         $numproducts = count($products);
     } catch (ErrorException $e) {
         //clear cache
         Kohana::cache($cache_key, NULL, 0);
         if (is_object(Kohana::$log)) {
             Kohana_Exception::log($e);
         }
         $this->template->content = View::factory('deals/error');
     }
 }
示例#20
0
 public function action_index()
 {
     $storage = array();
     $tweets = array();
     // Check to see if we have a valid cached version
     foreach ($this->search_terms as $item) {
         if (($storage[$item] = Kohana::cache($item)) === NULL) {
             // We need to generate this item
             $storage[$item] = file_get_contents('http://search.twitter.com/search.json?q=%23' . $item);
             // Save the new item to the cache
             Kohana::cache($item, $storage[$item], $this->cache_seconds);
         }
     }
     // Convert the json to an array and send it through to the view
     foreach ($this->search_terms as $item) {
         if (($temp = json_decode($storage[$item])) === NULL) {
             $this->template->error = __("performance breakdown, and I don't wanna hear it, I'm just not available");
             return;
         }
         $tweets[$item] = $temp->results;
     }
     $this->template->tweets = $tweets;
 }
示例#21
0
文件: kohana.php 项目: anqh/anqh
 /**
  * Override core shutdown_handler to user Anqh_Exceptions.
  *
  * @uses  Anqh_Exception::handler
  */
 public static function shutdown_handler()
 {
     // Do not execute when not active
     if (!Kohana::$_init) {
         return;
     }
     try {
         if (Kohana::$caching === true and Kohana::$_files_changed === true) {
             // Write the file path cache
             Kohana::cache('Kohana::find_file()', Kohana::$_files);
         }
     } catch (Exception $e) {
         // Pass the exception to the handler
         Anqh_Exception::handler($e);
     }
     if (Kohana::$errors and $error = error_get_last() and in_array($error['type'], Kohana::$shutdown_errors)) {
         // Clean the output buffer
         ob_get_level() and ob_clean();
         // Fake an exception for nice debugging
         Anqh_Exception::handler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
         // Shutdown now to avoid a "death loop"
         exit(1);
     }
 }
示例#22
0
 /**
  * Gets the total application run time and memory usage.
  *
  * @return  array  execution time, memory
  */
 public static function application()
 {
     // Load the stats from cache, which is valid for 1 day
     $stats = Kohana::cache('profiler_application_stats', NULL, 3600 * 24);
     if (!is_array($stats) or $stats['count'] > 1000) {
         // Initialize the stats array
         $stats = array('min' => array('time' => NULL, 'memory' => NULL), 'max' => array('time' => NULL, 'memory' => NULL), 'total' => array('time' => NULL, 'memory' => NULL), 'count' => 0);
     }
     // Get the application run time
     $time = microtime(TRUE) - KOHANA_START_TIME;
     // Get the total memory usage
     $memory = memory_get_usage();
     if ($stats['max']['time'] === NULL or $time > $stats['max']['time']) {
         $stats['max']['time'] = $time;
     }
     if ($stats['min']['time'] === NULL or $time < $stats['min']['time']) {
         $stats['min']['time'] = $time;
     }
     // Add on to the time
     $stats['total']['time'] += $time;
     if ($stats['max']['memory'] === NULL or $memory > $stats['max']['memory']) {
         $stats['max']['memory'] = $memory;
     }
     if ($stats['min']['memory'] === NULL or $memory < $stats['min']['memory']) {
         $stats['min']['memory'] = $memory;
     }
     // Add on to the memory
     $stats['total']['memory'] += $memory;
     // Another mark has been added to the stats
     $stats['count']++;
     // Determine the averages
     $stats['average'] = array('time' => $stats['total']['time'] / $stats['count'], 'memory' => $stats['total']['memory'] / $stats['count']);
     // Cache the new stats
     Kohana::cache('profiler_application_stats', $stats);
     // Return the total application run time and memory usage
     return $stats;
 }
示例#23
0
文件: route.php 项目: ascseb/core
 /**
  * Saves or loads the route cache.
  *
  * @param   boolean   cache the current routes
  * @return  void      when saving routes
  * @return  boolean   when loading routes
  */
 public static function cache($save = FALSE)
 {
     if ($save === TRUE) {
         // Cache all defined routes
         Kohana::cache('Route::cache()', Route::$_routes);
     } else {
         if ($routes = Kohana::cache('Route::cache()')) {
             Route::$_routes = $routes;
             // Routes were cached
             return TRUE;
         } else {
             // Routes were not cached
             return FALSE;
         }
     }
 }
示例#24
0
 /**
  * Saves or loads the route cache. If your routes will remain the same for
  * a long period of time, use this to reload the routes from the cache
  * rather than redefining them on every page load.
  *
  *     if ( ! Route::cache())
  *     {
  *         // Set routes here
  *         Route::cache(TRUE);
  *     }
  *
  * @param   boolean $save   cache the current routes
  * @param   boolean $append append, rather than replace, cached routes when loading
  * @return  void    when saving routes
  * @return  boolean when loading routes
  * @uses    Kohana::cache
  */
 public static function cache($save = FALSE, $append = FALSE)
 {
     if ($save === TRUE) {
         try {
             // Cache all defined routes
             Kohana::cache('Route::cache()', Route::$_routes);
         } catch (Exception $e) {
             // We most likely have a lambda in a route, which cannot be cached
             throw new Kohana_Exception('One or more routes could not be cached (:message)', array(':message' => $e->getMessage()), 0, $e);
         }
     } else {
         if ($routes = Kohana::cache('Route::cache()')) {
             if ($append) {
                 // Append cached routes
                 Route::$_routes += $routes;
             } else {
                 // Replace existing routes
                 Route::$_routes = $routes;
             }
             // Routes were cached
             return Route::$cache = TRUE;
         } else {
             // Routes were not cached
             return Route::$cache = FALSE;
         }
     }
 }
示例#25
0
 /**
  * Delete a cached fragment.
  *
  *     Fragment::delete($key);
  *
  * @param   string  $name   fragment name
  * @param   boolean $i18n   multilingual fragment support
  * @return  void
  */
 public static function delete($name, $i18n = NULL)
 {
     // Invalid the cache
     Kohana::cache(Fragment::_cache_key($name, $i18n), NULL, -3600);
 }
示例#26
0
 /**
  * This function manages query caching.
  *
  * @access protected
  * @param string $sql                           the SQL statement being queried
  * @param string $type                          the return type that is being used
  * @param DB_ResultSet $results                 the result set
  * @return DB_ResultSet                         the result set for the specified
  */
 protected function cache($sql, $type, $results = NULL)
 {
     if ($this->data_source->cache->enabled) {
         if ($results !== NULL) {
             if ($this->data_source->cache->lifetime > 0) {
                 Kohana::cache($this->cache_key, $results, $this->data_source->cache->lifetime);
             }
             return $results;
         } else {
             if ($this->data_source->cache->lifetime !== NULL) {
                 $this->cache_key = 'DB_Connection_Driver::query("' . $this->data_source->id . '", "' . $type . '", "' . $sql . '")';
                 $results = Kohana::cache($this->cache_key, NULL, $this->data_source->cache->lifetime);
                 if ($results !== NULL and !$this->data_source->cache->force) {
                     return $results;
                 }
             }
         }
     }
     return $results;
 }
示例#27
0
文件: core.php 项目: ascseb/core
 /**
  * Catches errors that are not caught by the error handler, such as E_PARSE.
  *
  * @uses    Kohana::exception_handler()
  * @return  void
  */
 public static function shutdown_handler()
 {
     try {
         if (self::$caching === TRUE and self::$_files_changed === TRUE) {
             // Write the file path cache
             Kohana::cache('Kohana::find_file()', self::$_files);
         }
     } catch (Exception $e) {
         // Pass the exception to the handler
         Kohana::exception_handler($e);
     }
     if ($error = error_get_last()) {
         // If an output buffer exists, clear it
         ob_get_level() and ob_clean();
         // Fake an exception for nice debugging
         Kohana::exception_handler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
     }
 }
示例#28
0
 /**
  * Tests Kohana::cache()
  *
  * @test
  * @dataProvider provider_cache
  * @covers Kohana::cache
  * @param boolean $key      Key to cache/get for Kohana::cache
  * @param boolean $value    Output from Kohana::cache
  * @param boolean $lifetime Lifetime for Kohana::cache
  */
 public function test_cache($key, $value, $lifetime)
 {
     Kohana::cache($key, $value, $lifetime);
     $this->assertEquals($value, Kohana::cache($key));
 }
示例#29
0
文件: query.php 项目: nevermlnd/cv
	/**
	 * Execute the current query on the given database.
	 *
	 * @param   mixed    Database instance or name of instance
	 * @return  object   Database_Result for SELECT queries
	 * @return  mixed    the insert id for INSERT queries
	 * @return  integer  number of affected rows for all other queries
	 */
	public function execute($db = NULL)
	{
		if ( ! is_object($db))
		{
			// Get the database instance
			$db = Database::instance($db);
		}

		// Compile the SQL query
		$sql = $this->compile($db);

		if ( ! empty($this->_lifetime) AND $this->_type === Database::SELECT)
		{
			// Set the cache key based on the database instance name and SQL
			$cache_key = 'Database::query("'.$db.'", "'.$sql.'")';

			if ($result = Kohana::cache($cache_key, NULL, $this->_lifetime))
			{
				// Return a cached result
				return new Database_Result_Cached($result, $sql, $this->_as_object, $this->_object_params);
			}
		}

		// Execute the query
		$result = $db->query($this->_type, $sql, $this->_as_object, $this->_object_params);

		if (isset($cache_key))
		{
			// Cache the result array
			Kohana::cache($cache_key, $result->as_array(), $this->_lifetime);
		}

		return $result;
	}
示例#30
0
文件: Config.php 项目: JasonWiki/docs
 /**
  * Loads the cached version of this configuration driver
  *
  * @return  array
  * @access  public
  */
 public function load_cache()
 {
     // Load the cache for this configuration
     $cached_config = Kohana::cache($this->cache_name, $this->cache_lifetime);
     // If the configuration wasn't loaded from the cache
     if ($cached_config === NULL) {
         $cached_config = array();
     }
     // Return the cached config
     return $cached_config;
 }