1 | <?php |
||||
2 | /** |
||||
3 | * This file is part of the O2System Framework package. |
||||
4 | * |
||||
5 | * For the full copyright and license information, please view the LICENSE |
||||
6 | * file that was distributed with this source code. |
||||
7 | * |
||||
8 | * @author Steeve Andrian Salim |
||||
9 | * @copyright Copyright (c) Steeve Andrian Salim |
||||
10 | */ |
||||
11 | |||||
12 | // ------------------------------------------------------------------------ |
||||
13 | |||||
14 | namespace O2System\Session\DataStructures; |
||||
15 | |||||
16 | // ------------------------------------------------------------------------ |
||||
17 | |||||
18 | use O2System\Kernel\DataStructures; |
||||
19 | |||||
20 | /** |
||||
21 | * Class Config |
||||
22 | * |
||||
23 | * @package O2System\Session\Metadata |
||||
24 | */ |
||||
25 | class Config extends DataStructures\Config |
||||
26 | { |
||||
27 | /** |
||||
28 | * Config::__construct |
||||
29 | * |
||||
30 | * @param array $config |
||||
31 | */ |
||||
32 | public function __construct(array $config) |
||||
33 | { |
||||
34 | // Define Session Name |
||||
35 | $config[ 'name' ] = isset($config[ 'name' ]) ? $config[ 'name' ] : 'o2session'; |
||||
36 | |||||
37 | // Define Session Match IP |
||||
38 | $config[ 'match' ][ 'ip' ] = isset($config[ 'match' ][ 'ip' ]) ? $config[ 'match' ][ 'ip' ] : false; |
||||
39 | |||||
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' ], ':'); |
||||
43 | |||||
44 | if (isset($config[ 'handler' ])) { |
||||
45 | $config[ 'handler' ] = $config[ 'handler' ] === 'files' ? 'file' : $config[ 'handler' ]; |
||||
46 | // $config[ 'handler' ] = $config[ 'handler' ] === 'memcache' ? 'memcached' : $config[ 'handler' ]; |
||||
47 | } |
||||
48 | |||||
49 | if ($config[ 'handler' ] === 'file') { |
||||
50 | if (isset($config[ 'filePath' ])) { |
||||
51 | $config[ 'filePath' ] = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $config[ 'filePath' ]); |
||||
52 | |||||
53 | if ( ! is_dir($config[ 'filePath' ])) { |
||||
54 | if (defined('PATH_CACHE')) { |
||||
55 | $config[ 'filePath' ] = PATH_CACHE . $config[ 'filePath' ]; |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
56 | } else { |
||||
57 | $config[ 'filePath' ] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $config[ 'filePath' ]; |
||||
58 | } |
||||
59 | } |
||||
60 | } elseif (defined('PATH_CACHE')) { |
||||
61 | $config[ 'filePath' ] = PATH_CACHE . 'sessions'; |
||||
62 | } else { |
||||
63 | $this->path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . implode( |
||||
0 ignored issues
–
show
|
|||||
64 | DIRECTORY_SEPARATOR, |
||||
65 | ['o2system', 'cache', 'sessions'] |
||||
66 | ); |
||||
67 | } |
||||
68 | |||||
69 | $config[ 'filePath' ] = rtrim($config[ 'filePath' ], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
||||
70 | |||||
71 | if ( ! is_writable($config[ 'filePath' ])) { |
||||
72 | if ( ! file_exists($config[ 'filePath' ])) { |
||||
73 | @mkdir($config[ 'filePath' ], 0777, true); |
||||
0 ignored issues
–
show
It seems like you do not handle an error condition for
mkdir() . This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||||
74 | } |
||||
75 | } |
||||
76 | } |
||||
77 | |||||
78 | if (empty($config[ 'cookie' ]) AND php_sapi_name() !== 'cli') { |
||||
79 | $config[ 'cookie' ] = [ |
||||
80 | 'name' => 'o2session', |
||||
81 | 'lifetime' => 7200, |
||||
82 | 'domain' => isset($_SERVER[ 'HTTP_HOST' ]) ? $_SERVER[ 'HTTP_HOST' ] : $_SERVER[ 'SERVER_NAME' ], |
||||
83 | 'path' => '/', |
||||
84 | 'secure' => false, |
||||
85 | 'httpOnly' => false, |
||||
86 | ]; |
||||
87 | } |
||||
88 | |||||
89 | if ( ! isset($config[ 'regenerate' ])) { |
||||
90 | $config[ 'regenerate' ][ 'destroy' ] = false; |
||||
91 | $config[ 'regenerate' ][ 'lifetime' ] = 600; |
||||
92 | } |
||||
93 | |||||
94 | if ( ! isset($config[ 'lifetime' ])) { |
||||
95 | $config[ 'lifetime' ] = $config[ 'cookie' ][ 'lifetime' ]; |
||||
96 | } |
||||
97 | |||||
98 | if ( ! isset($config[ 'path' ])) { |
||||
99 | $config[ 'path' ] = '/'; |
||||
100 | } |
||||
101 | |||||
102 | parent::__construct($config, Config::CAMELCASE_OFFSET); |
||||
103 | } |
||||
104 | } |