4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
15 * NativeFileSessionHandler.
17 * Native session handler using PHP's built in file storage.
19 * @author Drak <drak@zikula.org>
21 class NativeFileSessionHandler extends NativeSessionHandler
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
30 * @see http://php.net/session.configuration.php#ini.session.save-path for further details.
32 * @throws \InvalidArgumentException On invalid $savePath
34 public function __construct($savePath = null)
36 if (null === $savePath) {
37 $savePath = ini_get('session.save_path');
42 if ($count = substr_count($savePath, ';')) {
44 throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'', $savePath));
47 // characters after last ';' are the path
48 $baseDir = ltrim(strrchr($savePath, ';'), ';');
51 if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) {
52 throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $baseDir));
55 ini_set('session.save_path', $savePath);
56 ini_set('session.save_handler', 'files');