1 | <?php |
||
33 | class Lock |
||
34 | { |
||
35 | /** |
||
36 | * Cookie |
||
37 | * |
||
38 | * @var array |
||
39 | * |
||
40 | * @access protected |
||
41 | */ |
||
42 | protected $cookie; |
||
43 | |||
44 | /** |
||
45 | * Session key for lock status |
||
46 | * |
||
47 | * @var string |
||
48 | * |
||
49 | * @access protected |
||
50 | */ |
||
51 | protected $key = 'vperyod/simplelock:unlocked'; |
||
52 | |||
53 | /** |
||
54 | * Session key for intent |
||
55 | * |
||
56 | * @var string |
||
57 | * |
||
58 | * @access protected |
||
59 | */ |
||
60 | protected $intent = 'vperyod/simplelock:intent'; |
||
61 | |||
62 | /** |
||
63 | * Create a session lock |
||
64 | * |
||
65 | * @access public |
||
66 | */ |
||
67 | 2 | public function __construct() |
|
71 | |||
72 | /** |
||
73 | * Unlock a session |
||
74 | * |
||
75 | * @return void |
||
76 | * |
||
77 | * @access public |
||
78 | */ |
||
79 | 1 | public function unlock() |
|
83 | |||
84 | /** |
||
85 | * Lock a session |
||
86 | * |
||
87 | * @return void |
||
88 | * |
||
89 | * @access public |
||
90 | */ |
||
91 | 1 | public function lock() |
|
95 | |||
96 | /** |
||
97 | * Set intent |
||
98 | * |
||
99 | * @param Request $request intended request |
||
100 | * |
||
101 | * @return void |
||
102 | * |
||
103 | * @access public |
||
104 | */ |
||
105 | 1 | public function setIntent(Request $request) |
|
109 | |||
110 | /** |
||
111 | * Get and clear intent |
||
112 | * |
||
113 | * @return null | Request |
||
114 | * |
||
115 | * @access public |
||
116 | */ |
||
117 | 1 | public function getIntent() |
|
126 | |||
127 | /** |
||
128 | * Is session unlocked? |
||
129 | * |
||
130 | * @return bool |
||
131 | * |
||
132 | * @access public |
||
133 | */ |
||
134 | 1 | public function isUnlocked() |
|
139 | |||
140 | /** |
||
141 | * Resume session |
||
142 | * |
||
143 | * @return bool |
||
144 | * |
||
145 | * @access protected |
||
146 | */ |
||
147 | 2 | protected function session() |
|
151 | } |
||
152 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: