1 | <?php |
||
12 | class SubsiteState implements Resettable |
||
13 | { |
||
14 | use Injectable; |
||
15 | |||
16 | /** |
||
17 | * @var int|null |
||
18 | */ |
||
19 | protected $subsiteId; |
||
20 | |||
21 | |||
22 | /** |
||
23 | * @var int|null |
||
24 | */ |
||
25 | protected $originalSubsiteId; |
||
26 | |||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | protected $useSessions; |
||
31 | |||
32 | /** |
||
33 | * Get the current subsite ID |
||
34 | * |
||
35 | * @return int|null |
||
36 | */ |
||
37 | public function getSubsiteId() |
||
41 | |||
42 | /** |
||
43 | * Set the current subsite ID, and track the first subsite ID set as the "original". This is used to check |
||
44 | * whether the ID has been changed through a request. |
||
45 | * |
||
46 | * @param int $id |
||
47 | * @return $this |
||
48 | */ |
||
49 | public function setSubsiteId($id) |
||
59 | |||
60 | /** |
||
61 | * Get whether to use sessions for storing the subsite ID |
||
62 | * |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function getUseSessions() |
||
69 | |||
70 | /** |
||
71 | * Set whether to use sessions for storing the subsite ID |
||
72 | * |
||
73 | * @param bool $useSessions |
||
74 | * @return $this |
||
75 | */ |
||
76 | public function setUseSessions($useSessions) |
||
82 | |||
83 | /** |
||
84 | * Get whether the subsite ID has been changed during a request, based on the original and current IDs |
||
85 | * |
||
86 | * @return bool |
||
87 | */ |
||
88 | public function getSubsiteIdWasChanged() |
||
92 | |||
93 | /** |
||
94 | * Perform a given action within the context of a new, isolated state. Modifications are temporary |
||
95 | * and the existing state will be restored afterwards. |
||
96 | * |
||
97 | * @param callable $callback Callback to run. Will be passed the nested state as a parameter |
||
98 | * @return mixed Result of callback |
||
99 | */ |
||
100 | public function withState(callable $callback) |
||
110 | |||
111 | /** |
||
112 | * Reset the local cache of the singleton |
||
113 | */ |
||
114 | public static function reset() |
||
118 | |||
119 | /** |
||
120 | * Reset the local cache of this object |
||
121 | */ |
||
122 | public function resetState() |
||
128 | } |
||
129 |