Changeset 1772

Show
Ignore:
Timestamp:
01/21/2008 10:33:19 AM (9 months ago)
Author:
Geert
Message:

Kohana::auto_load() now throws an exception if the needed file does not exist.

This fixes proper exception handling on all the driver based libraries: Archive, Cache, Database, Image, Payment and Session.
See for example: http://trac.kohanaphp.com/browser/trunk/system/libraries/Session.php?rev=1745#L63

Also changed code and lang files to be more consistent.

Location:
trunk/system
Files:
13 modified

Legend:

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

    r1762 r1772  
    597597 
    598598                // If the file doesn't exist, just return 
    599                 if (($filepath = self::find_file($type, $file)) === FALSE) 
     599                if (($filepath = self::find_file($type, $file, TRUE)) === FALSE) 
    600600                        return; 
    601601 
  • trunk/system/i18n/en_US/archive.php

    r1297 r1772  
    33$lang = array 
    44( 
    5         'driver_not_supported' => 'The requested Archive driver, %s, is not supported.', 
     5        'driver_not_supported' => 'The requested Archive driver, %s, was not found.', 
    66        'driver_implements'    => 'The requested Archive driver, %s, does not implement Archive_Driver.', 
    77        'directory_unwritable' => 'The directory you requested to save the file in, %s, is unwritable. Please correct the permissions and try again.', 
  • trunk/system/i18n/en_US/cache.php

    r1748 r1772  
    33$lang = array 
    44( 
    5         'driver_not_supported' => 'The %s cache driver does not exist.', 
     5        'driver_not_supported' => 'The requested Cache driver, %s, was not found.', 
    66        'extension_not_loaded' => 'The %s PHP extension must be loaded to use this driver.', 
    77        'unwritable'           => 'The configured storage location, <tt>%s</tt>, is not writable.', 
  • trunk/system/i18n/en_US/database.php

    r1522 r1772  
    66        'error'                 => 'There was an SQL error: %s', 
    77        'connection'            => 'There was an error connecting to the database: %s', 
    8         'driver_not_supported'  => 'The %s database driver does not exist.', 
     8        'driver_not_supported'  => 'The requested Database driver, %s, was not found.', 
    99        'invalid_dsn'           => 'The DSN you supplied is not valid: %s', 
    1010        'must_use_set'          => 'You must set a SET clause for your query.', 
  • trunk/system/i18n/en_US/image.php

    r1766 r1772  
    33$lang = array 
    44( 
    5         'driver_not_supported'    => 'The %s image driver does not exist.', 
     5        'driver_not_supported'    => 'The requested Image driver, %s, was not found.', 
    66 
    77        // CI's Image_lib stuff below 
  • trunk/system/i18n/en_US/payment.php

    r1600 r1772  
    33$lang = array 
    44( 
    5         'required' => 'Some required fields were not supplied: %s', 
     5        'driver_not_supported'     => 'The requested Payment driver, %s, was not found.', 
     6        'required'                 => 'Some required fields were not supplied: %s', 
    67        'gateway_connection_error' => 'An error occured connecting to the payment gateway. please contact the webmaster if this problem persists.', 
    7         'invalid_certificate' => 'The certificate file is invalid: %s', 
    8         'no_dlib' => 'Could not load the dynamic library: %s', 
    9         'error' => 'There was an error processing the transaction: %s', 
     8        'invalid_certificate'      => 'The certificate file is invalid: %s', 
     9        'no_dlib'                  => 'Could not load the dynamic library: %s', 
     10        'error'                    => 'There was an error processing the transaction: %s', 
    1011); 
  • trunk/system/i18n/en_US/session.php

    r1522 r1772  
    44( 
    55        'no_table'                        => 'The configured session table, %s, was not found.', 
    6         'driver_not_supported'            => 'The requested session driver, %s, was not found.', 
     6        'driver_not_supported'            => 'The requested Session driver, %s, was not found.', 
    77        'driver_must_implement_interface' => 'Session drivers must implement the Session_Driver interface.' 
    88); 
  • trunk/system/libraries/Archive.php

    r1481 r1772  
    3232                { 
    3333                        // Set driver name 
    34                         $driver = 'Archive_'.ucfirst($type).'_Driver'; 
     34                        $driver = 'Archive_'.ucfirst(strtolower($type)).'_Driver'; 
    3535 
    36                         // Manually call auto-loading, for proper exception handling 
     36                        // Manually autoload so that exceptions can be caught 
    3737                        Kohana::auto_load($driver); 
    38  
    39                         // Initialize the driver 
    40                         $this->driver = new $driver(); 
    4138                } 
    4239                catch (Kohana_Exception $exception) 
     
    4441                        throw new Kohana_Exception('archive.driver_not_supported', $type); 
    4542                } 
     43 
     44                // Initialize the driver 
     45                $this->driver = new $driver(); 
    4646 
    4747                // Validate the driver 
  • trunk/system/libraries/Cache.php

    r1695 r1772  
    3636                try 
    3737                { 
    38                         $driver = 'Cache_'.ucfirst($this->config['driver']).'_Driver'; 
     38                        // Set driver name 
     39                        $driver = 'Cache_'.ucfirst(strtolower($this->config['driver'])).'_Driver'; 
    3940 
    4041                        // Manually autoload so that exceptions can be caught 
     
    4344                catch (Kohana_Exception $e) 
    4445                { 
    45                         // Driver was not found 
    4646                        throw new Kohana_Exception('cache.driver_not_supported', $this->config['driver']); 
    4747                } 
  • trunk/system/libraries/Database.php

    r1719 r1772  
    155155                { 
    156156                        // Set driver name 
    157                         $driver = 'Database_'.ucfirst($this->config['connection']['type']).'_Driver'; 
    158  
    159                         // Manually call auto-loading, for proper exception handling 
     157                        $driver = 'Database_'.ucfirst(strtolower($this->config['connection']['type'])).'_Driver'; 
     158 
     159                        // Manually autoload so that exceptions can be caught 
    160160                        Kohana::auto_load($driver); 
    161  
    162                         // Initialize the driver 
    163                         $this->driver = new $driver($this->config); 
    164161                } 
    165162                catch (Kohana_Exception $e) 
     
    167164                        throw new Kohana_Database_Exception('database.driver_not_supported', $this->config['connection']['type']); 
    168165                } 
     166 
     167                // Initialize the driver 
     168                $this->driver = new $driver($this->config); 
    169169 
    170170                // Validate the driver 
  • trunk/system/libraries/Image.php

    r1565 r1772  
    6666                try 
    6767                { 
    68                         // Create the driver class name 
    69                         $driver = 'Image_'.ucfirst($this->config['driver']).'_Driver'; 
     68                        // Set driver name 
     69                        $driver = 'Image_'.ucfirst(strtolower($this->config['driver'])).'_Driver'; 
    7070 
    7171                        // Manually autoload so that exceptions can be caught 
     
    7474                catch (Kohana_Exception $e) 
    7575                { 
    76                         // Driver was not found 
    77                         throw new Kohana_Exception('cache.driver_not_supported', $this->config['driver']); 
     76                        throw new Kohana_Exception('image.driver_not_supported', $this->config['driver']); 
    7877                } 
    7978 
  • trunk/system/libraries/Payment.php

    r1766 r1772  
    7878                $this->config = array_merge($this->config, Config::item('payment.'.$this->config['driver'])); 
    7979 
    80                 // Set driver name 
    81                 $driver = 'Payment_'.ucfirst($this->config['driver']).'_Driver'; 
     80                try 
     81                { 
     82                        // Set driver name 
     83                        $driver = 'Payment_'.ucfirst(strtolower($this->config['driver'])).'_Driver'; 
    8284 
    83                 // Manually call auto-loading, for proper exception handling 
    84                 Kohana::auto_load($driver); 
     85                        // Manually autoload so that exceptions can be caught 
     86                        Kohana::auto_load($driver); 
     87                } 
     88                catch (Kohana_Exception $e) 
     89                { 
     90                        throw new Kohana_Exception('payment.driver_not_supported', $this->config['driver']); 
     91                } 
    8592 
    8693                // Initialize the driver 
  • trunk/system/libraries/Session.php

    r1745 r1772  
    5858                                try 
    5959                                { 
    60                                         // Set the driver name 
     60                                        // Set driver name 
    6161                                        $driver = 'Session_'.ucfirst(strtolower(self::$config['driver'])).'_Driver'; 
    6262 
    63                                         // Manually call auto-loading, for proper exception handling 
     63                                        // Manually autoload so that exceptions can be caught 
    6464                                        Kohana::auto_load($driver); 
    6565                                }