Changeset 2072 for trunk/system/core/Kohana.php
- Timestamp:
- 02/18/2008 11:54:41 AM (9 months ago)
- Files:
-
- 1 modified
-
trunk/system/core/Kohana.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/core/Kohana.php
r2003 r2072 219 219 class_exists($controller, FALSE) or Event::run('system.404'); 220 220 221 // Find the unique controller methods 222 $methods = array_diff(get_class_methods($controller), get_class_methods('Controller_Core')); 223 224 // If there are no methods in the controller, it's invalid 225 empty($methods) and Event::run('system.404'); 226 227 // Combine the methods 228 $methods = array_combine($methods, $methods); 221 // Get the controller methods 222 $methods = array_flip(get_class_methods($controller)); 223 229 224 230 225 if (isset($methods['_remap'])) 231 226 { 232 // Change arguments to be $method, $arguments. 233 // This makes _remap capable of being a much more effecient dispatcher 234 Router::$arguments = array(Router::$method, Router::$arguments); 227 // Make the arguments routed 228 $arguments = array(Router::$method, Router::$arguments); 229 230 // The method becomes part of the arguments 231 array_unshift(Router::$arguments, Router::$method); 235 232 236 233 // Set the method to _remap 237 234 Router::$method = '_remap'; 238 235 } 239 elseif (isset($methods[Router::$method]) AND substr(Router::$method, 0, 1) != '_') 240 { 241 // A valid route has been found, and nothing needs to be done. 242 // Amazing that having nothing inside the statement still works. 243 } 244 elseif (method_exists($controller, '_default')) 245 { 246 // Change arguments to be $method, $arguments. 247 // This makes _default a much more effecient 404 handler 248 Router::$arguments = array(Router::$method, Router::$arguments); 236 elseif (isset($methods[Router::$method]) AND Router::$method{0} !== '_') 237 { 238 // Use the arguments normally 239 $arguments = Router::$arguments; 240 } 241 elseif (isset($methods['_default'])) 242 { 243 // Make the arguments routed 244 $arguments = array(Router::$method, Router::$arguments); 245 246 // The method becomes part of the arguments 247 array_unshift(Router::$arguments, Router::$method); 249 248 250 249 // Set the method to _default … … 260 259 $controller = new $controller; 261 260 261 // Controller method name, used for calling 262 $method = Router::$method; 263 262 264 // Run system.post_controller_constructor 263 265 Event::run('system.post_controller_constructor'); … … 269 271 Benchmark::start(SYSTEM_BENCHMARK.'_controller_execution'); 270 272 271 // Controller method name, used for calling 272 $method = Router::$method; 273 274 if (empty(Router::$arguments)) 273 if (empty($arguments)) 275 274 { 276 275 // Call the controller method with no arguments … … 279 278 else 280 279 { 281 // Manually call the controller for up to 4 arguments. Why? Because 282 // call_user_func_array is ~3 times slower than direct method calls. 283 switch(count(Router::$arguments)) 280 // Manually call the controller for up to 4 arguments, to increase performance 281 switch(count($arguments)) 284 282 { 285 283 case 1: 286 $controller->$method( Router::$arguments[0]);284 $controller->$method($arguments[0]); 287 285 break; 288 286 case 2: 289 $controller->$method( Router::$arguments[0], Router::$arguments[1]);287 $controller->$method($arguments[0], $arguments[1]); 290 288 break; 291 289 case 3: 292 $controller->$method( Router::$arguments[0], Router::$arguments[1], Router::$arguments[2]);290 $controller->$method($arguments[0], $arguments[1], $arguments[2]); 293 291 break; 294 292 case 4: 295 $controller->$method( Router::$arguments[0], Router::$arguments[1], Router::$arguments[2], Router::$arguments[3]);293 $controller->$method($arguments[0], $arguments[1], $arguments[2], $arguments[3]); 296 294 break; 297 295 default: 298 296 // Resort to using call_user_func_array for many segments 299 call_user_func_array(array($controller, $method), Router::$arguments);297 call_user_func_array(array($controller, $method), $arguments); 300 298 break; 301 299 }
