1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Xervice\Session\Business; |
5
|
|
|
|
6
|
|
|
use Xervice\Core\Business\Model\Facade\AbstractFacade; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @method \Xervice\Session\Business\SessionBusinessFactory getFactory() |
11
|
|
|
* @method string getId() |
12
|
|
|
* @method bool has($name) |
13
|
|
|
* @method mixed get($name, $default = null) |
14
|
|
|
* @method void set($name, $value) |
15
|
|
|
* @method mixed remove($name) |
16
|
|
|
* @method void clear() |
17
|
|
|
*/ |
18
|
|
|
class SessionFacade extends AbstractFacade |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param string $name |
22
|
|
|
* @param array $arguments |
23
|
|
|
* |
24
|
|
|
* @return mixed |
25
|
|
|
* @throws \InvalidArgumentException |
26
|
|
|
* @throws \RuntimeException |
27
|
|
|
*/ |
28
|
1 |
|
public function __call(string $name, array $arguments) |
29
|
|
|
{ |
30
|
1 |
|
return $this->isSessionMethodExist($name) ? $this->callSessionMethod($name, $arguments) : null; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Initialize session |
35
|
|
|
* |
36
|
|
|
* @api |
37
|
|
|
* @throws \InvalidArgumentException |
38
|
|
|
* @throws \RuntimeException |
39
|
|
|
*/ |
40
|
2 |
|
public function initSession(): void |
41
|
|
|
{ |
42
|
2 |
|
$this->getFactory()->getSession()->start(); |
43
|
2 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $name |
47
|
|
|
* |
48
|
|
|
* @return bool |
49
|
|
|
* @throws \RuntimeException |
50
|
|
|
* @throws \InvalidArgumentException |
51
|
|
|
*/ |
52
|
1 |
|
private function isSessionMethodExist(string $name): bool |
53
|
|
|
{ |
54
|
1 |
|
return \method_exists($this->getFactory()->getSession(), $name); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $name |
59
|
|
|
* @param array $arguments |
60
|
|
|
* |
61
|
|
|
* @return mixed |
62
|
|
|
* @throws \RuntimeException |
63
|
|
|
* @throws \InvalidArgumentException |
64
|
|
|
*/ |
65
|
1 |
|
private function callSessionMethod(string $name, array $arguments) |
66
|
|
|
{ |
67
|
|
|
return \call_user_func_array( |
68
|
|
|
[ |
69
|
1 |
|
$this->getFactory()->getSession(), |
70
|
1 |
|
$name |
71
|
|
|
], |
72
|
1 |
|
$arguments |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|