Changeset 1249

Show
Ignore:
Timestamp:
11/23/2007 04:14:42 PM (11 months ago)
Author:
Shadowhand
Message:

Small changes to core:

  • Optimized Kohana::instance(), avoiding a call_user_func_array, which is extremely slow (woot PHP!)
  • Fixed the "private" controller method prefixing (using "_" should prevent the method from being called via the URL)
  • Moved Controller::kohana_include_view() to Controller::_kohana_load_view(), for consistency
  • Updated View::render() to use the renamed Controller method
  • Small logic fix in Encrypt
Location:
trunk/system
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/core/Event.php

    r1230 r1249  
    260260        public static function run($name, & $data = NULL) 
    261261        { 
    262                 if ($name == FALSE) 
     262                if ($name == FALSE OR empty(self::$events[$name])) 
    263263                        return FALSE; 
    264264 
  • trunk/system/core/Kohana.php

    r1230 r1249  
    186186                                Router::$method = '_remap'; 
    187187                        } 
    188                         elseif (isset($methods[Router::$method]) AND Router::$method != 'kohana_include_view') 
    189                         { 
    190                                 /** 
    191                                  * Do nothing. Exciting! Honestly, I am surprised having only 
    192                                  * a comment here works. 
    193                                  */ 
     188                        elseif (isset($methods[Router::$method]) AND substr(Router::$method, 0, 1) != '_') 
     189                        { 
     190                                // A valid route has been found, and nothing needs to be done. 
     191                                // Amazing that having nothing inside the statment still works. 
    194192                        } 
    195193                        elseif (method_exists($controller, '_default')) 
     
    217215                        ); 
    218216 
    219                         // Call the controller method 
    220                         if (is_array(Router::$arguments) AND ! empty(Router::$arguments)) 
    221                         { 
    222                                 call_user_func_array(array($controller, Router::$method), Router::$arguments); 
     217                        // Run system.post_controller_constructor 
     218                        Event::run('system.post_controller_constructor'); 
     219 
     220                        // Controller method name, used for calling 
     221                        $method = Router::$method; 
     222 
     223                        if (empty(Router::$arguments)) 
     224                        { 
     225                                // Call the controller method with no arguments 
     226                                $controller->$method(); 
    223227                        } 
    224228                        else 
    225229                        { 
    226                                 call_user_func(array($controller, Router::$method)); 
    227                         } 
    228  
    229                         // Run system.pre_controller 
     230                                // Manually call the controller for up to 4 arguments. Why? Because 
     231                                // call_user_func_array is ~3 times slower than direct method calls. 
     232                                switch(count(Router::$arguments)) 
     233                                { 
     234                                        case 1: 
     235                                                $controller->$method(Router::$arguments[0]); 
     236                                        break; 
     237                                        case 2: 
     238                                                $controller->$method(Router::$arguments[0], Router::$arguments[1]); 
     239                                        break; 
     240                                        case 3: 
     241                                                $controller->$method(Router::$arguments[0], Router::$arguments[1], Router::$arguments[2]); 
     242                                        break; 
     243                                        case 4: 
     244                                                $controller->$method(Router::$arguments[0], Router::$arguments[1], Router::$arguments[2], Router::$arguments[3]); 
     245                                        break; 
     246                                        default: 
     247                                                // Resort to using call_user_func_array for many segments 
     248                                                call_user_func_array(array($controller, $method), Router::$arguments); 
     249                                        break; 
     250                                } 
     251                        } 
     252 
     253                        // Run system.post_controller 
    230254                        Event::run('system.post_controller'); 
    231255                } 
     
    467491                        case 'Controller': 
    468492                                $type = 'controllers'; 
    469                                 $file = substr($class, 0, -11); 
     493                                // Lowercase filename 
     494                                $file = strtolower(substr($class, 0, -11)); 
    470495                        break; 
    471496                        case 'Model': 
    472497                                $type = 'models'; 
    473                                 $file = substr($class, 0, -6); 
    474                                 // Models are always lowercase 
    475                                 $file = strtolower($file); 
     498                                // Lowercase filename 
     499                                $file = strtolower(substr($class, 0, -6)); 
    476500                        break; 
    477501                        case 'Driver': 
     
    488512                } 
    489513 
     514                // Load the requested file 
    490515                require_once self::find_file($type, $file, TRUE); 
    491516 
     
    525550 
    526551                $search = $directory.'/'.$filename; 
    527                 $hash   = md5($search); 
     552                $hash   = sha1($search); 
    528553 
    529554                if (isset($found[$hash])) 
  • trunk/system/libraries/Controller.php

    r1230 r1249  
    3030 
    3131        /** 
    32          * Method: kohana_include_view 
    33          *  Includes a View within the controller scope. 
     32         * Includes a View within the controller scope. 
    3433         * 
    3534         * Parameters: 
     
    4039         *  Output of view file 
    4140         */ 
    42         public function kohana_include_view($kohana_view_filename, $kohana_input_data) 
     41        public function _kohana_load_view($kohana_view_filename, $kohana_input_data) 
    4342        { 
    4443                if ($kohana_view_filename == '') 
  • trunk/system/libraries/Encrypt.php

    r1230 r1249  
    4040 
    4141                // Different random seeds must be used for Windows and UNIX 
    42                 $rand = (strpos(PHP_OS, 'WIN') !== FALSE) ? MCRYPT_RAND : MCRYPT_DEV_RANDOM; 
     42                $rand = (strpos(PHP_OS, 'WIN') === FALSE) ? MCRYPT_DEV_RANDOM : MCRYPT_RAND; 
    4343 
    4444                // Create an initialization vector 
  • trunk/system/libraries/View.php

    r1230 r1249  
    140140                { 
    141141                        // Load the view in the controller for access to $this 
    142                         $output = Kohana::instance()->kohana_include_view($this->kohana_filename, $this->data); 
     142                        $output = Kohana::instance()->_kohana_load_view($this->kohana_filename, $this->data); 
    143143 
    144144                        // Pass the output through the user defined renderer