| | 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 | /** |
|---|
| 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; |
|---|