Changeset 3280

Show
Ignore:
Timestamp:
08/06/2008 11:10:31 AM (2 months ago)
Author:
Shadowhand
Message:

Fixing #722, thanks dlib!

Files:
1 modified

Legend:

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

    r3259 r3280  
    232232                        Benchmark::start(SYSTEM_BENCHMARK.'_controller_setup'); 
    233233 
     234                        if (Router::$method[0] === '_') 
     235                        { 
     236                                // Do not allow access to hidden methods 
     237                                Event::run('system.404'); 
     238                        } 
     239 
    234240                        // Include the Controller file 
    235241                        require Router::$controller_path; 
     
    255261                        Event::run('system.pre_controller'); 
    256262 
    257                         if ($class->hasMethod('_remap')) 
    258                         { 
    259                                 // Make the arguments routed 
    260                                 $arguments = array(Router::$method, Router::$arguments); 
    261  
    262                                 // The method becomes part of the arguments 
    263                                 array_unshift(Router::$arguments, Router::$method); 
    264  
    265                                 // Set the method to _remap 
    266                                 Router::$method = '_remap'; 
    267                         } 
    268                         elseif (Router::$method[0] != '_') 
    269                         { 
    270                                 // Use the arguments normally 
    271                                 $arguments = Router::$arguments; 
    272                         } 
    273  
    274                         if ($class->hasMethod(Router::$method)) 
    275                         { 
    276                                 // Start validation of method 
    277                                 $method = $class->getMethod(Router::$method); 
    278  
    279                                 if ($method->isPrivate() OR $method->isProtected()) 
    280                                 { 
    281                                         // Method is invalid 
    282                                         unset($method); 
    283                                 } 
    284                         } 
    285  
    286                         if ( ! isset($method)) 
    287                         { 
    288                                 if ($class->hasMethod('_default')) 
    289                                 { 
    290                                         // Make the arguments routed 
    291                                         $arguments = array(Router::$method, Router::$arguments); 
    292  
    293                                         // The method becomes part of the arguments 
    294                                         array_unshift(Router::$arguments, Router::$method); 
    295  
    296                                         // Set the method to _default 
    297                                         Router::$method = '_default'; 
    298  
    299                                         // Load method 
    300                                         $method = $class->getMethod('_default'); 
    301                                 } 
    302                                 else 
    303                                 { 
    304                                         Event::run('system.404'); 
    305                                 } 
    306                         } 
    307  
    308263                        // Create a new controller instance 
    309264                        $controller = $class->newInstance(); 
     
    311266                        // Controller constructor has been executed 
    312267                        Event::run('system.post_controller_constructor'); 
     268 
     269                        try 
     270                        { 
     271                                // Load the controller method 
     272                                $method = $class->getMethod(Router::$method); 
     273 
     274                                if ($method->isProtected() or $method->isPrivate()) 
     275                                { 
     276                                        // Do not attempt to invoke protected methods 
     277                                        throw new ReflectionException('protected controller method'); 
     278                                } 
     279 
     280                                // Default arguments 
     281                                $arguments = Router::$arguments; 
     282                        } 
     283                        catch (ReflectionException $e) 
     284                        { 
     285                                // Use __call instead 
     286                                $method = $class->getMethod('__call'); 
     287 
     288                                // Use arguments in __call format 
     289                                $arguments = array(Router::$method, Router::$arguments); 
     290                        } 
    313291 
    314292                        // Stop the controller setup benchmark