Example #1
0
 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;
         }
     }
 }
Example #2
0
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;
    }
}
Example #3
0
    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);
}
Example #4
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;
         }
     }
 }
Example #5
0
<?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']);
}
Example #6
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   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;
         }
     }
 }
 /**
  * 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);
 }
Example #8
0
 /**
  * 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');
 }
Example #9
0
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);
}