Changeset 2249 for trunk/index.php

Show
Ignore:
Timestamp:
03/09/2008 03:09:43 PM (9 months ago)
Author:
Shadowhand
Message:

Changes to Kohana exception/error handling:

  • Added KOHANA_ERROR_CSS to index.php
  • Updated error pages to use new KOHANA_ERROR_CSS constant
  • Reflected changes in Kohana and i18n/core.php
  • Kohana::exeception_handler will no longer include the backtrace when IN_PRODUCTION is enabled, for a small security benefit
  • Changed index.php directory checks to only execute when IN_PRODUCTION is enabled, for a small performance benefit
  • Small cleanups in index.php comments
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r2242 r2249  
    55 * PHP error_reporting level may also be changed. 
    66 * 
    7  * @package    Core 
    8  * @author     Kohana Team 
    9  * @copyright  (c) 2007-2008 Kohana Team 
    10  * @license    http://kohanaphp.com/license.html 
     7 * @see http://kohanaphp.com 
    118 */ 
    129 
     
    4542$kohana_system = 'system'; 
    4643 
     44/** 
     45 * Test to make sure that Kohana is running on PHP 5.2 or newer. Once you are 
     46 * sure that your environment is compatible with Kohana, you can comment this 
     47 * line out. When running an application on a new server, uncomment this line 
     48 * to check the PHP version quickly. 
     49 */ 
     50version_compare(PHP_VERSION, '5.2', '<') and exit('Kohana requires PHP 5.2 or newer.'); 
    4751 
    4852/** 
     
    5963 
    6064/** 
     65 * Define the Kohana-generated error message style. 
     66 */ 
     67define('KOHANA_ERROR_CSS', 
     68        // Any of these styles can be changed to affect all error messages. 
     69        'div#kohana_error { background: #fff; border:solid 1px #ccc; font-family:sans-serif; color:#111; font-size: 14px; line-height: 130%; vertical-align: baseline; }'. 
     70        'div#kohana_error h3 { color:#fff; font-size:16px; padding:8px 6px; margin:0 0 8px; background: #f15a00; text-align: center; }'. 
     71        'div#kohana_error a { color:#228; text-decoration:none; }'. 
     72        'div#kohana_error a:hover { text-decoration:underline; }'. 
     73        'div#kohana_error strong { color:#900; }'. 
     74        'div#kohana_error p { margin:0; padding:4px 6px 10px; }'. 
     75        'div#kohana_error tt,'. 
     76        'div#kohana_error pre,'. 
     77        'div#kohana_error code { font-family:monospace; padding:2px 4px; white-space:pre; font-size:12px; color:#333; }'. 
     78        'div#kohana_error tt { font-style:italic; }'. 
     79        'div#kohana_error tt:before { content:">"; color:#aaa; }'. 
     80        'div#kohana_error code tt:before { content:""; }'. 
     81        'div#kohana_error pre,'. 
     82        'div#kohana_error code { background:#eaeee5; border:solid 0 #D6D8D1; border-width:0 1px 1px 0; }'. 
     83        'div#kohana_error .block { display:block; text-align:left; }'. 
     84        'div#kohana_error .stats { padding: 4px; background: #eee; border-top:solid 1px #ccc; text-align:center; font-size:10px; color: #888; }'. 
     85        'div#kohana_error .backtrace { margin:0; padding:0 6px; list-style:none; line-height:12px; }' 
     86); 
     87 
     88/** 
    6189 * If you rename all of your .php files to a different extension, set the new 
    6290 * extension here. This option can left to .php, even if this file is has a 
     
    6492 */ 
    6593define('EXT', '.php'); 
    66  
    67 /** 
    68  * Test to make sure that Kohana is running on PHP 5.2 or newer. Once you are 
    69  * sure that your environment is compatible with Kohana, you can disable this. 
    70  */ 
    71 version_compare(PHP_VERSION, '5.2', '<') and exit('Kohana requires PHP 5.2 or newer.'); 
    7294 
    7395// 
     
    92114unset($kohana_application, $kohana_modules, $kohana_system); 
    93115 
    94 (is_dir(APPPATH) AND is_dir(APPPATH.'/config')) or die 
    95 ( 
    96         'Your <code>$kohana_application</code> directory does not exist. '. 
    97         'Set a valid <code>$kohana_application</code> in <tt>'.KOHANA.'</tt> and refresh the page.' 
    98 ); 
     116if ( ! IN_PRODUCTION) 
     117{ 
     118        // Check APPPATH 
     119        if ( ! (is_dir(APPPATH) AND file_exists(APPPATH.'/config/config'.EXT))) 
     120        { 
     121                die 
     122                ( 
     123                        '<style type="text/css">'.KOHANA_ERROR_CSS.'</style>'. 
     124                        '<div id="kohana_error" style="width:26em;margin:50px auto;text-align:center;">'. 
     125                                '<h3>Application Directory Not Found</h3>'. 
     126                                '<p>The <code>$kohana_application</code> directory does not exist.</p>'. 
     127                                '<p>Set <code>$kohana_application</code> in <tt>'.KOHANA.'</tt> to a valid directory and refresh the page.</p>'. 
     128                        '</div>' 
     129                ); 
     130        } 
    99131 
    100 (is_dir(SYSPATH) AND file_exists(SYSPATH.'/core/'.'Bootstrap'.EXT)) or die 
    101 ( 
    102         'Your <code>$kohana_system</code> directory does not exist. '. 
    103         'Set a valid <code>$kohana_system</code> in <tt>'.KOHANA.'</tt> and refresh the page.' 
    104 ); 
     132        // Check SYSPATH 
     133        if ( ! (is_dir(SYSPATH) AND file_exists(SYSPATH.'/core/Bootstrap'.EXT))) 
     134        { 
     135                die 
     136                ( 
     137                        '<style type="text/css">'.KOHANA_ERROR_CSS.'</style>'. 
     138                        '<div id="kohana_error" style="width:26em;margin:50px auto;text-align:center;">'. 
     139                                '<h3>System Directory Not Found</h3>'. 
     140                                '<p>The <code>$kohana_system</code> directory does not exist.</p>'. 
     141                                '<p>Set <code>$kohana_system</code> in <tt>'.KOHANA.'</tt> to a valid directory and refresh the page.</p>'. 
     142                        '</div>' 
     143                ); 
     144        } 
     145} 
    105146 
     147// Initialize. 
    106148require SYSPATH.'core/Bootstrap'.EXT;