@@ -16,7 +16,7 @@ |
||
| 16 | 16 | * @param $className |
| 17 | 17 | */ |
| 18 | 18 | spl_autoload_register( |
| 19 | - function ($className) {
|
|
| 19 | + function($className) {
|
|
| 20 | 20 | if ($className === 'O2System\Session') {
|
| 21 | 21 | require __DIR__ . DIRECTORY_SEPARATOR . 'Session.php'; |
| 22 | 22 | } elseif (strpos($className, 'O2System\Session\\') === false) {
|
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | {
|
| 98 | 98 | $this->config = $config; |
| 99 | 99 | $this->config->offsetUnset('handler');
|
| 100 | - $this->setPrefixKey($this->config[ 'name' ]); |
|
| 100 | + $this->setPrefixKey($this->config['name']); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | //-------------------------------------------------------------------- |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function setLogger(LoggerInterface $logger) |
| 129 | 129 | {
|
| 130 | - $this->logger =& $logger; |
|
| 130 | + $this->logger = & $logger; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -313,12 +313,12 @@ discard block |
||
| 313 | 313 | protected function destroyCookie() |
| 314 | 314 | {
|
| 315 | 315 | return setcookie( |
| 316 | - $this->config[ 'name' ], |
|
| 316 | + $this->config['name'], |
|
| 317 | 317 | null, |
| 318 | 318 | 1, |
| 319 | - $this->config[ 'cookie' ]->path, |
|
| 320 | - '.' . ltrim($this->config[ 'cookie' ]->domain, '.'), |
|
| 321 | - $this->config[ 'cookie' ]->secure, |
|
| 319 | + $this->config['cookie']->path, |
|
| 320 | + '.' . ltrim($this->config['cookie']->domain, '.'), |
|
| 321 | + $this->config['cookie']->secure, |
|
| 322 | 322 | true |
| 323 | 323 | ); |
| 324 | 324 | } |
@@ -89,26 +89,26 @@ discard block |
||
| 89 | 89 | return false; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if (isset($this->config[ 'servers' ])) { |
|
| 93 | - foreach ($this->config[ 'servers' ] as $server => $setup) { |
|
| 94 | - isset($setup[ 'port' ]) OR $setup[ 'port' ] = 11211; |
|
| 95 | - isset($setup[ 'weight' ]) OR $setup[ 'weight' ] = 1; |
|
| 92 | + if (isset($this->config['servers'])) { |
|
| 93 | + foreach ($this->config['servers'] as $server => $setup) { |
|
| 94 | + isset($setup['port']) OR $setup['port'] = 11211; |
|
| 95 | + isset($setup['weight']) OR $setup['weight'] = 1; |
|
| 96 | 96 | |
| 97 | 97 | // Third parameter is persistance and defaults to TRUE. |
| 98 | 98 | $this->memcache->addServer( |
| 99 | - $setup[ 'host' ], |
|
| 100 | - $setup[ 'port' ], |
|
| 99 | + $setup['host'], |
|
| 100 | + $setup['port'], |
|
| 101 | 101 | true, |
| 102 | - $setup[ 'weight' ] |
|
| 102 | + $setup['weight'] |
|
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | } else { |
| 106 | 106 | // Third parameter is persistance and defaults to TRUE. |
| 107 | 107 | $this->memcache->addServer( |
| 108 | - $this->config[ 'host' ], |
|
| 109 | - $this->config[ 'port' ], |
|
| 108 | + $this->config['host'], |
|
| 109 | + $this->config['port'], |
|
| 110 | 110 | true, |
| 111 | - $this->config[ 'weight' ] |
|
| 111 | + $this->config['weight'] |
|
| 112 | 112 | ); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | $this->prefixKey . $session_id, |
| 342 | 342 | $session_data, |
| 343 | 343 | false, |
| 344 | - $this->config[ 'lifetime' ] |
|
| 344 | + $this->config['lifetime'] |
|
| 345 | 345 | ) |
| 346 | 346 | ) { |
| 347 | 347 | $this->fingerprint = $fingerprint; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | return $this->memcache->replace($this->prefixKey . $session_id, $session_data, false, |
| 356 | - $this->config[ 'lifetime' ]); |
|
| 356 | + $this->config['lifetime']); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | return false; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | apcu_store($this->lockKey, time(), 300); |
| 284 | 284 | |
| 285 | 285 | if ($this->fingerprint !== ($fingerprint = md5($sessionData))) { |
| 286 | - if (apcu_store($this->prefixKey . $session_id, $sessionData, $this->config[ 'lifetime' ])) { |
|
| 286 | + if (apcu_store($this->prefixKey . $session_id, $sessionData, $this->config['lifetime'])) { |
|
| 287 | 287 | $this->fingerprint = $fingerprint; |
| 288 | 288 | |
| 289 | 289 | return true; |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | return false; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - return apcu_store($this->prefixKey . $session_id, $sessionData, $this->config[ 'lifetime' ]); |
|
| 295 | + return apcu_store($this->prefixKey . $session_id, $sessionData, $this->config['lifetime']); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | return false; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | if (wincache_ucache_set( |
| 287 | 287 | $this->prefixKey . $session_id, |
| 288 | 288 | $session_data, |
| 289 | - $this->config[ 'lifetime' ] |
|
| 289 | + $this->config['lifetime'] |
|
| 290 | 290 | )) {
|
| 291 | 291 | $this->fingerprint = $fingerprint; |
| 292 | 292 | |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | return false; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - return wincache_ucache_set($this->prefixKey . $session_id, $session_data, $this->config[ 'lifetime' ]); |
|
| 299 | + return wincache_ucache_set($this->prefixKey . $session_id, $session_data, $this->config['lifetime']); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | return false; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function open($save_path, $name) |
| 82 | 82 | {
|
| 83 | - $this->path = $this->config[ 'filePath' ]; |
|
| 83 | + $this->path = $this->config['filePath']; |
|
| 84 | 84 | |
| 85 | 85 | if ($this->isSupported() === false) {
|
| 86 | 86 | if ($this->logger instanceof LoggerInterface) {
|
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | $this->filePath = $this->path |
| 94 | 94 | . $name . '-' // we'll use the session cookie name as a prefix to avoid collisions |
| 95 | - . ($this->config[ 'match' ]->ip ? md5($_SERVER[ 'REMOTE_ADDR' ]) . '-' : ''); |
|
| 95 | + . ($this->config['match']->ip ? md5($_SERVER['REMOTE_ADDR']) . '-' : ''); |
|
| 96 | 96 | |
| 97 | 97 | return true; |
| 98 | 98 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | while (($file = readdir($directory)) !== false) {
|
| 213 | 213 | // If the filename doesn't match this pattern, it's either not a session file or is not ours |
| 214 | - if ( ! preg_match('/[' . $this->config[ 'name' ] . '-]+[0-9-a-f]+/', $file)
|
|
| 214 | + if ( ! preg_match('/[' . $this->config['name'] . '-]+[0-9-a-f]+/', $file)
|
|
| 215 | 215 | || ! is_file($this->path . '/' . $file) |
| 216 | 216 | || ($mtime = filemtime($this->path . '/' . $file)) === false |
| 217 | 217 | || $mtime > $ts |
@@ -90,22 +90,22 @@ discard block |
||
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if (isset($this->config[ 'servers' ])) {
|
|
| 94 | - foreach ($this->config[ 'servers' ] as $server => $setup) {
|
|
| 95 | - isset($setup[ 'port' ]) OR $setup[ 'port' ] = 11211; |
|
| 96 | - isset($setup[ 'weight' ]) OR $setup[ 'weight' ] = 1; |
|
| 93 | + if (isset($this->config['servers'])) {
|
|
| 94 | + foreach ($this->config['servers'] as $server => $setup) {
|
|
| 95 | + isset($setup['port']) OR $setup['port'] = 11211; |
|
| 96 | + isset($setup['weight']) OR $setup['weight'] = 1; |
|
| 97 | 97 | |
| 98 | 98 | $this->memcached->addServer( |
| 99 | - $setup[ 'host' ], |
|
| 100 | - $setup[ 'port' ], |
|
| 101 | - $setup[ 'weight' ] |
|
| 99 | + $setup['host'], |
|
| 100 | + $setup['port'], |
|
| 101 | + $setup['weight'] |
|
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | } else {
|
| 105 | 105 | $this->memcached->addServer( |
| 106 | - $this->config[ 'host' ], |
|
| 107 | - $this->config[ 'port' ], |
|
| 108 | - $this->config[ 'weight' ] |
|
| 106 | + $this->config['host'], |
|
| 107 | + $this->config['port'], |
|
| 108 | + $this->config['weight'] |
|
| 109 | 109 | ); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | if ($this->memcached->set( |
| 338 | 338 | $this->prefixKey . $session_id, |
| 339 | 339 | $session_data, |
| 340 | - $this->config[ 'lifetime' ] |
|
| 340 | + $this->config['lifetime'] |
|
| 341 | 341 | ) |
| 342 | 342 | ) {
|
| 343 | 343 | $this->fingerprint = $fingerprint; |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | return false; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - return $this->memcached->touch($this->prefixKey . $session_id, $this->config[ 'lifetime' ]); |
|
| 351 | + return $this->memcached->touch($this->prefixKey . $session_id, $this->config['lifetime']); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | return false; |
@@ -93,10 +93,10 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | try {
|
| 95 | 95 | if ( ! $this->redis->connect( |
| 96 | - $this->config[ 'host' ], |
|
| 97 | - ($this->config[ 'host' ][ 0 ] === '/' ? 0 |
|
| 98 | - : $this->config[ 'port' ]), |
|
| 99 | - $this->config[ 'timeout' ] |
|
| 96 | + $this->config['host'], |
|
| 97 | + ($this->config['host'][0] === '/' ? 0 |
|
| 98 | + : $this->config['port']), |
|
| 99 | + $this->config['timeout'] |
|
| 100 | 100 | ) |
| 101 | 101 | ) {
|
| 102 | 102 | if ($this->logger instanceof LoggerInterface) {
|
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | return false; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if (isset($this->config[ 'password' ]) AND ! $this->redis->auth($this->config[ 'password' ])) {
|
|
| 109 | + if (isset($this->config['password']) AND ! $this->redis->auth($this->config['password'])) {
|
|
| 110 | 110 | if ($this->logger instanceof LoggerInterface) {
|
| 111 | 111 | $this->logger->error('SESSION_E_REDIS_AUTHENTICATION_FAILED', ['Redis']);
|
| 112 | 112 | } |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | $this->redis->setTimeout($this->lockKey, 300); |
| 351 | 351 | |
| 352 | 352 | if ($this->fingerprint !== ($fingerprint = md5($session_data))) {
|
| 353 | - if ($this->redis->set($this->prefixKey . $session_id, $session_data, $this->config[ 'lifetime' ])) {
|
|
| 353 | + if ($this->redis->set($this->prefixKey . $session_id, $session_data, $this->config['lifetime'])) {
|
|
| 354 | 354 | $this->fingerprint = $fingerprint; |
| 355 | 355 | |
| 356 | 356 | return true; |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | return false; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - return $this->redis->setTimeout($this->prefixKey . $session_id, $this->config[ 'lifetime' ]); |
|
| 362 | + return $this->redis->setTimeout($this->prefixKey . $session_id, $this->config['lifetime']); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | return false; |
@@ -32,33 +32,33 @@ discard block |
||
| 32 | 32 | public function __construct(array $config) |
| 33 | 33 | {
|
| 34 | 34 | // Define Session Name |
| 35 | - $config[ 'name' ] = isset($config[ 'name' ]) ? $config[ 'name' ] : 'o2session'; |
|
| 35 | + $config['name'] = isset($config['name']) ? $config['name'] : 'o2session'; |
|
| 36 | 36 | |
| 37 | 37 | // Define Session Match IP |
| 38 | - $config[ 'match' ][ 'ip' ] = isset($config[ 'match' ][ 'ip' ]) ? $config[ 'match' ][ 'ip' ] : false; |
|
| 38 | + $config['match']['ip'] = isset($config['match']['ip']) ? $config['match']['ip'] : false; |
|
| 39 | 39 | |
| 40 | 40 | // Re-Define Session Name base on Match IP |
| 41 | - $config[ 'name' ] = $config[ 'name' ] . ':' . ($config[ 'match' ][ 'ip' ] ? $_SERVER[ 'REMOTE_ADDR' ] . ':' : ''); |
|
| 42 | - $config[ 'name' ] = rtrim($config[ 'name' ], ':'); |
|
| 41 | + $config['name'] = $config['name'] . ':' . ($config['match']['ip'] ? $_SERVER['REMOTE_ADDR'] . ':' : ''); |
|
| 42 | + $config['name'] = rtrim($config['name'], ':'); |
|
| 43 | 43 | |
| 44 | - if (isset($config[ 'handler' ])) {
|
|
| 45 | - $config[ 'handler' ] = $config[ 'handler' ] === 'files' ? 'file' : $config[ 'handler' ]; |
|
| 44 | + if (isset($config['handler'])) {
|
|
| 45 | + $config['handler'] = $config['handler'] === 'files' ? 'file' : $config['handler']; |
|
| 46 | 46 | // $config[ 'handler' ] = $config[ 'handler' ] === 'memcache' ? 'memcached' : $config[ 'handler' ]; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ($config[ 'handler' ] === 'file') {
|
|
| 50 | - if (isset($config[ 'filePath' ])) {
|
|
| 51 | - $config[ 'filePath' ] = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $config[ 'filePath' ]); |
|
| 49 | + if ($config['handler'] === 'file') {
|
|
| 50 | + if (isset($config['filePath'])) {
|
|
| 51 | + $config['filePath'] = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $config['filePath']); |
|
| 52 | 52 | |
| 53 | - if ( ! is_dir($config[ 'filePath' ])) {
|
|
| 53 | + if ( ! is_dir($config['filePath'])) {
|
|
| 54 | 54 | if (defined('PATH_CACHE')) {
|
| 55 | - $config[ 'filePath' ] = PATH_CACHE . $config[ 'filePath' ]; |
|
| 55 | + $config['filePath'] = PATH_CACHE . $config['filePath']; |
|
| 56 | 56 | } else {
|
| 57 | - $config[ 'filePath' ] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $config[ 'filePath' ]; |
|
| 57 | + $config['filePath'] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $config['filePath']; |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | } elseif (defined('PATH_CACHE')) {
|
| 61 | - $config[ 'filePath' ] = PATH_CACHE . 'sessions'; |
|
| 61 | + $config['filePath'] = PATH_CACHE . 'sessions'; |
|
| 62 | 62 | } else {
|
| 63 | 63 | $this->path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . implode( |
| 64 | 64 | DIRECTORY_SEPARATOR, |
@@ -66,37 +66,37 @@ discard block |
||
| 66 | 66 | ); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $config[ 'filePath' ] = rtrim($config[ 'filePath' ], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 69 | + $config['filePath'] = rtrim($config['filePath'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 70 | 70 | |
| 71 | - if ( ! is_writable($config[ 'filePath' ])) {
|
|
| 72 | - if ( ! file_exists($config[ 'filePath' ])) {
|
|
| 73 | - @mkdir($config[ 'filePath' ], 0777, true); |
|
| 71 | + if ( ! is_writable($config['filePath'])) {
|
|
| 72 | + if ( ! file_exists($config['filePath'])) {
|
|
| 73 | + @mkdir($config['filePath'], 0777, true); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if (empty($config[ 'cookie' ]) AND php_sapi_name() !== 'cli') {
|
|
| 79 | - $config[ 'cookie' ] = [ |
|
| 78 | + if (empty($config['cookie']) AND php_sapi_name() !== 'cli') {
|
|
| 79 | + $config['cookie'] = [ |
|
| 80 | 80 | 'name' => 'o2session', |
| 81 | 81 | 'lifetime' => 7200, |
| 82 | - 'domain' => isset($_SERVER[ 'HTTP_HOST' ]) ? $_SERVER[ 'HTTP_HOST' ] : $_SERVER[ 'SERVER_NAME' ], |
|
| 82 | + 'domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'], |
|
| 83 | 83 | 'path' => '/', |
| 84 | 84 | 'secure' => false, |
| 85 | 85 | 'httpOnly' => false, |
| 86 | 86 | ]; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ( ! isset($config[ 'regenerate' ])) {
|
|
| 90 | - $config[ 'regenerate' ][ 'destroy' ] = false; |
|
| 91 | - $config[ 'regenerate' ][ 'lifetime' ] = 600; |
|
| 89 | + if ( ! isset($config['regenerate'])) {
|
|
| 90 | + $config['regenerate']['destroy'] = false; |
|
| 91 | + $config['regenerate']['lifetime'] = 600; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if ( ! isset($config[ 'lifetime' ])) {
|
|
| 95 | - $config[ 'lifetime' ] = $config[ 'cookie' ][ 'lifetime' ]; |
|
| 94 | + if ( ! isset($config['lifetime'])) {
|
|
| 95 | + $config['lifetime'] = $config['cookie']['lifetime']; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if ( ! isset($config[ 'path' ])) {
|
|
| 99 | - $config[ 'path' ] = '/'; |
|
| 98 | + if ( ! isset($config['path'])) {
|
|
| 99 | + $config['path'] = '/'; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | parent::__construct($config, Config::CAMELCASE_OFFSET); |