Exemplo n.º 1
0
 public static function setup()
 {
     static $run;
     // This function can only be run once
     if ($run === TRUE) {
         return;
     }
     // Start the environment setup benchmark
     DEBUG == 1 && Benchmark::start(SYSTEM_BENCHMARK . '_environment_setup');
     // Enable Kohana controller initialization
     //Event::add('system.set_timezone', array('Lemon', 'set_timezone_default'));
     //Event::run('system.set_timezone');
     self::set_timezone_default();
     // web应用相关设定
     if (RUNTIME_UI == 'WEB') {
         // Set the user agent
         self::$user_agent = !empty($_SERVER['HTTP_USER_AGENT']) ? trim($_SERVER['HTTP_USER_AGENT']) : '';
         // Start output buffering
         ob_start(array(__CLASS__, 'output_buffer'));
         // Save buffering level
         self::$buffer_level = ob_get_level();
     }
     if (AUTOLOAD == 1) {
         // Set autoloader
         spl_autoload_register(array('Lemon', 'auto_load'));
     }
     // Enable Kohana routing
     if (RUNTIME_UI == 'WEB') {
         // Send default text/html UTF-8 header
         header('Content-Type: text/html; charset=UTF-8');
         Event::add('system.routing', array('Router', 'find_uri'));
         Event::add('system.routing', array('Router', 'setup'));
         // Enable Kohana 404 pages
         Event::add('system.404', array('Lemon', 'show_404'));
         // Enable Kohana controller initialization
         Event::add('system.execute', array('Lemon', 'instance'));
         // Enable Kohana output handling
         Event::add('system.shutdown', array('Lemon', 'shutdown'));
         if (self::config('core.enable_hooks') === TRUE) {
             // Find all the hook files
             $hooks = self::list_files('hooks', TRUE);
             foreach ($hooks as $file) {
                 // Load the hook
                 include $file;
             }
         }
     }
     // Setup is complete, prevent it from being run again
     $run = TRUE;
     // Stop the environment setup routine
     DEBUG == 1 && Benchmark::stop(SYSTEM_BENCHMARK . '_environment_setup');
 }