Show
Ignore:
Timestamp:
09/05/06 23:00:01 (2 years ago)
Author:
gerd
Message:

- support for autopackage
- added feature: custom driver

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/patSession.php

    r46 r49  
    4848 
    4949   /** 
     50    * custom driver dir 
     51    * @var array 
     52    */ 
     53    static private $_driverDir = array(); 
     54 
     55   /** 
     56    * Custom driver dir to include your own classes 
     57    *  
     58    * Set or add a folder as custom driver directory 
     59    * 
     60    * @static 
     61    * @access public 
     62    * @param string $dir of custom drivers 
     63    * @param bool $add  
     64    * @return int current amount of custom directories  
     65    */ 
     66    static public function setDriverDir( $dir, $add = true ) 
     67    { 
     68        if( !$add ) { 
     69            self::$_driverDir   =   array(); 
     70        } 
     71     
     72        self::$_driverDir[] =   $dir; 
     73        return count( self::$_driverDir ); 
     74    } 
     75 
     76   /** 
    5077    * Singleton 
    5178        * create a single instance of patSession driver 
     
    6693         
    6794        // create driver 
    68         $driver =&      patSession::createDriver( $id, $storage, $options ); 
     95        $driver =&      self::createDriver( $id, $storage, $options ); 
    6996        if( patErrorManager::isError( $driver ) ) { 
    7097            return $driver; 
     
    97124                 
    98125                // create driver 
    99                 $driver =&      patSession::createDriver( $id, $storage, $options ); 
     126                $driver =&      self::createDriver( $id, $storage, $options ); 
    100127                if( patErrorManager::isError( $driver ) ) { 
    101128                        return $driver; 
     
    121148    { 
    122149                $driver =       ucfirst(  $storage ); 
    123                 $name   =       'patSession_Storage_' . $storage
     150                $name   =       'patSession_Storage_' . $driver
    124151                 
    125152                $includePath    =       dirname( __FILE__ ) . '/patSession'; 
     153         
     154        // include base class 
    126155                if( !class_exists( 'patSession_Storage' ) ) { 
    127                         include_once $includePath . '/Storage.php'; 
     156                        require_once $includePath . '/Storage.php'; 
    128157                } 
    129158                 
    130159        // storage driver already loaded       
    131         if( class_exists( 'patSession_Storage_' . $storage ) ) { 
     160        if( class_exists( $name ) ) { 
    132161            $driver = new $name( $id, $options ); 
    133162            return $driver;         
     
    135164                 
    136165        // try to load storage driver 
    137         $includePath    .=  '/Storage'; 
    138                 if( !file_exists( $includePath . '/' . $storage . '.php' ) ) { 
    139                         $available      =       array(); 
    140                         if( false !== ( $dh     = dir( $includePath ) ) ) { 
    141                                 while( false !== ( $entry = $dh->read() ) ) { 
    142                                         // search for files 
    143                                         if( $entry[0] === '.' || !is_file( $includePath . '/' . $entry ) ) { 
    144                                                 continue; 
    145                                         } 
    146                                  
    147                                         $name   =       explode( '.', $entry ); 
    148                                         // strange name 
    149                                         if( count( $name ) < 2 ) { 
    150                                                 continue; 
    151                                         } 
    152                                          
    153                                         $ext    =       array_pop( $name ); 
    154                                         // require php-files 
    155                                         if( $ext != 'php' ) { 
    156                                                 continue; 
    157                                         } 
    158                                  
    159                                         array_push( $available, implode( '.', $name ) ); 
    160                                 } 
    161                                  
    162                                 $dh->close(); 
    163                         } 
    164                  
    165                         // create error!  
    166                         $error =& patErrorManager::raiseError( 'patSession:' . self::ERROR_DRIVER_NOT_FOUND, 
    167                                                         'Storage driver not found!', 
    168                                                         'Driver "'. $storage .'" not found - available drivers: "'. implode( '", "', $available ) .'"' 
    169                                                         ); 
    170             return $error; 
    171                          
    172                 } 
    173                  
    174         include_once $includePath . '/' . $storage . '.php';             
    175                 $driver = new $name( $id, $options ); 
    176                 return $driver; 
     166        $includeDirs    =   self::$_driverDir; 
     167        $includeDirs[]  =   $includePath    .=  '/Storage';    
     168         
     169        foreach( $includeDirs as $dir ) { 
     170         
     171            // locate include file 
     172            if( file_exists( $dir . '/' . $driver . '.php' ) ) { 
     173             
     174                // start driver 
     175                include_once $dir . '/' . $driver . '.php';       
     176                $driver = new $name( $id, $options ); 
     177                return $driver; 
     178            }             
     179        } 
     180         
     181        // could not find class to include 
     182         
     183        // collect other files 
     184        $available  =   array(); 
     185        foreach( $includeDirs as $dir ) { 
     186            $di =   new DirectoryIterator( $dir ); 
     187            foreach( $di as $file ) { 
     188                if( $file->isDot() || !$file->isFile() ) { 
     189                    continue; 
     190                } 
     191                 
     192                $n  =   explode( '.', $file->getFilename() ); 
     193                // strange name 
     194                if( count( $n ) < 2 ) { 
     195                    continue; 
     196                } 
     197                     
     198                // require php-files 
     199                $ext    =   array_pop( $n ); 
     200                if( $ext != 'php' ) { 
     201                    continue; 
     202                } 
     203             
     204                array_push( $available, implode( '.', $n ) ); 
     205            } 
     206        } 
     207             
     208        // create error!  
     209        $error  =   patErrorManager::raiseError( 'patSession:' . self::ERROR_DRIVER_NOT_FOUND, 
     210                        'Storage driver not found!', 
     211                        'Driver "'. $storage .'" not found - available drivers: "'. implode( '", "', $available ) .'"' 
     212                        ); 
     213        return $error;                   
    177214    } 
    178215}