Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | 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
 * Adds basic `SessionUpdateTimestampHandlerInterface` behaviors to another `SessionHandlerInterface`.
16
 *
17
 * @author Nicolas Grekas <p@tchwork.com>
18
 */
19
class StrictSessionHandler extends AbstractSessionHandler
20
{
21
    private \SessionHandlerInterface $handler;
22
    private bool $doDestroy;
23
 
24
    public function __construct(\SessionHandlerInterface $handler)
25
    {
26
        if ($handler instanceof \SessionUpdateTimestampHandlerInterface) {
27
            throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', get_debug_type($handler), self::class));
28
        }
29
 
30
        $this->handler = $handler;
31
    }
32
 
33
    /**
34
     * Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
35
     *
36
     * @internal
37
     */
38
    public function isWrapper(): bool
39
    {
40
        return $this->handler instanceof \SessionHandler;
41
    }
42
 
43
    public function open(string $savePath, string $sessionName): bool
44
    {
45
        parent::open($savePath, $sessionName);
46
 
47
        return $this->handler->open($savePath, $sessionName);
48
    }
49
 
50
    protected function doRead(string $sessionId): string
51
    {
52
        return $this->handler->read($sessionId);
53
    }
54
 
55
    public function updateTimestamp(string $sessionId, string $data): bool
56
    {
57
        return $this->write($sessionId, $data);
58
    }
59
 
60
    protected function doWrite(string $sessionId, string $data): bool
61
    {
62
        return $this->handler->write($sessionId, $data);
63
    }
64
 
65
    public function destroy(string $sessionId): bool
66
    {
67
        $this->doDestroy = true;
68
        $destroyed = parent::destroy($sessionId);
69
 
70
        return $this->doDestroy ? $this->doDestroy($sessionId) : $destroyed;
71
    }
72
 
73
    protected function doDestroy(string $sessionId): bool
74
    {
75
        $this->doDestroy = false;
76
 
77
        return $this->handler->destroy($sessionId);
78
    }
79
 
80
    public function close(): bool
81
    {
82
        return $this->handler->close();
83
    }
84
 
85
    public function gc(int $maxlifetime): int|false
86
    {
87
        return $this->handler->gc($maxlifetime);
88
    }
89
}