Checking if a driver can be loaded

In driver-based packages you should check if the driver exists before loading it. A simple file_exists() does not work since it does not check the include path. fopen()'s third parameter does that, so we use it.

<?php
$driver 
'SomeDriver';
$class  'My_Package_Driver_' $driver;
$file   str_replace('_''/'$class) . '.php';

//check if it exists and can be loaded
if (!@fclose(@fopen($file'r'true))) {
    throw new 
My_Package_Driver_Exception(
        
'Driver ' $driver ' cannot be loaded.'
    
);
}

//continue with including the driver
require_once $file;

//...
?>