本文整理汇总了PHP中Route::cache方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::cache方法的具体用法?PHP Route::cache怎么用?PHP Route::cache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route::cache方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cache
public static function cache($save = FALSE, $append = FALSE)
{
if ($save === TRUE) {
try {
JsonApiApplication::cache('Route::cache()', Route::$_routes);
} catch (Exception $e) {
throw new JsonApiApplication_Exception('One or more routes could not be cached (:message)', array(':message' => $e->getMessage()), 0, $e);
}
} else {
if ($routes = JsonApiApplication::cache('Route::cache()')) {
if ($append) {
Route::$_routes += $routes;
} else {
Route::$_routes = $routes;
}
return Route::$cache = TRUE;
} else {
return Route::$cache = FALSE;
}
}
}
示例2: Kohana_Log_File
Kohana::$log->attach(new Kohana_Log_File(APPPATH . 'logs'));
/**
* Attach a file reader to config. Multiple readers are supported.
*/
Kohana::$config->attach(new Kohana_Config_File());
/**
* Enable modules. Modules are referenced by a relative or absolute path.
*/
Kohana::modules(array());
/**
* Set the routes. Each route must have a minimum of a name, a URI and a set of
* defaults for the URI.
*/
// if ( ! Route::cache())
// {
Route::set('cron', 'cron/injest')->defaults(array('controller' => 'cron', 'action' => 'injest'));
Route::set('default', '(<controller>(/<action>(/<id>)))')->defaults(array('controller' => 'front', 'action' => 'index'));
// Save the routes to cache
Route::cache(TRUE);
// }
/**
* Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
* If no source is specified, the URI will be automatically detected.
*/
if (!defined('SUPPRESS_REQUEST')) {
try {
echo Request::instance($_SERVER['PATH_INFO'])->execute()->send_headers()->body();
} catch (Exception $e) {
throw $e;
}
}
示例3: Log_File
Kohana::$log->attach(new Log_File(APPPATH . 'logs'));
}
/**
* Default path for uploads directory.
* Path are referenced by a relative or absolute path.
*/
Upload::$default_directory = APPPATH . 'uploads';
/**
* Set the routes
*
* Each route must have a minimum of a name,
* a URI and a set of defaults for the URI.
*
* Example:
* ~~~
* Route::set('frontend/page', 'page(/<action>)')
* ->defaults(array(
* 'controller' => 'page',
* 'action' => 'view',
* ));
* ~~~
*
* @uses Path::lookup
* @uses Route::cache
* @uses Route::set
*/
if (!Route::cache()) {
Route::set('default', '(<controller>(/<action>(/<id>)))')->filter('Path::lookup')->defaults(array('controller' => 'welcome', 'action' => 'index'));
// Cache the routes in production
Route::cache(Kohana::$environment === Kohana::PRODUCTION);
}
示例4: cache
/**
* 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;
}
}
}
示例5: defined
<?php
defined('SYSPATH') or die('No direct script access.');
if (!Route::cache()) {
Route::set('b_settings', ADMIN . '/settings(/<action>)', ['action' => 'i18n'])->defaults(['directory' => 'Settings/Backend', 'controller' => 'page', 'action' => 'edit']);
}
示例6: cache
/**
* 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 cache the current routes
* @return void when saving routes
* @return boolean when loading routes
* @uses Kohana::cache
*/
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 Route::$cache = TRUE;
} else {
// Routes were not cached
return Route::$cache = FALSE;
}
}
}
示例7: test_cache_returns_false_if_cache_dnx
/**
* Route::cache() should return FALSE if cached routes could not be found
*
* The cache is cleared before and after each test in setUp tearDown
* by cleanCacheDir()
*
* @test
* @covers Route::cache
*/
public function test_cache_returns_false_if_cache_dnx()
{
$this->assertSame(FALSE, Route::cache(), 'Route cache was not empty');
// Check the route cache flag
$this->assertFalse(Route::$cache);
}
示例8: test_cache_returns_false_if_cache_dnx
/**
* Route::cache() should return FALSE if cached routes could not be found
*
* The cache is cleared before and after each test in setUp tearDown
* by clean_cache_dir()
*
* @test
* @covers Route::cache
*/
public function test_cache_returns_false_if_cache_dnx()
{
$this->assertSame(FALSE, Route::cache(), 'Route cache was not empty');
}
示例9: define
if (!defined('REST_URL_FORMAT_RESOURCE')) {
define('REST_URL_FORMAT_RESOURCE', '[a-zA-Z][a-zA-Z0-9_\\./]*');
}
if (!defined('REST_LOG_DIR')) {
define('REST_LOG_DIR', Arr::get($_SERVER, 'REST_LOG_DIR', LOG_TMP_DIR));
}
if (!defined('REST_METRIC_NAMESPACE')) {
define('REST_METRIC_NAMESPACE', Arr::get($_SERVER, 'REST_METRIC_NAMESPACE', null));
}
if (!defined('REST_PRODUCT_CONFIG_DIR')) {
define('REST_PRODUCT_CONFIG_DIR', Arr::get($_SERVER, 'REST_PRODUCT_CONFIG_DIR', null));
}
if (!defined('RESOURCE_QUERY_LIMIT_DEFAULT')) {
define('RESOURCE_QUERY_LIMIT_DEFAULT', Arr::get($_SERVER, 'RESOURCE_QUERY_LIMIT_DEFAULT', 10));
}
if (!defined('RESOURCE_QUERY_LIMIT_MAX')) {
define('RESOURCE_QUERY_LIMIT_MAX', Arr::get($_SERVER, 'RESOURCE_QUERY_LIMIT_MAX', 100));
}
if (!Kohana::$errors && 'cli' !== php_sapi_name()) {
set_exception_handler(array('Rest_Exception', 'handler'));
set_error_handler(array('Rest_Error', 'handler'));
register_shutdown_function(array('Rest_Error', 'shutdown_handler'));
}
/**
* Cache Routes.
*/
if (!Route::cache()) {
include __DIR__ . DIRECTORY_SEPARATOR . 'routes.php';
// Cache the routes in Production
Route::cache(Kohana::PRODUCTION === Kohana::$environment || Kohana::STAGING === Kohana::$environment);
}