1: <?php
2:
3: /*
4: * This file is part of the Symfony package.
5: *
6: * (c) Fabien Potencier <fabien@symfony.com>
7: *
8: * For the full copyright and license information, please view the LICENSE
9: * file that was distributed with this source code.
10: */
11:
12: namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
13:
14: /**
15: * NativeFileSessionHandler.
16: *
17: * Native session handler using PHP's built in file storage.
18: *
19: * @author Drak <drak@zikula.org>
20: */
21: class NativeFileSessionHandler extends NativeSessionHandler
22: {
23: /**
24: * Constructor.
25: *
26: * @param string $savePath Path of directory to save session files.
27: * Default null will leave setting as defined by PHP.
28: * '/path', 'N;/path', or 'N;octal-mode;/path
29: *
30: * @see http://php.net/session.configuration.php#ini.session.save-path for further details.
31: *
32: * @throws \InvalidArgumentException On invalid $savePath
33: */
34: public function __construct($savePath = null)
35: {
36: if (null === $savePath) {
37: $savePath = ini_get('session.save_path');
38: }
39:
40: $baseDir = $savePath;
41:
42: if ($count = substr_count($savePath, ';')) {
43: if ($count > 2) {
44: throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'', $savePath));
45: }
46:
47: // characters after last ';' are the path
48: $baseDir = ltrim(strrchr($savePath, ';'), ';');
49: }
50:
51: if ($baseDir && !is_dir($baseDir)) {
52: mkdir($baseDir, 0777, true);
53: }
54:
55: ini_set('session.save_path', $savePath);
56: ini_set('session.save_handler', 'files');
57: }
58: }
59: