|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Xervice\Session\Business; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; |
|
10
|
|
|
use Xervice\Core\Business\Model\Factory\AbstractBusinessFactory; |
|
11
|
|
|
use Xervice\Session\SessionDependencyProvider; |
|
12
|
|
|
|
|
13
|
|
|
class SessionBusinessFactory extends AbstractBusinessFactory |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var Session |
|
17
|
|
|
*/ |
|
18
|
|
|
private $session; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @return \Symfony\Component\HttpFoundation\Session\Session |
|
22
|
|
|
* @throws \InvalidArgumentException |
|
23
|
|
|
* @throws \RuntimeException |
|
24
|
|
|
*/ |
|
25
|
2 |
|
public function getSession(): Session |
|
26
|
|
|
{ |
|
27
|
2 |
|
if ($this->session === null) { |
|
28
|
1 |
|
$this->session = $this->createSession(); |
|
29
|
|
|
} |
|
30
|
2 |
|
return $this->session; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return \Symfony\Component\HttpFoundation\Session\Session |
|
35
|
|
|
* @throws \RuntimeException |
|
36
|
|
|
* @throws \InvalidArgumentException |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function createSession(): Session |
|
39
|
|
|
{ |
|
40
|
1 |
|
return new Session( |
|
41
|
1 |
|
$this->createSessionStorage() |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage |
|
47
|
|
|
* @throws \RuntimeException |
|
48
|
|
|
* @throws \InvalidArgumentException |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function createSessionStorage(): SessionStorageInterface |
|
51
|
|
|
{ |
|
52
|
1 |
|
return new NativeSessionStorage( |
|
53
|
1 |
|
[], |
|
54
|
1 |
|
$this->getSessionHandler() |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return \SessionHandlerInterface |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function getSessionHandler(): \SessionHandlerInterface |
|
62
|
|
|
{ |
|
63
|
1 |
|
return $this->getDependency(SessionDependencyProvider::SESSION_HANDLER); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|