示例#1
0
 /**
  * Initializes the environment:
  *
  * - Disables register_globals and magic_quotes_gpc
  * - Determines the current environment
  * - Set global settings
  * - Sanitizes GET, POST, and COOKIE variables
  * - Converts GET, POST, and COOKIE variables to the global character set
  *
  * Any of the global settings can be set here:
  *
  * Type      | Setting    | Description                                    | Default Value
  * ----------|------------|------------------------------------------------|---------------
  * `boolean` | errors     | use internal error and exception handling?     | `TRUE`
  * `boolean` | profile    | do internal benchmarking?                      | `TRUE`
  * `boolean` | caching    | cache the location of files between requests?  | `FALSE`
  * `string`  | charset    | character set used for all input and output    | `"utf-8"`
  * `string`  | base_url   | set the base URL for the application           | `"/"`
  * `string`  | index_file | set the index.php file name                    | `"index.php"`
  * `string`  | cache_dir  | set the cache directory path                   | `APPPATH."cache"`
  *
  * @throws  Kohana_Exception
  * @param   array   global settings
  * @return  void
  * @uses    Kohana::globals
  * @uses    Kohana::sanitize
  * @uses    Kohana::cache
  * @uses    Profiler
  */
 public static function init(array $settings = NULL)
 {
     if (Kohana::$_init) {
         // Do not allow execution twice
         return;
     }
     // Kohana is now initialized
     Kohana::$_init = TRUE;
     if (isset($settings['profile'])) {
         // Enable profiling
         Kohana::$profiling = (bool) $settings['profile'];
     }
     if (Kohana::$profiling === TRUE) {
         // Start a new benchmark
         $benchmark = Profiler::start('Kohana', __FUNCTION__);
     }
     // Start an output buffer
     ob_start();
     if (defined('E_DEPRECATED')) {
         // E_DEPRECATED only exists in PHP >= 5.3.0
         Kohana::$php_errors[E_DEPRECATED] = 'Deprecated';
     }
     if (isset($settings['errors'])) {
         // Enable error handling
         Kohana::$errors = (bool) $settings['errors'];
     }
     if (Kohana::$errors === TRUE) {
         // Enable Kohana exception handling, adds stack traces and error source.
         set_exception_handler(array('Kohana', 'exception_handler'));
         // Enable Kohana error handling, converts all PHP errors to exceptions.
         set_error_handler(array('Kohana', 'error_handler'));
     }
     // Enable the Kohana shutdown handler, which catches E_FATAL errors.
     register_shutdown_function(array('Kohana', 'shutdown_handler'));
     if (ini_get('register_globals')) {
         // Reverse the effects of register_globals
         Kohana::globals();
     }
     // Determine if we are running in a command line environment
     Kohana::$is_cli = PHP_SAPI === 'cli';
     // Determine if we are running in a Windows environment
     Kohana::$is_windows = DIRECTORY_SEPARATOR === '\\';
     if (isset($settings['cache_dir'])) {
         // Set the cache directory path
         Kohana::$cache_dir = realpath($settings['cache_dir']);
     } else {
         // Use the default cache directory
         Kohana::$cache_dir = APPPATH . 'cache';
     }
     if (!is_writable(Kohana::$cache_dir)) {
         throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Kohana::debug_path(Kohana::$cache_dir)));
     }
     if (isset($settings['caching'])) {
         // Enable or disable internal caching
         Kohana::$caching = (bool) $settings['caching'];
     }
     if (Kohana::$caching === TRUE) {
         // Load the file path cache
         Kohana::$_files = Kohana::cache('Kohana::find_file()');
     }
     if (isset($settings['charset'])) {
         // Set the system character set
         Kohana::$charset = strtolower($settings['charset']);
     }
     if (function_exists('mb_internal_encoding')) {
         // Set the MB extension encoding to the same character set
         mb_internal_encoding(Kohana::$charset);
     }
     if (isset($settings['base_url'])) {
         // Set the base URL
         Kohana::$base_url = rtrim($settings['base_url'], '/') . '/';
     }
     if (isset($settings['index_file'])) {
         // Set the index file
         Kohana::$index_file = trim($settings['index_file'], '/');
     }
     // Determine if the extremely evil magic quotes are enabled
     Kohana::$magic_quotes = (bool) get_magic_quotes_gpc();
     // Sanitize all request variables
     $_GET = Kohana::sanitize($_GET);
     $_POST = Kohana::sanitize($_POST);
     $_COOKIE = Kohana::sanitize($_COOKIE);
     // Load the logger
     Kohana::$log = Kohana_Log::instance();
     // Load the config
     Kohana::$config = Kohana_Config::instance();
     if (isset($benchmark)) {
         // Stop benchmarking
         Profiler::stop($benchmark);
     }
 }
示例#2
0
文件: Core.php 项目: eok8177/shopCMS
 /**
  * Initializes the environment:
  *
  * - Disables register_globals and magic_quotes_gpc
  * - Determines the current environment
  * - Set global settings
  * - Sanitizes GET, POST, and COOKIE variables
  * - Converts GET, POST, and COOKIE variables to the global character set
  *
  * The following settings can be set:
  *
  * Type      | Setting    | Description                                    | Default Value
  * ----------|------------|------------------------------------------------|---------------
  * `string`  | base_url   | The base URL for your application.  This should be the *relative* path from your DOCROOT to your `index.php` file, in other words, if Kohana is in a subfolder, set this to the subfolder name, otherwise leave it as the default.  **The leading slash is required**, trailing slash is optional.   | `"/"`
  * `string`  | index_file | The name of the [front controller](http://en.wikipedia.org/wiki/Front_Controller_pattern).  This is used by Kohana to generate relative urls like [HTML::anchor()] and [URL::base()]. This is usually `index.php`.  To [remove index.php from your urls](tutorials/clean-urls), set this to `FALSE`. | `"index.php"`
  * `string`  | charset    | Character set used for all input and output    | `"utf-8"`
  * `string`  | cache_dir  | Kohana's cache directory.  Used by [Kohana::cache] for simple internal caching, like [Fragments](kohana/fragments) and **\[caching database queries](this should link somewhere)**.  This has nothing to do with the [Cache module](cache). | `APPPATH."cache"`
  * `integer` | cache_life | Lifetime, in seconds, of items cached by [Kohana::cache]         | `60`
  * `boolean` | errors     | Should Kohana catch PHP errors and uncaught Exceptions and show the `error_view`. See [Error Handling](kohana/errors) for more info. <br /> <br /> Recommended setting: `TRUE` while developing, `FALSE` on production servers. | `TRUE`
  * `boolean` | profile    | Whether to enable the [Profiler](kohana/profiling). <br /> <br />Recommended setting: `TRUE` while developing, `FALSE` on production servers. | `TRUE`
  * `boolean` | caching    | Cache file locations to speed up [Kohana::find_file].  This has nothing to do with [Kohana::cache], [Fragments](kohana/fragments) or the [Cache module](cache).  <br /> <br />  Recommended setting: `FALSE` while developing, `TRUE` on production servers. | `FALSE`
  * `boolean` | expose     | Set the X-Powered-By header
  *
  * @throws  Kohana_Exception
  * @param   array   $settings   Array of settings.  See above.
  * @return  void
  * @uses    Kohana::globals
  * @uses    Kohana::sanitize
  * @uses    Kohana::cache
  * @uses    Profiler
  */
 public static function init(array $settings = NULL)
 {
     if (Kohana::$_init) {
         // Do not allow execution twice
         return;
     }
     // Kohana is now initialized
     Kohana::$_init = TRUE;
     if (isset($settings['profile'])) {
         // Enable profiling
         Kohana::$profiling = (bool) $settings['profile'];
     }
     // Start an output buffer
     ob_start();
     if (isset($settings['errors'])) {
         // Enable error handling
         Kohana::$errors = (bool) $settings['errors'];
     }
     if (Kohana::$errors === TRUE) {
         // Enable Kohana exception handling, adds stack traces and error source.
         set_exception_handler(array('Kohana_Exception', 'handler'));
         // Enable Kohana error handling, converts all PHP errors to exceptions.
         set_error_handler(array('Kohana', 'error_handler'));
     }
     /**
      * Enable xdebug parameter collection in development mode to improve fatal stack traces.
      */
     if (Kohana::$environment == Kohana::DEVELOPMENT and extension_loaded('xdebug')) {
         ini_set('xdebug.collect_params', 3);
     }
     // Enable the Kohana shutdown handler, which catches E_FATAL errors.
     register_shutdown_function(array('Kohana', 'shutdown_handler'));
     if (ini_get('register_globals')) {
         // Reverse the effects of register_globals
         Kohana::globals();
     }
     if (isset($settings['expose'])) {
         Kohana::$expose = (bool) $settings['expose'];
     }
     // Determine if we are running in a Windows environment
     Kohana::$is_windows = DIRECTORY_SEPARATOR === '\\';
     // Determine if we are running in safe mode
     Kohana::$safe_mode = (bool) ini_get('safe_mode');
     if (isset($settings['cache_dir'])) {
         if (!is_dir($settings['cache_dir'])) {
             try {
                 // Create the cache directory
                 mkdir($settings['cache_dir'], 0755, TRUE);
                 // Set permissions (must be manually set to fix umask issues)
                 chmod($settings['cache_dir'], 0755);
             } catch (Exception $e) {
                 throw new Kohana_Exception('Could not create cache directory :dir', array(':dir' => Debug::path($settings['cache_dir'])));
             }
         }
         // Set the cache directory path
         Kohana::$cache_dir = realpath($settings['cache_dir']);
     } else {
         // Use the default cache directory
         Kohana::$cache_dir = APPPATH . 'cache';
     }
     if (!is_writable(Kohana::$cache_dir)) {
         throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Debug::path(Kohana::$cache_dir)));
     }
     if (isset($settings['cache_life'])) {
         // Set the default cache lifetime
         Kohana::$cache_life = (int) $settings['cache_life'];
     }
     if (isset($settings['caching'])) {
         // Enable or disable internal caching
         Kohana::$caching = (bool) $settings['caching'];
     }
     if (Kohana::$caching === TRUE) {
         // Load the file path cache
         Kohana::$_files = Kohana::cache('Kohana::find_file()');
     }
     if (isset($settings['charset'])) {
         // Set the system character set
         Kohana::$charset = strtolower($settings['charset']);
     }
     if (function_exists('mb_internal_encoding')) {
         // Set the MB extension encoding to the same character set
         mb_internal_encoding(Kohana::$charset);
     }
     if (isset($settings['base_url'])) {
         // Set the base URL
         Kohana::$base_url = rtrim($settings['base_url'], '/') . '/';
     }
     if (isset($settings['index_file'])) {
         // Set the index file
         Kohana::$index_file = trim($settings['index_file'], '/');
     }
     // Determine if the extremely evil magic quotes are enabled
     Kohana::$magic_quotes = (bool) get_magic_quotes_gpc();
     // Sanitize all request variables
     $_GET = Kohana::sanitize($_GET);
     $_POST = Kohana::sanitize($_POST);
     $_COOKIE = Kohana::sanitize($_COOKIE);
     // Load the logger if one doesn't already exist
     if (!Kohana::$log instanceof Log) {
         Kohana::$log = Log::instance();
     }
     // Load the config if one doesn't already exist
     if (!Kohana::$config instanceof Config) {
         Kohana::$config = new Config();
     }
 }
示例#3
0
/**
 * Attach the file write to logging. Multiple writers are supported.
 */
Kohana::$log->attach(new Log_File(APPPATH . 'logs'));
/**
 * Attach a file reader to config. Multiple readers are supported.
 */
Kohana::$config->attach(new Config_File());
/**
 * Enable modules. Modules are referenced by a relative or absolute path.
 */
Kohana::modules(array('cache' => MODPATH . 'cache', 'database' => MODPATH . 'database', 'image' => MODPATH . 'image', 'orm' => MODPATH . 'orm', 'paypal' => MODPATH . 'paypal', 'kandler' => MODPATH . 'kandler', 'email' => MODPATH . 'email', 'pagination' => MODPATH . 'pagination', 'sitemap' => MODPATH . 'sitemap', 'amazon' => MODPATH . 'amazon'));
/**
 * Cache
 */
Kohana::$caching = TRUE;
Cache::$default = 'apc';
/**
 * Set the routes. Each route must have a minimum of a name, a URI and a set of
 * defaults for the URI.
 */
// Default route
Route::set('default', '(<controller>(/<action>(/<id>)))')->defaults(array('controller' => 'ads', 'action' => 'home'));
// Error route
Route::set('error', 'error/<action>(/<message>)', array('action' => '[0-9]++', 'message' => '.+'))->defaults(array('controller' => 'error_handler'));
/**
 * Cookie configuration settings
 */
Cookie::$salt = 'ASJ12094X:F?!*!*AD';
Cookie::$expiration = Date::MONTH;
Cookie::$httponly = TRUE;
示例#4
0
 /**
  * Initializes the environment:
  *
  * - Disables register_globals and magic_quotes_gpc
  * - Determines the current environment
  * - Set global settings
  * - Sanitizes GET, POST, and COOKIE variables
  * - Converts GET, POST, and COOKIE variables to the global character set
  *
  * Any of the global settings can be set here:
  *
  * Type      | Setting    | Description                                    | Default Value
  * ----------|------------|------------------------------------------------|---------------
  * `boolean` | errors     | use internal error and exception handling?     | `TRUE`
  * `boolean` | profile    | do internal benchmarking?                      | `TRUE`
  * `boolean` | caching    | cache the location of files between requests?  | `FALSE`
  * `string`  | charset    | character set used for all input and output    | `"utf-8"`
  * `string`  | base_url   | set the base URL for the application           | `"/"`
  * `string`  | index_file | set the index.php file name                    | `"index.php"`
  * `string`  | cache_dir  | set the cache directory path                   | `APPPATH."cache"`
  *
  * @throws  Kohana_Exception
  * @param   array   global settings
  * @return  void
  */
 public static function init(array $settings = NULL)
 {
     if (Kohana::$_init) {
         // Do not allow execution twice
         return;
     }
     // Kohana is now initialized
     Kohana::$_init = TRUE;
     if (isset($settings['profile'])) {
         // Enable profiling
         Kohana::$profiling = (bool) $settings['profile'];
     }
     if (Kohana::$profiling === TRUE) {
         // Start a new benchmark
         $benchmark = Profiler::start('Kohana', __FUNCTION__);
     }
     // Start an output buffer
     ob_start();
     if (defined('E_DEPRECATED')) {
         // E_DEPRECATED only exists in PHP >= 5.3.0
         Kohana::$php_errors[E_DEPRECATED] = 'Deprecated';
     }
     if (isset($settings['errors'])) {
         // Enable error handling
         Kohana::$errors = (bool) $settings['errors'];
     }
     if (Kohana::$errors === TRUE) {
         // Enable Kohana exception handling, adds stack traces and error source.
         set_exception_handler(array('Kohana', 'exception_handler'));
         // Enable Kohana error handling, converts all PHP errors to exceptions.
         set_error_handler(array('Kohana', 'error_handler'));
     }
     // Enable the Kohana shutdown handler, which catches E_FATAL errors.
     register_shutdown_function(array('Kohana', 'shutdown_handler'));
     if (ini_get('register_globals')) {
         if (isset($_REQUEST['GLOBALS']) or isset($_FILES['GLOBALS'])) {
             // Prevent malicious GLOBALS overload attack
             echo "Global variable overload attack detected! Request aborted.\n";
             // Exit with an error status
             exit(1);
         }
         // Get the variable names of all globals
         $global_variables = array_keys($GLOBALS);
         // Remove the standard global variables from the list
         $global_variables = array_diff($global_variables, array('GLOBALS', '_REQUEST', '_GET', '_POST', '_FILES', '_COOKIE', '_SERVER', '_ENV', '_SESSION'));
         foreach ($global_variables as $name) {
             // Retrieve the global variable and make it null
             global ${$name};
             ${$name} = NULL;
             // Unset the global variable, effectively disabling register_globals
             unset($GLOBALS[$name], ${$name});
         }
     }
     // Determine if we are running in a command line environment
     Kohana::$is_cli = PHP_SAPI === 'cli';
     // Determine if we are running in a Windows environment
     Kohana::$is_windows = DIRECTORY_SEPARATOR === '\\';
     if (isset($settings['cache_dir'])) {
         // Set the cache directory path
         Kohana::$cache_dir = realpath($settings['cache_dir']);
     } else {
         // Use the default cache directory
         Kohana::$cache_dir = APPPATH . 'cache';
     }
     if (!is_writable(Kohana::$cache_dir)) {
         throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Kohana::debug_path(Kohana::$cache_dir)));
     }
     if (isset($settings['caching'])) {
         // Enable or disable internal caching
         Kohana::$caching = (bool) $settings['caching'];
     }
     if (Kohana::$caching === TRUE) {
         // Load the file path cache
         Kohana::$_files = Kohana::cache('Kohana::find_file()');
     }
     if (isset($settings['charset'])) {
         // Set the system character set
         Kohana::$charset = strtolower($settings['charset']);
     }
     if (isset($settings['base_url'])) {
         // Set the base URL
         Kohana::$base_url = rtrim($settings['base_url'], '/') . '/';
     }
     if (isset($settings['index_file'])) {
         // Set the index file
         Kohana::$index_file = trim($settings['index_file'], '/');
     }
     // Determine if the extremely evil magic quotes are enabled
     Kohana::$magic_quotes = (bool) get_magic_quotes_gpc();
     // Sanitize all request variables
     $_GET = Kohana::sanitize($_GET);
     $_POST = Kohana::sanitize($_POST);
     $_COOKIE = Kohana::sanitize($_COOKIE);
     // Load the logger
     Kohana::$log = Kohana_Log::instance();
     // Load the config
     Kohana::$config = Kohana_Config::instance();
     if (isset($benchmark)) {
         // Stop benchmarking
         Profiler::stop($benchmark);
     }
 }
示例#5
0
    define('PUBLIC_URL', BASE_URL . 'public/');
}
if (!defined('PLUGINS_URL')) {
    define('PLUGINS_URL', BASE_URL . 'cms/plugins/');
}
if (!defined('IS_BACKEND')) {
    define('IS_BACKEND', FALSE);
}
/**
 * Set the default cookie salt
 */
Cookie::$salt = 'install_system';
/**
 * Disable kohana caching
 */
Kohana::$caching = FALSE;
/**
 * Enable modules. Modules are referenced by a relative or absolute path.
 */
Kohana::modules(array('api' => MODPATH . 'api', 'users' => MODPATH . 'users', 'kodicms' => MODPATH . 'kodicms', 'assets' => MODPATH . 'assets', 'cache' => MODPATH . 'cache', 'database' => MODPATH . 'database', 'auth' => MODPATH . 'auth', 'orm' => MODPATH . 'orm', 'minion' => MODPATH . 'minion', 'filesystem' => MODPATH . 'filesystem', 'breadcrumbs' => MODPATH . 'breadcrumbs', 'widget' => MODPATH . 'widget', 'email' => MODPATH . 'email', 'plugins' => MODPATH . 'plugins', 'installer' => MODPATH . 'installer'));
Observer::notify('modules::after_load');
/**
 * Проверка на существование модуля `installer`
 */
if (array_key_exists('installer', Kohana::modules()) === FALSE) {
    throw HTTP_Exception::factory(404, __('System not installed. Installer not found.'));
}
if (PHP_SAPI != 'cli') {
    if (!URL::match('install', Request::detect_uri()) and !URL::match('cms/media/', Request::detect_uri())) {
        $uri = Route::get('install')->uri();
    }
示例#6
0
 /**
  * Initializes the environment:
  *
  * - Disables register_globals and magic_quotes_gpc
  * - Determines the current environment
  * - Set global settings
  * - Sanitizes GET, POST, and COOKIE variables
  * - Converts GET, POST, and COOKIE variables to the global character set
  *
  * The following settings can be set:
  *
  * Type      | Setting    | Description                                    | Default Value
  * ----------|------------|------------------------------------------------|---------------
  * `string`  | base_url   | The base URL for your application.  This should be the *relative* path from your DOCROOT to your `index.php` file, in other words, if Kohana is in a subfolder, set this to the subfolder name, otherwise leave it as the default.  **The leading slash is required**, trailing slash is optional.   | `"/"`
  * `string`  | index_file | The name of the [front controller](http://en.wikipedia.org/wiki/Front_Controller_pattern).  This is used by Kohana to generate relative urls like [HTML::anchor()] and [URL::base()]. This is usually `index.php`.  To [remove index.php from your urls](tutorials/clean-urls), set this to `FALSE`. | `"index.php"`
  * `string`  | charset    | Character set used for all input and output    | `"utf-8"`
  * `string`  | cache_dir  | Kohana's cache directory.  Used by [Kohana::cache] for simple internal caching, like [Fragments](kohana/fragments) and **\[caching database queries](this should link somewhere)**.  This has nothing to do with the [Cache module](cache). | `APPPATH."cache"`
  * `integer` | cache_life | Lifetime, in seconds, of items cached by [Kohana::cache]         | `60`
  * `boolean` | errors     | Should Kohana catch PHP errors and uncaught Exceptions and show the `error_view`. See [Error Handling](kohana/errors) for more info. <br /> <br /> Recommended setting: `TRUE` while developing, `FALSE` on production servers. | `TRUE`
  * `boolean` | profile    | Whether to enable the [Profiler](kohana/profiling). <br /> <br />Recommended setting: `TRUE` while developing, `FALSE` on production servers. | `TRUE`
  * `boolean` | caching    | Cache file locations to speed up [Kohana::find_file].  This has nothing to do with [Kohana::cache], [Fragments](kohana/fragments) or the [Cache module](cache).  <br /> <br />  Recommended setting: `FALSE` while developing, `TRUE` on production servers. | `FALSE`
  * `boolean` | expose     | Set the X-Powered-By header
  *
  * @throws  Gleez_Exception
  * @param   array   $settings   Array of settings.  See above.
  * @return  void
  *
  * @uses    Kohana::globals
  * @uses    Kohana::sanitize
  * @uses    Kohana::cache
  * @uses    Profiler
  * @uses    System::mkdir
  */
 public static function init(array $settings = NULL)
 {
     if (Kohana::$_init) {
         // Do not allow execution twice
         return;
     }
     // Kohana is now initialized
     Kohana::$_init = TRUE;
     if (isset($settings['profile'])) {
         // Enable profiling
         Kohana::$profiling = (bool) $settings['profile'];
     }
     // Start an output buffer
     ob_start();
     if (isset($settings['errors'])) {
         // Enable error handling
         Kohana::$errors = (bool) $settings['errors'];
     }
     if (Kohana::$errors === TRUE) {
         // Enable Gleez exception handling, adds stack traces and error source.
         set_exception_handler(array('Gleez_Exception', 'handler'));
         // Enable Kohana error handling, converts all PHP errors to exceptions.
         set_error_handler(array('Kohana', 'error_handler'));
     }
     if (isset($settings['autolocale'])) {
         // Manual enable Gleez_Locale
         Kohana::$autolocale = (bool) $settings['autolocale'];
     }
     // Enable the Kohana shutdown handler, which catches E_FATAL errors.
     register_shutdown_function(array('Kohana', 'shutdown_handler'));
     if (ini_get('register_globals')) {
         // Reverse the effects of register_globals
         Kohana::globals();
     }
     if (isset($settings['expose'])) {
         Kohana::$expose = (bool) $settings['expose'];
     }
     // Determine if we are running in a command line environment
     Kohana::$is_cli = PHP_SAPI === 'cli';
     // Determine if we are running in a Windows environment
     Kohana::$is_windows = DS === '\\';
     // Determine if we are running in safe mode
     Kohana::$safe_mode = (bool) ini_get('safe_mode');
     if (isset($settings['cache_dir'])) {
         if (!is_dir($settings['cache_dir'])) {
             try {
                 // Create the cache directory
                 System::mkdir($settings['cache_dir']);
             } catch (Exception $e) {
                 throw new Gleez_Exception('Could not create cache directory :dir', array(':dir' => Debug::path($settings['cache_dir'])));
             }
         }
         // Set the cache directory path
         Kohana::$cache_dir = realpath($settings['cache_dir']);
     } else {
         // Use the default cache directory
         Kohana::$cache_dir = APPPATH . 'cache';
     }
     if (!is_dir(Kohana::$cache_dir)) {
         try {
             System::mkdir(Kohana::$cache_dir);
         } catch (Exception $e) {
             throw new Gleez_Exception('Could not create cache directory :dir', array(':dir' => Debug::path(Kohana::$cache_dir)));
         }
     }
     if (!is_writable(Kohana::$cache_dir)) {
         throw new Gleez_Exception('Directory :dir must be writable', array(':dir' => Debug::path(Kohana::$cache_dir)));
     }
     if (isset($settings['cache_life'])) {
         // Set the default cache lifetime
         Kohana::$cache_life = (int) $settings['cache_life'];
     }
     if (isset($settings['caching'])) {
         // Enable or disable internal caching
         Kohana::$caching = (bool) $settings['caching'];
     }
     if (Kohana::$caching === TRUE) {
         // Load the file path cache
         Kohana::$_files = Kohana::cache('Kohana::find_file()');
     }
     if (isset($settings['charset'])) {
         // Set the system character set
         Kohana::$charset = strtolower($settings['charset']);
     }
     if (function_exists('mb_internal_encoding')) {
         // Set the MB extension encoding to the same character set
         mb_internal_encoding(Kohana::$charset);
     }
     if (isset($settings['base_url'])) {
         // Set the base URL
         Kohana::$base_url = rtrim($settings['base_url'], '/') . '/';
     }
     if (isset($settings['index_file'])) {
         // Set the index file
         Kohana::$index_file = trim($settings['index_file'], '/');
     }
     // Determine if the extremely evil magic quotes are enabled
     Kohana::$magic_quotes = (bool) get_magic_quotes_gpc();
     // Sanitize all request variables
     $_GET = Kohana::sanitize($_GET);
     $_POST = Kohana::sanitize($_POST);
     $_COOKIE = Kohana::sanitize($_COOKIE);
     // Load the logger object
     Kohana::$log = Log::instance();
     // Load the config object
     Kohana::$config = new Config();
 }
<?php

error_reporting(E_ALL ^ E_NOTICE);
require_once __DIR__ . '/../vendor/autoload.php';
Kohana::$caching = false;
$_SERVER['HTTP_HOST'] = 'localhost';
Kohana::modules(['test-module' => __DIR__ . '/module']);
Kohana::$environment = Kohana::TESTING;
示例#8
0
 /**
  * Searches for a file in the [Cascading Filesystem](kohana/files), and
  * returns the path to the file that has the highest precedence, so that it
  * can be included.
  *
  * When searching the "config", "messages", or "i18n" directories, or when
  * the `$array` flag is set to true, an array of all the files that match
  * that path in the [Cascading Filesystem](kohana/files) will be returned.
  * These files will return arrays which must be merged together.
  *
  * If no extension is given, the default extension (`EXT` set in
  * `index.php`) will be used.
  *
  *     // Returns an absolute path to views/template.php
  *     Kohana::find_file('views', 'template');
  *
  *     // Returns an absolute path to media/css/style.css
  *     Kohana::find_file('media', 'css/style', 'css');
  *
  *     // Returns an array of all the "mimes" configuration files
  *     Kohana::find_file('config', 'mimes');
  *
  * @param   string   directory name (views, i18n, classes, extensions, etc.)
  * @param   string   filename with subdirectory
  * @param   string   extension to search for
  * @param   boolean  return an array of files?
  * @return  array    a list of files when $array is TRUE
  * @return  string   single file path
  */
 public static function find_file($dir, $file, $ext = NULL, $array = FALSE)
 {
     if ($ext === NULL) {
         // Use the default extension
         $ext = EXT;
     } elseif ($ext) {
         // Prefix the extension with a period
         $ext = ".{$ext}";
     } else {
         // Use no extension
         $ext = '';
     }
     // Create a partial path of the filename
     $path = $dir . DIRECTORY_SEPARATOR . $file . $ext;
     /* Hack */
     Kohana::$caching = TRUE;
     if (Kohana::$caching === TRUE and isset(Kohana::$_files[$path . ($array ? '_array' : '_path')])) {
         // This path has been cached
         return Kohana::$_files[$path . ($array ? '_array' : '_path')];
     }
     if (Kohana::$profiling === TRUE and class_exists('Profiler', FALSE)) {
         // Start a new benchmark
         $benchmark = Profiler::start('Kohana', __FUNCTION__);
     }
     if ($array or $dir === 'config' or $dir === 'i18n' or $dir === 'messages') {
         // Include paths must be searched in reverse
         $paths = array_reverse(Kohana::$_paths);
         // Array of files that have been found
         $found = array();
         foreach ($paths as $dir) {
             if (is_file($dir . $path)) {
                 // This path has a file, add it to the list
                 $found[] = $dir . $path;
             }
         }
     } else {
         // The file has not been found yet
         $found = FALSE;
         foreach (Kohana::$_paths as $dir) {
             if (is_file($dir . $path)) {
                 // A path has been found
                 $found = $dir . $path;
                 // Stop searching
                 break;
             }
         }
     }
     if (Kohana::$caching === TRUE) {
         // Add the path to the cache
         Kohana::$_files[$path . ($array ? '_array' : '_path')] = $found;
         // Files have been changed
         Kohana::$_files_changed = TRUE;
     }
     if (isset($benchmark)) {
         // Stop the benchmark
         Profiler::stop($benchmark);
     }
     return $found;
 }