Changeset 3367
- Timestamp:
- 08/27/2008 05:22:55 PM (3 months ago)
- Location:
- trunk/system/classes
- Files:
-
- 1 removed
- 1 modified
- 3 moved
-
benchmark.php (moved) (moved from trunk/system/core/Benchmark.php) (1 prop)
-
event.php (moved) (moved from trunk/system/core/Event.php) (1 prop)
-
kohana.php (moved) (moved from trunk/system/core/Kohana.php) (14 diffs, 1 prop)
-
router.php (modified) (1 diff)
-
utf8 (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/classes/benchmark.php
-
trunk/system/classes/event.php
-
trunk/system/classes/kohana.php
r3366 r3367 126 126 self::$buffer_level = ob_get_level(); 127 127 128 // Send default text/html UTF-8 header 129 header('Content-Type: text/html; charset=UTF-8'); 130 128 131 // Set autoloader 129 132 spl_autoload_register(array('Kohana', 'auto_load')); … … 135 138 Kohana_PHP_Exception::enable(); 136 139 137 // Send default text/html UTF-8 header 138 header('Content-Type: text/html; charset=UTF-8'); 140 if (self::$configuration['core']['log_threshold'] > 0) 141 { 142 // Set the log directory 143 self::log_directory(self::$configuration['core']['log_directory']); 144 145 // Enable log writing at shutdown 146 register_shutdown_function(array(__CLASS__, 'log_save')); 147 } 139 148 140 149 // Load locales 141 $locales = self::config('locale.language');150 $locales = Kohana::config('locale.language'); 142 151 143 152 // Make first locale UTF-8 … … 146 155 // Set locale information 147 156 self::$locale = setlocale(LC_ALL, $locales); 148 149 if (self::$configuration['core']['log_threshold'] > 0)150 {151 // Set the log directory152 self::log_directory(self::$configuration['core']['log_directory']);153 154 // Enable log writing at shutdown155 register_shutdown_function(array(__CLASS__, 'log_save'));156 }157 157 158 158 // Enable Kohana routing … … 235 235 if (self::$instance === NULL) 236 236 { 237 // Routing has been completed 238 Event::run('system.post_routing'); 239 237 240 Benchmark::start(SYSTEM_BENCHMARK.'_controller_setup'); 238 241 239 if (Router::$ method[0] === '_')242 if (Router::$controller === NULL OR Router::$method[0] === '_') 240 243 { 241 244 // Do not allow access to hidden methods … … 243 246 } 244 247 245 // Include the Controller file246 require Router::$controller_path;247 248 248 try 249 249 { 250 250 // Start validation of the controller 251 $class = new ReflectionClass( ucfirst(Router::$controller).'_Controller');251 $class = new ReflectionClass('Controller_'.ucfirst(Router::$controller)); 252 252 } 253 253 catch (ReflectionException $e) … … 280 280 { 281 281 // Do not attempt to invoke protected methods 282 throw new ReflectionException(' protected controller method');282 throw new ReflectionException('invalid router method'); 283 283 } 284 284 … … 325 325 if ($process === TRUE) 326 326 { 327 // Get standard PHP include paths 328 // $php_paths = get_include_path(); 329 327 330 // Add APPPATH as the first path 328 331 self::$include_paths = array(APPPATH); … … 339 342 // Add SYSPATH as the last path 340 343 self::$include_paths[] = SYSPATH; 344 345 // New PHP include paths 346 // $new_paths = array_diff(self::$include_paths, explode(PATH_SEPARATOR, $php_paths)); 347 348 // set_include_path($php_paths.PATH_SEPARATOR.implode(PATH_SEPARATOR, $new_paths)); 341 349 } 342 350 … … 820 828 * Provides class auto-loading. 821 829 * 822 * @throws Kohana_Exception823 830 * @param string name of class 824 831 * @return bool … … 829 836 return TRUE; 830 837 831 if (($suffix = strrpos($class, '_')) > 0) 832 { 833 // Find the class suffix 834 $suffix = substr($class, $suffix + 1); 835 } 836 else 837 { 838 // No suffix 839 $suffix = FALSE; 840 } 841 842 if ($suffix === 'Core') 843 { 844 $type = 'libraries'; 845 $file = substr($class, 0, -5); 846 } 847 elseif ($suffix === 'Controller') 848 { 849 $type = 'controllers'; 850 // Lowercase filename 851 $file = strtolower(substr($class, 0, -11)); 852 } 853 elseif ($suffix === 'Model') 854 { 855 $type = 'models'; 856 // Lowercase filename 857 $file = strtolower(substr($class, 0, -6)); 858 } 859 elseif ($suffix === 'Driver') 860 { 861 $type = 'libraries/drivers'; 862 $file = str_replace('_', '/', substr($class, 0, -7)); 863 } 864 else 865 { 866 // This could be either a library or a helper, but libraries must 867 // always be capitalized, so we check if the first character is 868 // uppercase. If it is, we are loading a library, not a helper. 869 $type = ($class[0] < 'a') ? 'libraries' : 'helpers'; 870 $file = $class; 871 } 872 873 if (($filepath = self::find_file($type, $file)) === FALSE) 838 // Determine class filename 839 $filename = str_replace('_', '/', strtolower($class)); 840 841 if ( ! ($path = Kohana::find_file('classes', $filename, FALSE))) 874 842 return FALSE; 875 843 876 // Load the file877 require $ filepath;878 879 if ( $type === 'libraries' OR $type === 'helpers')880 { 881 if ($ extension = self::find_file($type, self::$configuration['core']['extension_prefix'].$class))882 { 883 // Load theextension884 require $ extension;885 } 886 else if ($suffix !== 'Core' AND class_exists($class.'_Core', FALSE))844 // Load class 845 require $path; 846 847 if (class_exists($class.'_Core', FALSE)) 848 { 849 if ($path = Kohana::find_file('extensions', $filename, FALSE)) 850 { 851 // Load class extension 852 require $path; 853 } 854 else 887 855 { 888 856 // Class extension to be evaluated … … 1463 1431 1464 1432 $args = array(); 1465 foreach ($trace['args'] as $arg) 1466 { 1467 if (is_string($arg) AND file_exists($arg)) 1433 1434 if ( ! empty($trace['args'])) 1435 { 1436 foreach ($trace['args'] as $arg) 1468 1437 { 1469 // Sanitize path 1470 $arg = Kohana::sanitize_path($arg); 1471 } 1472 1473 switch (gettype($arg)) 1474 { 1475 case 'object': 1476 $args[] = '<object> '.get_class($arg); 1477 break; 1478 case 'array': 1479 if (is_callable($arg, FALSE, $call)) 1480 { 1481 $args[] = '<callback> '.$call; 1482 } 1483 else 1484 { 1485 $args[] = '<array>'; 1486 } 1487 break; 1488 case 'string': 1489 $args[] = "'$arg'"; 1490 break; 1491 default: 1492 $args[] = $arg; 1493 break; 1438 if (is_string($arg) AND file_exists($arg)) 1439 { 1440 // Sanitize path 1441 $arg = Kohana::sanitize_path($arg); 1442 } 1443 1444 switch (gettype($arg)) 1445 { 1446 case 'object': 1447 $args[] = '<object> '.get_class($arg); 1448 break; 1449 case 'array': 1450 if (is_callable($arg, FALSE, $call)) 1451 { 1452 $args[] = '<callback> '.$call; 1453 } 1454 else 1455 { 1456 $args[] = '<array>'; 1457 } 1458 break; 1459 case 'string': 1460 $args[] = "'$arg'"; 1461 break; 1462 default: 1463 $args[] = $arg; 1464 break; 1465 } 1494 1466 } 1495 1467 } … … 1601 1573 // An error has been triggered 1602 1574 Kohana::$has_error = TRUE; 1575 1576 if (is_numeric($exception->code)) 1577 { 1578 $codes = Kohana::lang('errors'); 1579 1580 if ( ! empty($codes[$exception->code])) 1581 { 1582 list($level, $error) = $codes[$exception->code]; 1583 } 1584 else 1585 { 1586 $level = 1; 1587 $error = get_class($exception); 1588 } 1589 } 1590 else 1591 { 1592 // Custom error message, this will never be logged 1593 $level = 5; 1594 $error = $exception->code; 1595 } 1596 1597 if ($level >= Kohana::config('core.log_threshold')) 1598 { 1599 // Log the error 1600 Kohana::log('error', Kohana::lang('core.uncaught_exception', $error, $exception->message, $exception->file, $exception->line)); 1601 } 1602 1603 if (method_exists($exception, 'sendHeaders') AND ! headers_sent()) 1604 { 1605 // Send the headers if they have not already been sent 1606 $exception->sendHeaders(); 1607 } 1603 1608 1604 1609 echo $exception; … … 1835 1840 Kohana::$has_error = TRUE; 1836 1841 1837 echo new Kohana_PHP_Exception($code, $error, $file, $line, $context); 1842 // Create an exception 1843 $exception = new Kohana_PHP_Exception($code, $error, $file, $line, $context); 1844 1845 // Get the error level and name 1846 list ($level, $error) = Kohana::lang('errors.'.$exception->code); 1847 1848 if ($level >= Kohana::config('core.log_threshold')) 1849 { 1850 // Log the error 1851 Kohana::log('error', Kohana::lang('core.uncaught_exception', $error, $exception->message, $exception->file, $exception->line)); 1852 } 1853 1854 if (method_exists($exception, 'sendHeaders') AND ! headers_sent()) 1855 { 1856 // Send the headers if they have not already been sent 1857 $exception->sendHeaders(); 1858 } 1859 1860 echo $exception; 1838 1861 } 1839 1862 … … 1853 1876 } 1854 1877 1878 public function sendHeaders() 1879 { 1880 // Send the 500 header 1881 header('HTTP/1.1 500 Internal Server Error'); 1882 } 1883 1855 1884 } // End Kohana PHP Exception 1856 1885 -
trunk/system/classes/router.php
r3366 r3367 24 24 * Event by default. 25 25 * 26 * [ref-esr]: http://docs.kohanaphp.com/events/system.routing 26 27 * @return boolean 27 28 */
