Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 688 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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
 * Native session handler using PHP's built in file storage.
16
 *
17
 * @author Drak <drak@zikula.org>
18
 */
19
class NativeFileSessionHandler extends \SessionHandler
20
{
21
    /**
688 lars 22
     * @param string|null $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
148 lars 25
     *
26
     * @see https://php.net/session.configuration#ini.session.save-path for further details.
27
     *
28
     * @throws \InvalidArgumentException On invalid $savePath
29
     * @throws \RuntimeException         When failing to create the save directory
30
     */
31
    public function __construct(string $savePath = null)
32
    {
33
        $baseDir = $savePath ??= \ini_get('session.save_path');
34
 
35
        if ($count = substr_count($savePath, ';')) {
36
            if ($count > 2) {
37
                throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'.', $savePath));
38
            }
39
 
40
            // characters after last ';' are the path
41
            $baseDir = ltrim(strrchr($savePath, ';'), ';');
42
        }
43
 
44
        if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) {
45
            throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $baseDir));
46
        }
47
 
991 lars 48
        if ($savePath !== \ini_get('session.save_path')) {
49
            ini_set('session.save_path', $savePath);
50
        }
51
        if ('files' !== \ini_get('session.save_handler')) {
52
            ini_set('session.save_handler', 'files');
53
        }
148 lars 54
    }
55
}