Changeset 1250

Show
Ignore:
Timestamp:
11/23/2007 05:10:56 PM (11 months ago)
Author:
Shadowhand
Message:

More changes to core:

  • Added a kohana_loading benchmark, for timing loading the core files
  • Split controller_execution benchmark into controller_setup and controller_execution
  • Created a new core config option, enable_utf8, to enable utf8 support to be turned off
  • Modified other core libraries and helpers to be aware of utf8 being disabled
Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/config/config.php

    r1230 r1250  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    22/** 
    3  * File: config.php 
    4  *  This configuration file is unique to every application. 
     3 * Site-specific application configuration is done here. This configuration file 
     4 * does not extend any other configuration file. All of the items here are prefixed 
     5 * with "core", eg: core.index_page would fetch the index_page variable from the 
     6 * configuration array. 
    57 * 
    68 * Options: 
     
    911 *  index_page           - name of the front controller, can be removed with URL rewriting 
    1012 *  url_suffix           - an extension that will be added to all generated URLs 
     13 *  enable_utf8          - enable or disable internal utf8 support 
     14 *  global_xss_filtering - enable or disable XSS attack filtering on all user input 
    1115 *  allow_config_set     - enable or disable setting of Config items 
    12  *  global_xss_filtering - enable or disable XSS attack filtering on all user input 
    1316 *  extension_prefix     - filename prefix for library extensions 
    14  *  include_paths        - extra Kohana resource paths, see <Kohana.find_file> 
     17 *  include_paths        - "module" support, additional resource paths that will be searched 
    1518 *  autoload             - libraries and models to be loaded with the controller 
    1619 */ 
     
    2124        'index_page'           => 'index.php', 
    2225        'url_suffix'           => '', 
    23         'allow_config_set'     => TRUE, 
     26        'enable_utf8'          => TRUE, 
    2427        'global_xss_filtering' => FALSE, 
     28        'allow_config_set'     => FALSE, 
    2529        'extension_prefix'     => 'MY_', 
    2630        'include_paths'        => array 
    2731        ( 
    28                 // 'modules/auth', 
    29                 // 'modules/ikeafans', 
    30                 // 'modules/user_guide', 
    31                 // 'modules/orm', 
    32                 'modules/kodoc', 
    33                 // 'modules/mixnotify' 
     32                // To enable the demo module, uncomment the following line 
     33                // 'modules/demo', 
    3434        ), 
    3535        'autoload'             => array 
     
    3737                'libraries' => '', 
    3838                'models'    => '' 
    39         ) 
     39        ), 
    4040); 
  • trunk/system/core/Benchmark.php

    r1230 r1250  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    22/** 
     3 * Kohana 
     4 * 
     5 * copyright - (c) 2007 Kohana Team 
     6 * license   - <http://kohanaphp.com/license.html> 
     7 * revision  - $Id$ 
     8 */ 
     9 
     10/** 
    311 * Simple benchmarking. 
    4  * 
    5  * Kohana Source Code: 
    6  *  author    - Kohana Team 
    7  *  copyright - (c) 2007 Kohana Team 
    8  *  license   - <http://kohanaphp.com/license.html> 
    912 */ 
    1013final class Benchmark { 
  • trunk/system/core/Bootstrap.php

    r1230 r1250  
    1818Benchmark::start(SYSTEM_BENCHMARK.'_total_execution_time'); 
    1919 
    20 Benchmark::start(SYSTEM_BENCHMARK.'_environment_setup'); 
    21 require SYSPATH.'core/utf8'.EXT; 
     20Benchmark::start(SYSTEM_BENCHMARK.'_kohana_loading'); 
    2221require SYSPATH.'core/Config'.EXT; 
    2322require SYSPATH.'core/Log'.EXT; 
    2423require SYSPATH.'core/Event'.EXT; 
    2524require SYSPATH.'core/Kohana'.EXT; 
     25Benchmark::stop(SYSTEM_BENCHMARK.'_kohana_loading'); 
    2626 
    2727Event::run('system.setup'); 
    28 Benchmark::stop(SYSTEM_BENCHMARK.'_environment_setup'); 
    2928 
    3029Benchmark::start(SYSTEM_BENCHMARK.'_system_initialization'); 
     
    3332Benchmark::stop(SYSTEM_BENCHMARK.'_system_initialization'); 
    3433 
    35 Benchmark::start(SYSTEM_BENCHMARK.'_controller_execution'); 
    3634Event::run('system.execute'); 
    37 Benchmark::stop(SYSTEM_BENCHMARK.'_controller_execution'); 
    3835 
    3936Event::run('system.shutdown'); 
  • trunk/system/core/Kohana.php

    r1249 r1250  
    8383                        return; 
    8484 
     85                // Start the environment setup benchmark 
     86                Benchmark::start(SYSTEM_BENCHMARK.'_environment_setup'); 
     87 
    8588                if (function_exists('date_default_timezone_set')) 
    8689                { 
     
    112115                set_magic_quotes_runtime(0); 
    113116 
     117                // Only include utf8 support if it's enabled 
     118                Config::item('core.enable_utf8') and require SYSPATH.'core/utf8'.EXT; 
     119 
    114120                // Send default text/html UTF-8 header 
    115121                header('Content-type: text/html; charset=UTF-8'); 
     
    154160                // Setup is complete, prevent it from being run again 
    155161                $run = TRUE; 
     162 
     163                // Stop the environment setup routine 
     164                Benchmark::start(SYSTEM_BENCHMARK.'_environment_setup'); 
    156165        } 
    157166 
     
    164173                if (self::$instance == FALSE) 
    165174                { 
     175                        Benchmark::start(SYSTEM_BENCHMARK.'_controller_setup'); 
     176 
    166177                        // Include the Controller file 
    167178                        require Router::$directory.Router::$controller.EXT; 
     
    217228                        // Run system.post_controller_constructor 
    218229                        Event::run('system.post_controller_constructor'); 
     230 
     231                        // Stop the controller setup benchmark 
     232                        Benchmark::stop(SYSTEM_BENCHMARK.'_controller_setup'); 
     233 
     234                        // Start the controller execution benchmark 
     235                        Benchmark::start(SYSTEM_BENCHMARK.'_controller_execution'); 
    219236 
    220237                        // Controller method name, used for calling 
     
    253270                        // Run system.post_controller 
    254271                        Event::run('system.post_controller'); 
     272 
     273                        Benchmark::stop(SYSTEM_BENCHMARK.'_controller_execution'); 
    255274                } 
    256275 
  • trunk/system/helpers/text.php

    r1230 r1250  
    5353         *  A character-limited string with the end character attached. 
    5454         */ 
    55         public static function limit_chars($str, $limit = 100, $end_char = '&#8230;', $preserve_words = FALSE) 
    56         { 
     55        public static function limit_chars($str, $limit = 100, $end_char = NULL, $preserve_words = FALSE) 
     56        { 
     57                $end_char = ($end_char === NULL) ? '&#8230;' : $end_char; 
     58 
    5759                $limit = (int) $limit; 
    5860 
    59                 if (trim($str) == '' OR utf8::strlen($str) <= $limit) 
     61                if (trim($str) == '' OR (class_exists('utf8', FALSE) AND utf8::strlen($str) <= $limit) OR strlen($str) <= $limit) 
    6062                        return $str; 
    6163 
     
    6365                        return $end_char; 
    6466 
    65                 if ( ! $preserve_words) 
    66                         return rtrim(utf8::substr($str, 0, $limit)).$end_char; 
     67                if ($preserve_words == FALSE) 
     68                { 
     69                        return rtrim(class_exists('utf8', FALSE) ? utf8::substr($str, 0, $limit) : substr($str, 0, $limit)).$end_char; 
     70                } 
    6771 
    6872                preg_match('/^.{'.($limit - 1).'}\S*/us', $str, $matches); 
  • trunk/system/helpers/url.php

    r1230 r1250  
    102102                $title = preg_replace('/[-_\s]+/', $separator, $title); 
    103103 
    104                 // Replace accented characters by their unaccented equivalents 
    105                 $title = utf8::transliterate_to_ascii($title); 
     104                if (class_exists('utf8', FALSE)) 
     105                { 
     106                        // Replace accented characters by their unaccented equivalents 
     107                        $title = utf8::transliterate_to_ascii($title); 
     108                } 
    106109 
    107110                // Remove all characters that are not a-z, 0-9, or the separator 
  • trunk/system/libraries/Router.php

    r1230 r1250  
    207207                                                list ($key, $val) = array_pad(explode('=', $pair), 1, ''); 
    208208 
    209                                                 $_GET[utf8::clean($key)] = utf8::clean($val); 
     209                                                if (class_exists('utf8', FALSE)) 
     210                                                { 
     211                                                        $_GET[utf8::clean($key)] = utf8::clean($val); 
     212                                                } 
     213                                                else 
     214                                                { 
     215                                                        $_GET[$key] = $val; 
     216                                                } 
    210217                                        } 
    211218                                } 
  • trunk/system/libraries/Validation.php

    r1230 r1250  
    773773                if (ctype_digit($val)) 
    774774                { 
    775                         if (utf8::strlen($str) >= $val) 
    776                                 return TRUE; 
     775                        if (class_exists('utf8', FALSE)) 
     776                        { 
     777                                if (utf8::strlen($str) >= $val) 
     778                                        return TRUE; 
     779                        } 
     780                        else 
     781                        { 
     782                                if (strlen($str) >= $val) 
     783                                        return TRUE; 
     784                        } 
    777785                } 
    778786 
     
    798806                if (ctype_digit($val)) 
    799807                { 
    800                         if (utf8::strlen($str) <= $val) 
    801                                 return TRUE; 
     808                        if (class_exists('utf8', FALSE)) 
     809                        { 
     810                                if (utf8::strlen($str) <= $val) 
     811                                        return TRUE; 
     812                        } 
     813                        else 
     814                        { 
     815                                if (strlen($str) <= $val) 
     816                                        return TRUE; 
     817                        } 
    802818                } 
    803819 
     
    823839                if (ctype_digit($val)) 
    824840                { 
    825                         if (utf8::strlen($str) == $val) 
    826                                 return TRUE; 
     841                        if (class_exists('utf8', FALSE)) 
     842                        { 
     843                                if (utf8::strlen($str) == $val) 
     844                                        return TRUE; 
     845                        } 
     846                        else 
     847                        { 
     848                                if (strlen($str) == $val) 
     849                                        return TRUE; 
     850                        } 
    827851                } 
    828852