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 * Native session handler using PHP's built in file storage.
17 * @author Drak <drak@zikula.org>
19 class NativeFileSessionHandler extends NativeSessionHandler
22 * @param string $savePath Path of directory to save session files
23 * Default null will leave setting as defined by PHP.
24 * '/path', 'N;/path', or 'N;octal-mode;/path
26 * @see http://php.net/session.configuration.php#ini.session.save-path for further details.
28 * @throws \InvalidArgumentException On invalid $savePath
29 * @throws \RuntimeException When failing to create the save directory
31 public function __construct($savePath = null)
33 if (null === $savePath) {
34 $savePath = ini_get('session.save_path');
39 if ($count = substr_count($savePath, ';')) {
41 throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'', $savePath));
44 // characters after last ';' are the path
45 $baseDir = ltrim(strrchr($savePath, ';'), ';');
48 if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) {
49 throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $baseDir));
52 ini_set('session.save_path', $savePath);
53 ini_set('session.save_handler', 'files');