1 | <?php |
||
13 | class Form |
||
14 | { |
||
15 | /** |
||
16 | * @var string $formId The form id |
||
17 | */ |
||
18 | protected $formId = ''; |
||
19 | |||
20 | /** |
||
21 | * Constructor |
||
22 | * Define form's id. |
||
23 | * |
||
24 | * @param string $formId The form id |
||
25 | */ |
||
26 | public function __construct($formId) |
||
30 | |||
31 | /** |
||
32 | * Save the form's token |
||
33 | * |
||
34 | * @param \stdClass $saveInfos Infos about token (id and expire time) |
||
35 | * |
||
36 | * @return void |
||
37 | */ |
||
38 | protected function saveToken($saveInfos) |
||
43 | |||
44 | /** |
||
45 | * Save a token in php session |
||
46 | * |
||
47 | * @global array $_SESSION |
||
48 | * |
||
49 | * @param \stdClass $saveInfos Infos about token (id and expire time) |
||
50 | * |
||
51 | * @return void |
||
52 | */ |
||
53 | protected function saveTokenInSession($saveInfos) |
||
59 | |||
60 | /** |
||
61 | * Get the token informations |
||
62 | * |
||
63 | * @return \stdClass |
||
64 | */ |
||
65 | protected function getToken() |
||
70 | |||
71 | /** |
||
72 | * Get a token from the session |
||
73 | * |
||
74 | * @global array $_SESSION |
||
75 | * |
||
76 | * @return \stdClass |
||
77 | * |
||
78 | * @throws Exception If there are no token |
||
79 | */ |
||
80 | protected function getTokenFromSession() |
||
94 | |||
95 | /** |
||
96 | * Create a token for the form and return the token |
||
97 | * |
||
98 | * @return string |
||
99 | * |
||
100 | * @throws Exception If the form id is undefined |
||
101 | */ |
||
102 | public function createToken() |
||
118 | |||
119 | /** |
||
120 | * Check the token receive with the generated token |
||
121 | * |
||
122 | * @param string $tokenToCheck The token receive from user |
||
123 | * @param int $timeExp (default 15) time on minute which the token is valid |
||
124 | * |
||
125 | * @return boolean |
||
126 | */ |
||
127 | public function checkToken($tokenToCheck, $timeExp = 15) |
||
149 | |||
150 | /** |
||
151 | * Check if the form has a token |
||
152 | * |
||
153 | * @return boolean |
||
154 | */ |
||
155 | public function hasToken() |
||
165 | } |
||
166 |