Changeset 3367

Show
Ignore:
Timestamp:
08/27/2008 05:22:55 PM (3 months ago)
Author:
Shadowhand
Message:

Moved core classes to system/classes, as they should have been originally

Location:
trunk/system/classes
Files:
1 removed
1 modified
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/system/classes/benchmark.php

  • trunk/system/classes/event.php

  • trunk/system/classes/kohana.php

    r3366 r3367  
    126126                self::$buffer_level = ob_get_level(); 
    127127 
     128                // Send default text/html UTF-8 header 
     129                header('Content-Type: text/html; charset=UTF-8'); 
     130 
    128131                // Set autoloader 
    129132                spl_autoload_register(array('Kohana', 'auto_load')); 
     
    135138                Kohana_PHP_Exception::enable(); 
    136139 
    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                } 
    139148 
    140149                // Load locales 
    141                 $locales = self::config('locale.language'); 
     150                $locales = Kohana::config('locale.language'); 
    142151 
    143152                // Make first locale UTF-8 
     
    146155                // Set locale information 
    147156                self::$locale = setlocale(LC_ALL, $locales); 
    148  
    149                 if (self::$configuration['core']['log_threshold'] > 0) 
    150                 { 
    151                         // Set the log directory 
    152                         self::log_directory(self::$configuration['core']['log_directory']); 
    153  
    154                         // Enable log writing at shutdown 
    155                         register_shutdown_function(array(__CLASS__, 'log_save')); 
    156                 } 
    157157 
    158158                // Enable Kohana routing 
     
    235235                if (self::$instance === NULL) 
    236236                { 
     237                        // Routing has been completed 
     238                        Event::run('system.post_routing'); 
     239 
    237240                        Benchmark::start(SYSTEM_BENCHMARK.'_controller_setup'); 
    238241 
    239                         if (Router::$method[0] === '_') 
     242                        if (Router::$controller === NULL OR Router::$method[0] === '_') 
    240243                        { 
    241244                                // Do not allow access to hidden methods 
     
    243246                        } 
    244247 
    245                         // Include the Controller file 
    246                         require Router::$controller_path; 
    247  
    248248                        try 
    249249                        { 
    250250                                // Start validation of the controller 
    251                                 $class = new ReflectionClass(ucfirst(Router::$controller).'_Controller'); 
     251                                $class = new ReflectionClass('Controller_'.ucfirst(Router::$controller)); 
    252252                        } 
    253253                        catch (ReflectionException $e) 
     
    280280                                { 
    281281                                        // Do not attempt to invoke protected methods 
    282                                         throw new ReflectionException('protected controller method'); 
     282                                        throw new ReflectionException('invalid router method'); 
    283283                                } 
    284284 
     
    325325                if ($process === TRUE) 
    326326                { 
     327                        // Get standard PHP include paths 
     328                        // $php_paths = get_include_path(); 
     329 
    327330                        // Add APPPATH as the first path 
    328331                        self::$include_paths = array(APPPATH); 
     
    339342                        // Add SYSPATH as the last path 
    340343                        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)); 
    341349                } 
    342350 
     
    820828         * Provides class auto-loading. 
    821829         * 
    822          * @throws  Kohana_Exception 
    823830         * @param   string  name of class 
    824831         * @return  bool 
     
    829836                        return TRUE; 
    830837 
    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))) 
    874842                        return FALSE; 
    875843 
    876                 // Load the file 
    877                 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 the extension 
    884                                 require $extension; 
    885                         } 
    886                         elseif ($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 
    887855                        { 
    888856                                // Class extension to be evaluated 
     
    14631431 
    14641432                                $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) 
    14681437                                        { 
    1469                                                 // Sanitize path 
    1470                                                 $arg = Kohana::sanitize_path($arg); 
    1471                                         } 
    1472  
    1473                                         switch (gettype($arg)) 
    1474                                         { 
    1475                                                 case 'object': 
    1476                                                         $args[] = '&lt;object&gt; '.get_class($arg); 
    1477                                                 break; 
    1478                                                 case 'array': 
    1479                                                         if (is_callable($arg, FALSE, $call)) 
    1480                                                         { 
    1481                                                                 $args[] = '&lt;callback&gt; '.$call; 
    1482                                                         } 
    1483                                                         else 
    1484                                                         { 
    1485                                                                 $args[] = '&lt;array&gt;'; 
    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[] = '&lt;object&gt; '.get_class($arg); 
     1448                                                        break; 
     1449                                                        case 'array': 
     1450                                                                if (is_callable($arg, FALSE, $call)) 
     1451                                                                { 
     1452                                                                        $args[] = '&lt;callback&gt; '.$call; 
     1453                                                                } 
     1454                                                                else 
     1455                                                                { 
     1456                                                                        $args[] = '&lt;array&gt;'; 
     1457                                                                } 
     1458                                                        break; 
     1459                                                        case 'string': 
     1460                                                                $args[] = "'$arg'"; 
     1461                                                        break; 
     1462                                                        default: 
     1463                                                                $args[] = $arg; 
     1464                                                        break; 
     1465                                                } 
    14941466                                        } 
    14951467                                } 
     
    16011573                // An error has been triggered 
    16021574                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                } 
    16031608 
    16041609                echo $exception; 
     
    18351840                Kohana::$has_error = TRUE; 
    18361841 
    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; 
    18381861        } 
    18391862 
     
    18531876        } 
    18541877 
     1878        public function sendHeaders() 
     1879        { 
     1880                // Send the 500 header 
     1881                header('HTTP/1.1 500 Internal Server Error'); 
     1882        } 
     1883 
    18551884} // End Kohana PHP Exception 
    18561885 
  • trunk/system/classes/router.php

    r3366 r3367  
    2424         * Event by default.  
    2525         * 
     26         * [ref-esr]: http://docs.kohanaphp.com/events/system.routing 
    2627         * @return  boolean 
    2728         */