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
 * Migrating session handler for migrating from one handler to another. It reads
16
 * from the current handler and writes both the current and new ones.
17
 *
18
 * It ignores errors from the new handler.
19
 *
20
 * @author Ross Motley <ross.motley@amara.com>
21
 * @author Oliver Radwell <oliver.radwell@amara.com>
22
 */
23
class MigratingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
24
{
25
    /**
26
     * @var \SessionHandlerInterface&\SessionUpdateTimestampHandlerInterface
27
     */
28
    private \SessionHandlerInterface $currentHandler;
29
 
30
    /**
31
     * @var \SessionHandlerInterface&\SessionUpdateTimestampHandlerInterface
32
     */
33
    private \SessionHandlerInterface $writeOnlyHandler;
34
 
35
    public function __construct(\SessionHandlerInterface $currentHandler, \SessionHandlerInterface $writeOnlyHandler)
36
    {
37
        if (!$currentHandler instanceof \SessionUpdateTimestampHandlerInterface) {
38
            $currentHandler = new StrictSessionHandler($currentHandler);
39
        }
40
        if (!$writeOnlyHandler instanceof \SessionUpdateTimestampHandlerInterface) {
41
            $writeOnlyHandler = new StrictSessionHandler($writeOnlyHandler);
42
        }
43
 
44
        $this->currentHandler = $currentHandler;
45
        $this->writeOnlyHandler = $writeOnlyHandler;
46
    }
47
 
48
    public function close(): bool
49
    {
50
        $result = $this->currentHandler->close();
51
        $this->writeOnlyHandler->close();
52
 
53
        return $result;
54
    }
55
 
56
    public function destroy(string $sessionId): bool
57
    {
58
        $result = $this->currentHandler->destroy($sessionId);
59
        $this->writeOnlyHandler->destroy($sessionId);
60
 
61
        return $result;
62
    }
63
 
64
    public function gc(int $maxlifetime): int|false
65
    {
66
        $result = $this->currentHandler->gc($maxlifetime);
67
        $this->writeOnlyHandler->gc($maxlifetime);
68
 
69
        return $result;
70
    }
71
 
72
    public function open(string $savePath, string $sessionName): bool
73
    {
74
        $result = $this->currentHandler->open($savePath, $sessionName);
75
        $this->writeOnlyHandler->open($savePath, $sessionName);
76
 
77
        return $result;
78
    }
79
 
80
    public function read(string $sessionId): string
81
    {
82
        // No reading from new handler until switch-over
83
        return $this->currentHandler->read($sessionId);
84
    }
85
 
86
    public function write(string $sessionId, string $sessionData): bool
87
    {
88
        $result = $this->currentHandler->write($sessionId, $sessionData);
89
        $this->writeOnlyHandler->write($sessionId, $sessionData);
90
 
91
        return $result;
92
    }
93
 
94
    public function validateId(string $sessionId): bool
95
    {
96
        // No reading from new handler until switch-over
97
        return $this->currentHandler->validateId($sessionId);
98
    }
99
 
100
    public function updateTimestamp(string $sessionId, string $sessionData): bool
101
    {
102
        $result = $this->currentHandler->updateTimestamp($sessionId, $sessionData);
103
        $this->writeOnlyHandler->updateTimestamp($sessionId, $sessionData);
104
 
105
        return $result;
106
    }
107
}