@@ -9,18 +9,18 @@ |
||
9 | 9 | |
10 | 10 | class Cookies implements RequestInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * get parameter |
|
14 | - * @param string $name |
|
15 | - * @param string $default |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function get(string $name, string $default = null) : string |
|
19 | - { |
|
20 | - if (isset($_COOKIE[$name]) && $_COOKIE[$name] != '') { |
|
21 | - return $_COOKIE[$name]; |
|
22 | - } else if ($default !== null) { |
|
23 | - return $default; |
|
24 | - } |
|
25 | - } |
|
12 | + /** |
|
13 | + * get parameter |
|
14 | + * @param string $name |
|
15 | + * @param string $default |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function get(string $name, string $default = null) : string |
|
19 | + { |
|
20 | + if (isset($_COOKIE[$name]) && $_COOKIE[$name] != '') { |
|
21 | + return $_COOKIE[$name]; |
|
22 | + } else if ($default !== null) { |
|
23 | + return $default; |
|
24 | + } |
|
25 | + } |
|
26 | 26 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | |
152 | 152 | error_reporting($iLevel); |
153 | 153 | |
154 | - set_error_handler(function ($iErrNo, $sErrStr, $sErrFile, $iErrLine) |
|
154 | + set_error_handler(function($iErrNo, $sErrStr, $sErrFile, $iErrLine) |
|
155 | 155 | { |
156 | 156 | $aContext = array('file' => $sErrFile, 'line' => $iErrLine); |
157 | 157 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | self::_initLogFile(); |
217 | 217 | self::$_bActivateException = true; |
218 | 218 | |
219 | - set_exception_handler(function (\Exception $oException) |
|
219 | + set_exception_handler(function(\Exception $oException) |
|
220 | 220 | { |
221 | 221 | $aContext = array('file' => $oException->getFile(), 'line' => $oException->getLine()); |
222 | 222 | self::getInstance()->critical($oException->getMessage(), $aContext); |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | else { |
413 | 413 | |
414 | 414 | if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) { |
415 | - error_log(Bash::setColor('############### ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . ' ###############', 'cyan')); |
|
415 | + error_log(Bash::setColor('############### '.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].' ###############', 'cyan')); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | } |
@@ -254,8 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public static function setKindOfReportLog(string $sKindOfReportLog) |
256 | 256 | { |
257 | - if ($sKindOfReportLog === 'screen' || $sKindOfReportLog === 'all') { self::$_sKindOfReportLog = $sKindOfReportLog; } |
|
258 | - else { self::$_sKindOfReportLog = 'error_log'; } |
|
257 | + if ($sKindOfReportLog === 'screen' || $sKindOfReportLog === 'all') { self::$_sKindOfReportLog = $sKindOfReportLog; } else { self::$_sKindOfReportLog = 'error_log'; } |
|
259 | 258 | } |
260 | 259 | |
261 | 260 | /** |
@@ -278,12 +277,9 @@ discard block |
||
278 | 277 | */ |
279 | 278 | public static function getTranslateErrorCode(int $iCode) : string |
280 | 279 | { |
281 | - if ($iCode === 1 && $iCode === 16 && $iCode === 256 && $iCode === 4096) { return LogLevel::ERROR; } |
|
282 | - else if ($iCode === 2 && $iCode === 32 && $iCode === 128 && $iCode === 512) { return LogLevel::WARNING; } |
|
283 | - else if ($iCode === 4 && $iCode === 64) { return LogLevel::EMERGENCY; } |
|
284 | - else if ($iCode === 8 && $iCode === 1024) { return LogLevel::NOTICE; } |
|
285 | - else if ($iCode === 2048 && $iCode === 8192 && $iCode === 16384) { return LogLevel::INFO; } |
|
286 | - else return LogLevel::DEBUG; |
|
280 | + if ($iCode === 1 && $iCode === 16 && $iCode === 256 && $iCode === 4096) { return LogLevel::ERROR; } else if ($iCode === 2 && $iCode === 32 && $iCode === 128 && $iCode === 512) { return LogLevel::WARNING; } else if ($iCode === 4 && $iCode === 64) { return LogLevel::EMERGENCY; } else if ($iCode === 8 && $iCode === 1024) { return LogLevel::NOTICE; } else if ($iCode === 2048 && $iCode === 8192 && $iCode === 16384) { return LogLevel::INFO; } else { |
|
281 | + return LogLevel::DEBUG; |
|
282 | + } |
|
287 | 283 | } |
288 | 284 | |
289 | 285 | /** |
@@ -408,8 +404,7 @@ discard block |
||
408 | 404 | if (defined('BASH_CALLED')) { |
409 | 405 | |
410 | 406 | error_log(Bash::setColor('############### '.BASH_CALLED.' ###############', 'cyan')); |
411 | - } |
|
412 | - else { |
|
407 | + } else { |
|
413 | 408 | |
414 | 409 | if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) { |
415 | 410 | error_log(Bash::setColor('############### ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . ' ###############', 'cyan')); |
@@ -34,418 +34,418 @@ |
||
34 | 34 | */ |
35 | 35 | class Debug extends AbstractLogger |
36 | 36 | { |
37 | - /** |
|
38 | - * variable to activate or not the debug |
|
39 | - * @var boolean |
|
40 | - */ |
|
41 | - private static $_bActivateDebug = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * variable to activate or not the error |
|
45 | - * @var boolean |
|
46 | - */ |
|
47 | - private static $_bActivateError = false; |
|
48 | - |
|
49 | - /** |
|
50 | - * variable to activate or not the exception |
|
51 | - * @var boolean |
|
52 | - */ |
|
53 | - private static $_bActivateException = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * variable to activate or not the debug |
|
57 | - * @var boolean |
|
58 | - */ |
|
59 | - private static $_sFileLog = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * first or not activation |
|
63 | - * @var boolean |
|
64 | - */ |
|
65 | - private static $_bFirstActivation = true; |
|
66 | - |
|
67 | - /** |
|
68 | - * kind of report log |
|
69 | - * @var string error_log|screen|all |
|
70 | - */ |
|
71 | - private static $_sKindOfReportLog = 'error_log'; |
|
72 | - |
|
73 | - /** |
|
74 | - * instance of logger |
|
75 | - * @var \Venus\lib\Debug |
|
76 | - */ |
|
77 | - private static $_oInstance; |
|
37 | + /** |
|
38 | + * variable to activate or not the debug |
|
39 | + * @var boolean |
|
40 | + */ |
|
41 | + private static $_bActivateDebug = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * variable to activate or not the error |
|
45 | + * @var boolean |
|
46 | + */ |
|
47 | + private static $_bActivateError = false; |
|
48 | + |
|
49 | + /** |
|
50 | + * variable to activate or not the exception |
|
51 | + * @var boolean |
|
52 | + */ |
|
53 | + private static $_bActivateException = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * variable to activate or not the debug |
|
57 | + * @var boolean |
|
58 | + */ |
|
59 | + private static $_sFileLog = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * first or not activation |
|
63 | + * @var boolean |
|
64 | + */ |
|
65 | + private static $_bFirstActivation = true; |
|
66 | + |
|
67 | + /** |
|
68 | + * kind of report log |
|
69 | + * @var string error_log|screen|all |
|
70 | + */ |
|
71 | + private static $_sKindOfReportLog = 'error_log'; |
|
72 | + |
|
73 | + /** |
|
74 | + * instance of logger |
|
75 | + * @var \Venus\lib\Debug |
|
76 | + */ |
|
77 | + private static $_oInstance; |
|
78 | 78 | |
79 | - /** |
|
80 | - * Send back the isntance or create it |
|
81 | - * |
|
82 | - * @access public |
|
83 | - */ |
|
84 | - public static function getInstance() : Debug |
|
85 | - { |
|
86 | - if (!(self::$_oInstance instanceof self)) { self::$_oInstance = new self(); } |
|
79 | + /** |
|
80 | + * Send back the isntance or create it |
|
81 | + * |
|
82 | + * @access public |
|
83 | + */ |
|
84 | + public static function getInstance() : Debug |
|
85 | + { |
|
86 | + if (!(self::$_oInstance instanceof self)) { self::$_oInstance = new self(); } |
|
87 | 87 | |
88 | - return self::$_oInstance; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * activate debug |
|
93 | - * |
|
94 | - * @access public |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public static function activateDebug() |
|
98 | - { |
|
99 | - if (self::$_bFirstActivation === true) { |
|
100 | - |
|
101 | - self::_setFileNameInErrorFile(); |
|
102 | - self::$_bFirstActivation = false; |
|
103 | - } |
|
104 | - |
|
105 | - self::_initLogFile(); |
|
106 | - self::$_bActivateDebug = true; |
|
107 | - self::activateError(E_ALL); |
|
108 | - self::activateException(E_ALL); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * activate debug |
|
113 | - * |
|
114 | - * @access public |
|
115 | - * @return void |
|
116 | - */ |
|
117 | - public static function deactivateDebug() |
|
118 | - { |
|
119 | - self::$_bActivateDebug = false; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * check if debug is activate or not |
|
124 | - * |
|
125 | - * @access public |
|
126 | - * @return boolean |
|
127 | - */ |
|
128 | - public static function isDebug() : bool |
|
129 | - { |
|
130 | - return self::$_bActivateDebug; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * activate error reporting |
|
135 | - * |
|
136 | - * @access public |
|
137 | - * @param int $iLevel level of error |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - public static function activateError($iLevel) |
|
141 | - { |
|
142 | - if (self::$_bFirstActivation === true) { |
|
143 | - |
|
144 | - self::_setFileNameInErrorFile(); |
|
145 | - self::$_bFirstActivation = false; |
|
146 | - } |
|
147 | - |
|
148 | - self::_initLogFile(); |
|
149 | - self::$_bActivateError = true; |
|
150 | - |
|
151 | - error_reporting($iLevel); |
|
152 | - |
|
153 | - set_error_handler(function ($iErrNo, $sErrStr, $sErrFile, $iErrLine) |
|
154 | - { |
|
155 | - $aContext = array('file' => $sErrFile, 'line' => $iErrLine); |
|
156 | - |
|
157 | - $sType = self::getTranslateErrorCode($iErrNo); |
|
158 | - |
|
159 | - self::getInstance()->$sType($sErrStr, $aContext); |
|
160 | - |
|
161 | - return true; |
|
162 | - }, $iLevel); |
|
163 | - |
|
164 | - register_shutdown_function(function() |
|
165 | - { |
|
166 | - if (null !== ($aLastError = error_get_last())) { |
|
167 | - |
|
168 | - $aContext = array('file' => $aLastError['file'], 'line' => $aLastError['line']); |
|
169 | - |
|
170 | - $sType = self::getTranslateErrorCode($aLastError['type']); |
|
171 | - |
|
172 | - self::getInstance()->$sType($aLastError['message'], $aContext); |
|
173 | - } |
|
174 | - }); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * activate error reporting |
|
179 | - * |
|
180 | - * @access public |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - public static function deactivateError() |
|
184 | - { |
|
185 | - self::$_bActivateError = false; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * check if error reporting is activate or not |
|
190 | - * |
|
191 | - * @access public |
|
192 | - * @return boolean |
|
193 | - */ |
|
194 | - public static function isError() : bool |
|
195 | - { |
|
196 | - return self::$_bActivateError; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * activate Exception |
|
202 | - * |
|
203 | - * @access public |
|
204 | - * @param int $iLevel level of error |
|
205 | - * @return void |
|
206 | - */ |
|
207 | - public static function activateException(int $iLevel) |
|
208 | - { |
|
209 | - if (self::$_bFirstActivation === true) { |
|
210 | - |
|
211 | - self::_setFileNameInErrorFile(); |
|
212 | - self::$_bFirstActivation = false; |
|
213 | - } |
|
214 | - |
|
215 | - self::_initLogFile(); |
|
216 | - self::$_bActivateException = true; |
|
217 | - |
|
218 | - set_exception_handler(function (\Exception $oException) |
|
219 | - { |
|
220 | - $aContext = array('file' => $oException->getFile(), 'line' => $oException->getLine()); |
|
221 | - self::getInstance()->critical($oException->getMessage(), $aContext); |
|
222 | - }); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * activate Exception |
|
227 | - * |
|
228 | - * @access public |
|
229 | - * @return void |
|
230 | - */ |
|
231 | - public static function deactivateException() |
|
232 | - { |
|
233 | - self::$_bActivateException = false; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * check if Exception is activate or not |
|
238 | - * |
|
239 | - * @access public |
|
240 | - * @return boolean |
|
241 | - */ |
|
242 | - public static function isException() : bool |
|
243 | - { |
|
244 | - return self::$_bActivateException; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * set the kind of report Log |
|
249 | - * |
|
250 | - * @access public |
|
251 | - * @param string $sKindOfReportLog |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - public static function setKindOfReportLog(string $sKindOfReportLog) |
|
255 | - { |
|
256 | - if ($sKindOfReportLog === 'screen' || $sKindOfReportLog === 'all') { self::$_sKindOfReportLog = $sKindOfReportLog; } |
|
257 | - else { self::$_sKindOfReportLog = 'error_log'; } |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * get the kind of report Log |
|
262 | - * |
|
263 | - * @access public |
|
264 | - * @return string |
|
265 | - */ |
|
266 | - public static function getKindOfReportLog() : string |
|
267 | - { |
|
268 | - return self::$_sKindOfReportLog; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * get the code by LogLevel adapt to the PSR-3 |
|
273 | - * |
|
274 | - * @access public |
|
275 | - * @param int $iCode |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - public static function getTranslateErrorCode(int $iCode) : string |
|
279 | - { |
|
280 | - if ($iCode === 1 && $iCode === 16 && $iCode === 256 && $iCode === 4096) { return LogLevel::ERROR; } |
|
281 | - else if ($iCode === 2 && $iCode === 32 && $iCode === 128 && $iCode === 512) { return LogLevel::WARNING; } |
|
282 | - else if ($iCode === 4 && $iCode === 64) { return LogLevel::EMERGENCY; } |
|
283 | - else if ($iCode === 8 && $iCode === 1024) { return LogLevel::NOTICE; } |
|
284 | - else if ($iCode === 2048 && $iCode === 8192 && $iCode === 16384) { return LogLevel::INFO; } |
|
285 | - else return LogLevel::DEBUG; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * System is unusable. |
|
290 | - * |
|
291 | - * @param string $message |
|
292 | - * @param array $context |
|
293 | - * @return null |
|
294 | - */ |
|
295 | - public function emergency($message, array $context = array()) |
|
296 | - { |
|
297 | - $this->log(LogLevel::EMERGENCY, $message, $context); |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Action must be taken immediately. |
|
302 | - * |
|
303 | - * Example: Entire website down, database unavailable, etc. This should |
|
304 | - * trigger the SMS alerts and wake you up. |
|
305 | - * |
|
306 | - * @param string $message |
|
307 | - * @param array $context |
|
308 | - * @return null |
|
309 | - */ |
|
310 | - public function alert($message, array $context = array()) |
|
311 | - { |
|
312 | - $this->log(LogLevel::ALERT, $message, $context); |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Critical conditions. |
|
317 | - * |
|
318 | - * Example: Application component unavailable, unexpected exception. |
|
319 | - * |
|
320 | - * @param string $message |
|
321 | - * @param array $context |
|
322 | - * @return null |
|
323 | - */ |
|
324 | - public function critical($message, array $context = array()) |
|
325 | - { |
|
326 | - $this->log(LogLevel::CRITICAL, $message, $context); |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Runtime errors that do not require immediate action but should typically |
|
331 | - * be logged and monitored. |
|
332 | - * |
|
333 | - * @param string $message |
|
334 | - * @param array $context |
|
335 | - * @return null |
|
336 | - */ |
|
337 | - public function error($message, array $context = array()) |
|
338 | - { |
|
339 | - $this->log(LogLevel::ERROR, $message, $context); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Exceptional occurrences that are not errors. |
|
344 | - * |
|
345 | - * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
346 | - * that are not necessarily wrong. |
|
347 | - * |
|
348 | - * @param string $message |
|
349 | - * @param array $context |
|
350 | - * @return null |
|
351 | - */ |
|
352 | - public function warning($message, array $context = array()) |
|
353 | - { |
|
354 | - $this->log(LogLevel::WARNING, $message, $context); |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Normal but significant events. |
|
359 | - * |
|
360 | - * @param string $message |
|
361 | - * @param array $context |
|
362 | - * @return null |
|
363 | - */ |
|
364 | - public function notice($message, array $context = array()) |
|
365 | - { |
|
366 | - $this->log(LogLevel::NOTICE, $message, $context); |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Interesting events. |
|
371 | - * |
|
372 | - * Example: User logs in, SQL logs. |
|
373 | - * |
|
374 | - * @param string $message |
|
375 | - * @param array $context |
|
376 | - * @return null |
|
377 | - */ |
|
378 | - public function info($message, array $context = array()) |
|
379 | - { |
|
380 | - $this->log(LogLevel::INFO, $message, $context); |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * Detailed debug information. |
|
385 | - * |
|
386 | - * @param string $message |
|
387 | - * @param array $context |
|
388 | - * @return null |
|
389 | - */ |
|
390 | - public function debug($message, array $context = array()) |
|
391 | - { |
|
392 | - $this->log(LogLevel::DEBUG, $message, $context); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * set the name of the called |
|
397 | - * |
|
398 | - * @access public |
|
399 | - * @return void |
|
400 | - */ |
|
401 | - private static function _setFileNameInErrorFile() |
|
402 | - { |
|
403 | - /** |
|
404 | - * We see if it's a cli call or a web call |
|
405 | - */ |
|
406 | - |
|
407 | - if (defined('BASH_CALLED')) { |
|
408 | - |
|
409 | - error_log(Bash::setColor('############### '.BASH_CALLED.' ###############', 'cyan')); |
|
410 | - } |
|
411 | - else { |
|
412 | - |
|
413 | - if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) { |
|
414 | - error_log(Bash::setColor('############### ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . ' ###############', 'cyan')); |
|
415 | - } |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * init the log file (error_log) |
|
421 | - * |
|
422 | - * @access private |
|
423 | - * @return void |
|
424 | - */ |
|
425 | - private static function _initLogFile() |
|
426 | - { |
|
427 | - self::$_sFileLog = str_replace(DIRECTORY_SEPARATOR.'bundles'.DIRECTORY_SEPARATOR.'lib', '', __DIR__).DIRECTORY_SEPARATOR. |
|
428 | - "data".DIRECTORY_SEPARATOR."log".DIRECTORY_SEPARATOR."php-error.log"; |
|
429 | - |
|
430 | - ini_set("log_errors", 1); |
|
431 | - ini_set("error_log", self::$_sFileLog); |
|
432 | - |
|
433 | - if (file_exists(self::$_sFileLog) === false) { file_put_contents(self::$_sFileLog, ''); } |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * constructor in private for the singleton |
|
438 | - * |
|
439 | - * @access private |
|
440 | - * @return \Venus\lib\Debug |
|
441 | - */ |
|
442 | - private function __construct() {} |
|
443 | - |
|
444 | - /** |
|
445 | - * not allowed to clone a object |
|
446 | - * |
|
447 | - * @access private |
|
448 | - * @return \Venus\lib\Debug |
|
449 | - */ |
|
450 | - private function __clone() {} |
|
88 | + return self::$_oInstance; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * activate debug |
|
93 | + * |
|
94 | + * @access public |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public static function activateDebug() |
|
98 | + { |
|
99 | + if (self::$_bFirstActivation === true) { |
|
100 | + |
|
101 | + self::_setFileNameInErrorFile(); |
|
102 | + self::$_bFirstActivation = false; |
|
103 | + } |
|
104 | + |
|
105 | + self::_initLogFile(); |
|
106 | + self::$_bActivateDebug = true; |
|
107 | + self::activateError(E_ALL); |
|
108 | + self::activateException(E_ALL); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * activate debug |
|
113 | + * |
|
114 | + * @access public |
|
115 | + * @return void |
|
116 | + */ |
|
117 | + public static function deactivateDebug() |
|
118 | + { |
|
119 | + self::$_bActivateDebug = false; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * check if debug is activate or not |
|
124 | + * |
|
125 | + * @access public |
|
126 | + * @return boolean |
|
127 | + */ |
|
128 | + public static function isDebug() : bool |
|
129 | + { |
|
130 | + return self::$_bActivateDebug; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * activate error reporting |
|
135 | + * |
|
136 | + * @access public |
|
137 | + * @param int $iLevel level of error |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + public static function activateError($iLevel) |
|
141 | + { |
|
142 | + if (self::$_bFirstActivation === true) { |
|
143 | + |
|
144 | + self::_setFileNameInErrorFile(); |
|
145 | + self::$_bFirstActivation = false; |
|
146 | + } |
|
147 | + |
|
148 | + self::_initLogFile(); |
|
149 | + self::$_bActivateError = true; |
|
150 | + |
|
151 | + error_reporting($iLevel); |
|
152 | + |
|
153 | + set_error_handler(function ($iErrNo, $sErrStr, $sErrFile, $iErrLine) |
|
154 | + { |
|
155 | + $aContext = array('file' => $sErrFile, 'line' => $iErrLine); |
|
156 | + |
|
157 | + $sType = self::getTranslateErrorCode($iErrNo); |
|
158 | + |
|
159 | + self::getInstance()->$sType($sErrStr, $aContext); |
|
160 | + |
|
161 | + return true; |
|
162 | + }, $iLevel); |
|
163 | + |
|
164 | + register_shutdown_function(function() |
|
165 | + { |
|
166 | + if (null !== ($aLastError = error_get_last())) { |
|
167 | + |
|
168 | + $aContext = array('file' => $aLastError['file'], 'line' => $aLastError['line']); |
|
169 | + |
|
170 | + $sType = self::getTranslateErrorCode($aLastError['type']); |
|
171 | + |
|
172 | + self::getInstance()->$sType($aLastError['message'], $aContext); |
|
173 | + } |
|
174 | + }); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * activate error reporting |
|
179 | + * |
|
180 | + * @access public |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + public static function deactivateError() |
|
184 | + { |
|
185 | + self::$_bActivateError = false; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * check if error reporting is activate or not |
|
190 | + * |
|
191 | + * @access public |
|
192 | + * @return boolean |
|
193 | + */ |
|
194 | + public static function isError() : bool |
|
195 | + { |
|
196 | + return self::$_bActivateError; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * activate Exception |
|
202 | + * |
|
203 | + * @access public |
|
204 | + * @param int $iLevel level of error |
|
205 | + * @return void |
|
206 | + */ |
|
207 | + public static function activateException(int $iLevel) |
|
208 | + { |
|
209 | + if (self::$_bFirstActivation === true) { |
|
210 | + |
|
211 | + self::_setFileNameInErrorFile(); |
|
212 | + self::$_bFirstActivation = false; |
|
213 | + } |
|
214 | + |
|
215 | + self::_initLogFile(); |
|
216 | + self::$_bActivateException = true; |
|
217 | + |
|
218 | + set_exception_handler(function (\Exception $oException) |
|
219 | + { |
|
220 | + $aContext = array('file' => $oException->getFile(), 'line' => $oException->getLine()); |
|
221 | + self::getInstance()->critical($oException->getMessage(), $aContext); |
|
222 | + }); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * activate Exception |
|
227 | + * |
|
228 | + * @access public |
|
229 | + * @return void |
|
230 | + */ |
|
231 | + public static function deactivateException() |
|
232 | + { |
|
233 | + self::$_bActivateException = false; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * check if Exception is activate or not |
|
238 | + * |
|
239 | + * @access public |
|
240 | + * @return boolean |
|
241 | + */ |
|
242 | + public static function isException() : bool |
|
243 | + { |
|
244 | + return self::$_bActivateException; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * set the kind of report Log |
|
249 | + * |
|
250 | + * @access public |
|
251 | + * @param string $sKindOfReportLog |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + public static function setKindOfReportLog(string $sKindOfReportLog) |
|
255 | + { |
|
256 | + if ($sKindOfReportLog === 'screen' || $sKindOfReportLog === 'all') { self::$_sKindOfReportLog = $sKindOfReportLog; } |
|
257 | + else { self::$_sKindOfReportLog = 'error_log'; } |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * get the kind of report Log |
|
262 | + * |
|
263 | + * @access public |
|
264 | + * @return string |
|
265 | + */ |
|
266 | + public static function getKindOfReportLog() : string |
|
267 | + { |
|
268 | + return self::$_sKindOfReportLog; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * get the code by LogLevel adapt to the PSR-3 |
|
273 | + * |
|
274 | + * @access public |
|
275 | + * @param int $iCode |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + public static function getTranslateErrorCode(int $iCode) : string |
|
279 | + { |
|
280 | + if ($iCode === 1 && $iCode === 16 && $iCode === 256 && $iCode === 4096) { return LogLevel::ERROR; } |
|
281 | + else if ($iCode === 2 && $iCode === 32 && $iCode === 128 && $iCode === 512) { return LogLevel::WARNING; } |
|
282 | + else if ($iCode === 4 && $iCode === 64) { return LogLevel::EMERGENCY; } |
|
283 | + else if ($iCode === 8 && $iCode === 1024) { return LogLevel::NOTICE; } |
|
284 | + else if ($iCode === 2048 && $iCode === 8192 && $iCode === 16384) { return LogLevel::INFO; } |
|
285 | + else return LogLevel::DEBUG; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * System is unusable. |
|
290 | + * |
|
291 | + * @param string $message |
|
292 | + * @param array $context |
|
293 | + * @return null |
|
294 | + */ |
|
295 | + public function emergency($message, array $context = array()) |
|
296 | + { |
|
297 | + $this->log(LogLevel::EMERGENCY, $message, $context); |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Action must be taken immediately. |
|
302 | + * |
|
303 | + * Example: Entire website down, database unavailable, etc. This should |
|
304 | + * trigger the SMS alerts and wake you up. |
|
305 | + * |
|
306 | + * @param string $message |
|
307 | + * @param array $context |
|
308 | + * @return null |
|
309 | + */ |
|
310 | + public function alert($message, array $context = array()) |
|
311 | + { |
|
312 | + $this->log(LogLevel::ALERT, $message, $context); |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Critical conditions. |
|
317 | + * |
|
318 | + * Example: Application component unavailable, unexpected exception. |
|
319 | + * |
|
320 | + * @param string $message |
|
321 | + * @param array $context |
|
322 | + * @return null |
|
323 | + */ |
|
324 | + public function critical($message, array $context = array()) |
|
325 | + { |
|
326 | + $this->log(LogLevel::CRITICAL, $message, $context); |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Runtime errors that do not require immediate action but should typically |
|
331 | + * be logged and monitored. |
|
332 | + * |
|
333 | + * @param string $message |
|
334 | + * @param array $context |
|
335 | + * @return null |
|
336 | + */ |
|
337 | + public function error($message, array $context = array()) |
|
338 | + { |
|
339 | + $this->log(LogLevel::ERROR, $message, $context); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Exceptional occurrences that are not errors. |
|
344 | + * |
|
345 | + * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
346 | + * that are not necessarily wrong. |
|
347 | + * |
|
348 | + * @param string $message |
|
349 | + * @param array $context |
|
350 | + * @return null |
|
351 | + */ |
|
352 | + public function warning($message, array $context = array()) |
|
353 | + { |
|
354 | + $this->log(LogLevel::WARNING, $message, $context); |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Normal but significant events. |
|
359 | + * |
|
360 | + * @param string $message |
|
361 | + * @param array $context |
|
362 | + * @return null |
|
363 | + */ |
|
364 | + public function notice($message, array $context = array()) |
|
365 | + { |
|
366 | + $this->log(LogLevel::NOTICE, $message, $context); |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Interesting events. |
|
371 | + * |
|
372 | + * Example: User logs in, SQL logs. |
|
373 | + * |
|
374 | + * @param string $message |
|
375 | + * @param array $context |
|
376 | + * @return null |
|
377 | + */ |
|
378 | + public function info($message, array $context = array()) |
|
379 | + { |
|
380 | + $this->log(LogLevel::INFO, $message, $context); |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * Detailed debug information. |
|
385 | + * |
|
386 | + * @param string $message |
|
387 | + * @param array $context |
|
388 | + * @return null |
|
389 | + */ |
|
390 | + public function debug($message, array $context = array()) |
|
391 | + { |
|
392 | + $this->log(LogLevel::DEBUG, $message, $context); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * set the name of the called |
|
397 | + * |
|
398 | + * @access public |
|
399 | + * @return void |
|
400 | + */ |
|
401 | + private static function _setFileNameInErrorFile() |
|
402 | + { |
|
403 | + /** |
|
404 | + * We see if it's a cli call or a web call |
|
405 | + */ |
|
406 | + |
|
407 | + if (defined('BASH_CALLED')) { |
|
408 | + |
|
409 | + error_log(Bash::setColor('############### '.BASH_CALLED.' ###############', 'cyan')); |
|
410 | + } |
|
411 | + else { |
|
412 | + |
|
413 | + if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) { |
|
414 | + error_log(Bash::setColor('############### ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . ' ###############', 'cyan')); |
|
415 | + } |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * init the log file (error_log) |
|
421 | + * |
|
422 | + * @access private |
|
423 | + * @return void |
|
424 | + */ |
|
425 | + private static function _initLogFile() |
|
426 | + { |
|
427 | + self::$_sFileLog = str_replace(DIRECTORY_SEPARATOR.'bundles'.DIRECTORY_SEPARATOR.'lib', '', __DIR__).DIRECTORY_SEPARATOR. |
|
428 | + "data".DIRECTORY_SEPARATOR."log".DIRECTORY_SEPARATOR."php-error.log"; |
|
429 | + |
|
430 | + ini_set("log_errors", 1); |
|
431 | + ini_set("error_log", self::$_sFileLog); |
|
432 | + |
|
433 | + if (file_exists(self::$_sFileLog) === false) { file_put_contents(self::$_sFileLog, ''); } |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * constructor in private for the singleton |
|
438 | + * |
|
439 | + * @access private |
|
440 | + * @return \Venus\lib\Debug |
|
441 | + */ |
|
442 | + private function __construct() {} |
|
443 | + |
|
444 | + /** |
|
445 | + * not allowed to clone a object |
|
446 | + * |
|
447 | + * @access private |
|
448 | + * @return \Venus\lib\Debug |
|
449 | + */ |
|
450 | + private function __clone() {} |
|
451 | 451 | } |
@@ -28,126 +28,126 @@ |
||
28 | 28 | */ |
29 | 29 | class Bash |
30 | 30 | { |
31 | - /** |
|
32 | - * color of the text in the bash |
|
33 | - * |
|
34 | - * @access public |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - public static $_aColorCodes = array( |
|
38 | - 'default' => 39, |
|
39 | - 'black' => 30, |
|
40 | - 'red' => 31, |
|
41 | - 'green' => 32, |
|
42 | - 'yellow' => 33, |
|
43 | - 'blue' => 34, |
|
44 | - 'magenta' => 35, |
|
45 | - 'cyan' => 36, |
|
46 | - 'light gray' => 37, |
|
47 | - 'dark gray' => 90, |
|
48 | - 'light red' => 91, |
|
49 | - 'light green' => 92, |
|
50 | - 'light yellow' => 93, |
|
51 | - 'light blue' => 94, |
|
52 | - 'light magenta' => 95, |
|
53 | - 'light cyan' => 96, |
|
54 | - 'white' => 97 |
|
55 | - ); |
|
31 | + /** |
|
32 | + * color of the text in the bash |
|
33 | + * |
|
34 | + * @access public |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + public static $_aColorCodes = array( |
|
38 | + 'default' => 39, |
|
39 | + 'black' => 30, |
|
40 | + 'red' => 31, |
|
41 | + 'green' => 32, |
|
42 | + 'yellow' => 33, |
|
43 | + 'blue' => 34, |
|
44 | + 'magenta' => 35, |
|
45 | + 'cyan' => 36, |
|
46 | + 'light gray' => 37, |
|
47 | + 'dark gray' => 90, |
|
48 | + 'light red' => 91, |
|
49 | + 'light green' => 92, |
|
50 | + 'light yellow' => 93, |
|
51 | + 'light blue' => 94, |
|
52 | + 'light magenta' => 95, |
|
53 | + 'light cyan' => 96, |
|
54 | + 'white' => 97 |
|
55 | + ); |
|
56 | 56 | |
57 | - /** |
|
58 | - * color of the background in the bash |
|
59 | - * |
|
60 | - * @access public |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - public static $_aBackgroundCodes = array( |
|
64 | - 'default' => 49, |
|
65 | - 'black' => 40, |
|
66 | - 'red' => 41, |
|
67 | - 'green' => 42, |
|
68 | - 'yellow' => 43, |
|
69 | - 'blue' => 44, |
|
70 | - 'magenta' => 45, |
|
71 | - 'cyan' => 46, |
|
72 | - 'light gray' => 47, |
|
73 | - 'dark gray' => 100, |
|
74 | - 'light red' => 101, |
|
75 | - 'light green' => 102, |
|
76 | - 'light yellow' => 103, |
|
77 | - 'light blue' => 104, |
|
78 | - 'light magenta' => 105, |
|
79 | - 'light cyan' => 106, |
|
80 | - 'white' => 107 |
|
81 | - ); |
|
57 | + /** |
|
58 | + * color of the background in the bash |
|
59 | + * |
|
60 | + * @access public |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + public static $_aBackgroundCodes = array( |
|
64 | + 'default' => 49, |
|
65 | + 'black' => 40, |
|
66 | + 'red' => 41, |
|
67 | + 'green' => 42, |
|
68 | + 'yellow' => 43, |
|
69 | + 'blue' => 44, |
|
70 | + 'magenta' => 45, |
|
71 | + 'cyan' => 46, |
|
72 | + 'light gray' => 47, |
|
73 | + 'dark gray' => 100, |
|
74 | + 'light red' => 101, |
|
75 | + 'light green' => 102, |
|
76 | + 'light yellow' => 103, |
|
77 | + 'light blue' => 104, |
|
78 | + 'light magenta' => 105, |
|
79 | + 'light cyan' => 106, |
|
80 | + 'white' => 107 |
|
81 | + ); |
|
82 | 82 | |
83 | - /** |
|
84 | - * color of the decoration code in the bash |
|
85 | - * |
|
86 | - * @access public |
|
87 | - * @var array |
|
88 | - */ |
|
89 | - public static $_aDecorationCodes = array( |
|
90 | - 'bold' => '1', |
|
91 | - 'dim' => '2', |
|
92 | - 'underline' => '4', |
|
93 | - 'blink' => '5', |
|
94 | - 'reverse' => '7', |
|
95 | - 'hidden' => '8' |
|
96 | - ); |
|
83 | + /** |
|
84 | + * color of the decoration code in the bash |
|
85 | + * |
|
86 | + * @access public |
|
87 | + * @var array |
|
88 | + */ |
|
89 | + public static $_aDecorationCodes = array( |
|
90 | + 'bold' => '1', |
|
91 | + 'dim' => '2', |
|
92 | + 'underline' => '4', |
|
93 | + 'blink' => '5', |
|
94 | + 'reverse' => '7', |
|
95 | + 'hidden' => '8' |
|
96 | + ); |
|
97 | 97 | |
98 | - /** |
|
99 | - * set a decoration of the text |
|
100 | - * |
|
101 | - * @access public |
|
102 | - * @param string $sContent content to around by the style |
|
103 | - * @param string $sStyleName the name of the style |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public static function setDecoration(string $sContent, string $sStyleName) : string |
|
107 | - { |
|
108 | - return self::_applyCode($sContent, self::$_aBackgroundCodes[$sStyleName]); |
|
109 | - } |
|
98 | + /** |
|
99 | + * set a decoration of the text |
|
100 | + * |
|
101 | + * @access public |
|
102 | + * @param string $sContent content to around by the style |
|
103 | + * @param string $sStyleName the name of the style |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public static function setDecoration(string $sContent, string $sStyleName) : string |
|
107 | + { |
|
108 | + return self::_applyCode($sContent, self::$_aBackgroundCodes[$sStyleName]); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * set a color of the background |
|
113 | - * |
|
114 | - * @access public |
|
115 | - * @param string $sContent content to around by the style |
|
116 | - * @param string $sColorName the name of the color |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public static function setBackground(string $sContent, string $sColorName) : string |
|
120 | - { |
|
121 | - if (!isset(self::$_aBackgroundCodes[$sColorName])) { $sColorName = 'black'; } |
|
111 | + /** |
|
112 | + * set a color of the background |
|
113 | + * |
|
114 | + * @access public |
|
115 | + * @param string $sContent content to around by the style |
|
116 | + * @param string $sColorName the name of the color |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public static function setBackground(string $sContent, string $sColorName) : string |
|
120 | + { |
|
121 | + if (!isset(self::$_aBackgroundCodes[$sColorName])) { $sColorName = 'black'; } |
|
122 | 122 | |
123 | - return self::_applyCode($sContent, self::$_aBackgroundCodes[$sColorName]); |
|
124 | - } |
|
123 | + return self::_applyCode($sContent, self::$_aBackgroundCodes[$sColorName]); |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * set a color of the text |
|
128 | - * |
|
129 | - * @access public |
|
130 | - * @param string $sContent content to around by the style |
|
131 | - * @param string $sColorName the name of the color |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public static function setColor(string $sContent, string $sColorName) : string |
|
135 | - { |
|
136 | - if (!isset(self::$_aBackgroundCodes[$sColorName])) { $sColorName = 'white'; } |
|
126 | + /** |
|
127 | + * set a color of the text |
|
128 | + * |
|
129 | + * @access public |
|
130 | + * @param string $sContent content to around by the style |
|
131 | + * @param string $sColorName the name of the color |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public static function setColor(string $sContent, string $sColorName) : string |
|
135 | + { |
|
136 | + if (!isset(self::$_aBackgroundCodes[$sColorName])) { $sColorName = 'white'; } |
|
137 | 137 | |
138 | - return self::_applyCode($sContent, self::$_aBackgroundCodes[$sColorName]); |
|
139 | - } |
|
138 | + return self::_applyCode($sContent, self::$_aBackgroundCodes[$sColorName]); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * around the text by a color |
|
143 | - * |
|
144 | - * @access private |
|
145 | - * @param string $sContent content to around by the style |
|
146 | - * @param string $sCode the name of the code (color or decoration) |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - private static function _applyCode(string $sContent, string $sCode) : string |
|
150 | - { |
|
151 | - return "\033[" . $sCode . "m" . $sContent . "\033[0m\n"; |
|
152 | - } |
|
141 | + /** |
|
142 | + * around the text by a color |
|
143 | + * |
|
144 | + * @access private |
|
145 | + * @param string $sContent content to around by the style |
|
146 | + * @param string $sCode the name of the code (color or decoration) |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + private static function _applyCode(string $sContent, string $sCode) : string |
|
150 | + { |
|
151 | + return "\033[" . $sCode . "m" . $sContent . "\033[0m\n"; |
|
152 | + } |
|
153 | 153 | } |
@@ -148,6 +148,6 @@ |
||
148 | 148 | */ |
149 | 149 | private static function _applyCode(string $sContent, string $sCode) : string |
150 | 150 | { |
151 | - return "\033[" . $sCode . "m" . $sContent . "\033[0m\n"; |
|
151 | + return "\033[".$sCode."m".$sContent."\033[0m\n"; |
|
152 | 152 | } |
153 | 153 | } |
@@ -129,7 +129,7 @@ |
||
129 | 129 | * @param mixed $mOffset |
130 | 130 | * @return boolean |
131 | 131 | */ |
132 | - public function offsetExists($mOffset) |
|
132 | + public function offsetExists($mOffset) |
|
133 | 133 | { |
134 | 134 | return $this->__isset($mOffset); |
135 | 135 | } |
@@ -30,162 +30,162 @@ |
||
30 | 30 | */ |
31 | 31 | class Input extends Common |
32 | 32 | { |
33 | - /** |
|
34 | - * the name of element |
|
35 | - * |
|
36 | - * @access private |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $_sType = null; |
|
40 | - |
|
41 | - /** |
|
42 | - * the label of element |
|
43 | - * |
|
44 | - * @access private |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - private $_sLabel = null; |
|
48 | - |
|
49 | - /** |
|
50 | - * the value of element |
|
51 | - * |
|
52 | - * @access private |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - private $_sValue = null; |
|
56 | - |
|
57 | - /** |
|
58 | - * constructor that it increment (static) for all use |
|
59 | - * |
|
60 | - * @access public |
|
61 | - * @param string $sName name |
|
62 | - * @param string $sType type of input |
|
63 | - * @param string $sLabel label of input |
|
64 | - * @param string $sValue value of input |
|
65 | - */ |
|
66 | - public function __construct(string $sName, string $sType, string $sLabel = null, string $sValue = null) |
|
67 | - { |
|
68 | - $this->setName($sName); |
|
69 | - $this->setType($sType); |
|
70 | - $this->setValue($sValue); |
|
71 | - |
|
72 | - if ($sLabel !== null) { $this->setLabel($sLabel); } else { $this->setLabel($sName); } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * get the type |
|
77 | - * |
|
78 | - * @access public |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getType() : string |
|
82 | - { |
|
83 | - return $this->_sType; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * set the type |
|
88 | - * |
|
89 | - * @access public |
|
90 | - * @param string $sType type of input; |
|
91 | - * @return \Venus\lib\Form\Input |
|
92 | - */ |
|
93 | - public function setType(string $sType) : Input |
|
94 | - { |
|
95 | - $this->_sType = $sType; |
|
96 | - return $this; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * get the Value |
|
101 | - * |
|
102 | - * @access public |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function getValue() : string |
|
106 | - { |
|
107 | - return $this->_sValue; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * set the Value |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @param string $sValue Value of input; |
|
115 | - * @return \Venus\lib\Form\Input |
|
116 | - */ |
|
117 | - public function setValue(string $sValue) : Input |
|
118 | - { |
|
119 | - $this->_sValue = $sValue; |
|
120 | - return $this; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * get the Label |
|
125 | - * |
|
126 | - * @access public |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function getLabel() : string |
|
130 | - { |
|
131 | - return $this->_sLabel; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * set the Label |
|
136 | - * |
|
137 | - * @access public |
|
138 | - * @param string $sLabel Label of input; |
|
139 | - * @return \Venus\lib\Form\Input |
|
140 | - */ |
|
141 | - public function setLabel(string $sLabel) : Input |
|
142 | - { |
|
143 | - $this->_sLabel = $sLabel; |
|
144 | - return $this; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * if the button is clicked |
|
149 | - * |
|
150 | - * @access public |
|
151 | - * @param string $sType type of input; |
|
152 | - * @return boolean |
|
153 | - */ |
|
154 | - public function isClicked(string $sType) : bool |
|
155 | - { |
|
156 | - if ($this->getType() === 'submit' || $this->getType() === 'button') { |
|
157 | - |
|
158 | - if (isset($_POST[$this->getName()])) { return true; } |
|
159 | - } |
|
160 | - |
|
161 | - return false; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * get the <html> |
|
166 | - * |
|
167 | - * @access public |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function fetch() : string |
|
171 | - { |
|
172 | - $sContent = ''; |
|
173 | - |
|
174 | - if ($this->getType() === 'text' || $this->getType() === 'password' || $this->getType() === 'file' |
|
175 | - || $this->getType() === 'tel' || $this->getType() === 'url' || $this->getType() === 'email' |
|
176 | - || $this->getType() === 'search' || $this->getType() === 'date' || $this->getType() === 'time' |
|
177 | - || $this->getType() === 'datetime' || $this->getType() === 'month' || $this->getType() === 'week' |
|
178 | - || $this->getType() === 'number' || $this->getType() === 'range' || $this->getType() === 'color') { |
|
179 | - |
|
180 | - $sContent .= '<label>'.$this->getLabel().'</label> '; |
|
181 | - } |
|
182 | - |
|
183 | - $sContent .= '<input type="'.$this->getType().'" name="'.$this->getName().'"'; |
|
184 | - |
|
185 | - if ($this->getValue() !== null) { $sContent .= ' value="'.$this->getValue().'"'; } |
|
186 | - |
|
187 | - $sContent .= '/>'; |
|
188 | - |
|
189 | - return $sContent; |
|
190 | - } |
|
33 | + /** |
|
34 | + * the name of element |
|
35 | + * |
|
36 | + * @access private |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $_sType = null; |
|
40 | + |
|
41 | + /** |
|
42 | + * the label of element |
|
43 | + * |
|
44 | + * @access private |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private $_sLabel = null; |
|
48 | + |
|
49 | + /** |
|
50 | + * the value of element |
|
51 | + * |
|
52 | + * @access private |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + private $_sValue = null; |
|
56 | + |
|
57 | + /** |
|
58 | + * constructor that it increment (static) for all use |
|
59 | + * |
|
60 | + * @access public |
|
61 | + * @param string $sName name |
|
62 | + * @param string $sType type of input |
|
63 | + * @param string $sLabel label of input |
|
64 | + * @param string $sValue value of input |
|
65 | + */ |
|
66 | + public function __construct(string $sName, string $sType, string $sLabel = null, string $sValue = null) |
|
67 | + { |
|
68 | + $this->setName($sName); |
|
69 | + $this->setType($sType); |
|
70 | + $this->setValue($sValue); |
|
71 | + |
|
72 | + if ($sLabel !== null) { $this->setLabel($sLabel); } else { $this->setLabel($sName); } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * get the type |
|
77 | + * |
|
78 | + * @access public |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getType() : string |
|
82 | + { |
|
83 | + return $this->_sType; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * set the type |
|
88 | + * |
|
89 | + * @access public |
|
90 | + * @param string $sType type of input; |
|
91 | + * @return \Venus\lib\Form\Input |
|
92 | + */ |
|
93 | + public function setType(string $sType) : Input |
|
94 | + { |
|
95 | + $this->_sType = $sType; |
|
96 | + return $this; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * get the Value |
|
101 | + * |
|
102 | + * @access public |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function getValue() : string |
|
106 | + { |
|
107 | + return $this->_sValue; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * set the Value |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @param string $sValue Value of input; |
|
115 | + * @return \Venus\lib\Form\Input |
|
116 | + */ |
|
117 | + public function setValue(string $sValue) : Input |
|
118 | + { |
|
119 | + $this->_sValue = $sValue; |
|
120 | + return $this; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * get the Label |
|
125 | + * |
|
126 | + * @access public |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function getLabel() : string |
|
130 | + { |
|
131 | + return $this->_sLabel; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * set the Label |
|
136 | + * |
|
137 | + * @access public |
|
138 | + * @param string $sLabel Label of input; |
|
139 | + * @return \Venus\lib\Form\Input |
|
140 | + */ |
|
141 | + public function setLabel(string $sLabel) : Input |
|
142 | + { |
|
143 | + $this->_sLabel = $sLabel; |
|
144 | + return $this; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * if the button is clicked |
|
149 | + * |
|
150 | + * @access public |
|
151 | + * @param string $sType type of input; |
|
152 | + * @return boolean |
|
153 | + */ |
|
154 | + public function isClicked(string $sType) : bool |
|
155 | + { |
|
156 | + if ($this->getType() === 'submit' || $this->getType() === 'button') { |
|
157 | + |
|
158 | + if (isset($_POST[$this->getName()])) { return true; } |
|
159 | + } |
|
160 | + |
|
161 | + return false; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * get the <html> |
|
166 | + * |
|
167 | + * @access public |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function fetch() : string |
|
171 | + { |
|
172 | + $sContent = ''; |
|
173 | + |
|
174 | + if ($this->getType() === 'text' || $this->getType() === 'password' || $this->getType() === 'file' |
|
175 | + || $this->getType() === 'tel' || $this->getType() === 'url' || $this->getType() === 'email' |
|
176 | + || $this->getType() === 'search' || $this->getType() === 'date' || $this->getType() === 'time' |
|
177 | + || $this->getType() === 'datetime' || $this->getType() === 'month' || $this->getType() === 'week' |
|
178 | + || $this->getType() === 'number' || $this->getType() === 'range' || $this->getType() === 'color') { |
|
179 | + |
|
180 | + $sContent .= '<label>'.$this->getLabel().'</label> '; |
|
181 | + } |
|
182 | + |
|
183 | + $sContent .= '<input type="'.$this->getType().'" name="'.$this->getName().'"'; |
|
184 | + |
|
185 | + if ($this->getValue() !== null) { $sContent .= ' value="'.$this->getValue().'"'; } |
|
186 | + |
|
187 | + $sContent .= '/>'; |
|
188 | + |
|
189 | + return $sContent; |
|
190 | + } |
|
191 | 191 | } |
@@ -33,207 +33,207 @@ |
||
33 | 33 | */ |
34 | 34 | class Container |
35 | 35 | { |
36 | - /** |
|
37 | - * complete view |
|
38 | - * |
|
39 | - * @access private |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - private $_sView = null; |
|
43 | - |
|
44 | - /** |
|
45 | - * form library with its entity |
|
46 | - * |
|
47 | - * @access private |
|
48 | - * @var Form |
|
49 | - */ |
|
50 | - private $_oForm = null; |
|
51 | - |
|
52 | - /** |
|
53 | - * Block the save in the entity if you don't call handleRequest |
|
54 | - * |
|
55 | - * @access private |
|
56 | - * @var bool |
|
57 | - */ |
|
58 | - private $_bHandleRequestActivate = false; |
|
59 | - |
|
60 | - /** |
|
61 | - * Request of the formular |
|
62 | - * |
|
63 | - * @access private |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - private $_aRequest = null; |
|
67 | - |
|
68 | - /** |
|
69 | - * get the Value |
|
70 | - * |
|
71 | - * @access public |
|
72 | - * @return \stdClass |
|
73 | - */ |
|
74 | - public function createView() : \stdClass |
|
75 | - { |
|
76 | - $oView = new \stdClass; |
|
77 | - $oView->form = $this->_sView; |
|
78 | - $oView->form_start = $this->_oForm->getFormInObject()->start; |
|
79 | - $oView->form_end = $this->_oForm->getFormInObject()->end; |
|
80 | - $oView->form_row = array(); |
|
81 | - |
|
82 | - foreach ($this->_oForm->getFormInObject()->form as $sKey => $mValue) { |
|
83 | - |
|
84 | - if ($mValue instanceof Container) { |
|
85 | - |
|
86 | - $oNewForm = $mValue->createView(); |
|
87 | - $oView->form_row[$sKey] = $oNewForm->form_row; |
|
88 | - } else { |
|
89 | - |
|
90 | - $oView->form_row[$sKey] = $mValue; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - return $oView; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * set the Value |
|
99 | - * |
|
100 | - * @access public |
|
101 | - * @param string $sView Display of form; |
|
102 | - * @return \Venus\lib\Form\Container |
|
103 | - */ |
|
104 | - public function setView(string $sView) : Container |
|
105 | - { |
|
106 | - $this->_sView = $sView; |
|
107 | - return $this; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * handle the request to do many actions on it |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @param array $aRequest request like $_POST |
|
115 | - * @return bool |
|
116 | - */ |
|
117 | - public function handleRequest(array $aRequest) : bool |
|
118 | - { |
|
119 | - if (!count($_POST)) { return true; } |
|
120 | - |
|
121 | - // Validation |
|
122 | - foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
123 | - |
|
124 | - if (!$sValue instanceof self && !$this->_validate($sValue)) { |
|
125 | - |
|
126 | - return false; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - // Save |
|
131 | - if ($this->_oForm->getIdEntity() > 0 && $this->_oForm->getSynchronizeEntity() !== null && count($aRequest) > 0) { |
|
132 | - |
|
133 | - $sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity()); |
|
134 | - $oModel = new $sModelName; |
|
135 | - |
|
136 | - $oEntity = new $this->_oForm->getSynchronizeEntity(); |
|
137 | - $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
138 | - $sMethodName = 'set_'.$sPrimaryKey; |
|
139 | - |
|
140 | - call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity())); |
|
141 | - |
|
142 | - foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
143 | - |
|
144 | - $sMethodName = 'set_'.$sValue->getName().''; |
|
145 | - call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
146 | - } |
|
147 | - |
|
148 | - $oEntity->save(); |
|
149 | - } else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) { |
|
150 | - |
|
151 | - $oEntity = new $this->_oForm->_sSynchronizeEntity; |
|
152 | - |
|
153 | - foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
154 | - |
|
155 | - $sMethodName = 'set_'.$sValue->getName().''; |
|
156 | - call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
157 | - } |
|
158 | - |
|
159 | - $this->_oForm->setIdEntityCreated($oEntity->save()); |
|
160 | - } |
|
161 | - |
|
162 | - $this->_bHandleRequestActivate = true; |
|
163 | - $this->_aRequest = $aRequest; |
|
164 | - return true; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * set Form lib with its entity |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @param Form $oForm request like $_POST |
|
172 | - * @return \Venus\lib\Form\Container |
|
173 | - */ |
|
174 | - public function setForm(Form $oForm) : Container |
|
175 | - { |
|
176 | - $this->_oForm = $oForm; |
|
177 | - return $this; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * if this form is validate and save |
|
182 | - * |
|
183 | - * @access public |
|
184 | - * @return boolean |
|
185 | - */ |
|
186 | - public function isValid() : bool |
|
187 | - { |
|
188 | - if ($this->_bHandleRequestActivate === true) { return true; } else { return false; } |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * if this form is validate and save |
|
193 | - * |
|
194 | - * @access public |
|
195 | - * @return boolean |
|
196 | - */ |
|
197 | - public function isSubmitted() : bool |
|
198 | - { |
|
199 | - if (isset($_POST['validform'.$this->_oForm->getFormNumber()]) && $_POST['validform'.$this->_oForm->getFormNumber()] == 1) { |
|
200 | - |
|
201 | - return true; |
|
202 | - } else { |
|
203 | - |
|
204 | - return false; |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * if this form is validate and save |
|
210 | - * |
|
211 | - * @access public |
|
212 | - * @param string $sElementName element name what we want test the click |
|
213 | - * @return boolean |
|
214 | - */ |
|
215 | - public function isClicked(string $sElementName) : bool |
|
216 | - { |
|
217 | - if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } else { return false; } |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * if the element is valide or not (with the constraint) |
|
222 | - * |
|
223 | - * @access private |
|
224 | - * @param object $oElement element of formular |
|
225 | - * @return boolean |
|
226 | - */ |
|
227 | - private function _validate($oElement) : bool |
|
228 | - { |
|
229 | - foreach ($oElement->getConstraint() as $oConstraint) { |
|
230 | - |
|
231 | - if (!$oConstraint->validate($_POST[$oElement->getName()])) { |
|
232 | - |
|
233 | - return false; |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - return true; |
|
238 | - } |
|
36 | + /** |
|
37 | + * complete view |
|
38 | + * |
|
39 | + * @access private |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + private $_sView = null; |
|
43 | + |
|
44 | + /** |
|
45 | + * form library with its entity |
|
46 | + * |
|
47 | + * @access private |
|
48 | + * @var Form |
|
49 | + */ |
|
50 | + private $_oForm = null; |
|
51 | + |
|
52 | + /** |
|
53 | + * Block the save in the entity if you don't call handleRequest |
|
54 | + * |
|
55 | + * @access private |
|
56 | + * @var bool |
|
57 | + */ |
|
58 | + private $_bHandleRequestActivate = false; |
|
59 | + |
|
60 | + /** |
|
61 | + * Request of the formular |
|
62 | + * |
|
63 | + * @access private |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + private $_aRequest = null; |
|
67 | + |
|
68 | + /** |
|
69 | + * get the Value |
|
70 | + * |
|
71 | + * @access public |
|
72 | + * @return \stdClass |
|
73 | + */ |
|
74 | + public function createView() : \stdClass |
|
75 | + { |
|
76 | + $oView = new \stdClass; |
|
77 | + $oView->form = $this->_sView; |
|
78 | + $oView->form_start = $this->_oForm->getFormInObject()->start; |
|
79 | + $oView->form_end = $this->_oForm->getFormInObject()->end; |
|
80 | + $oView->form_row = array(); |
|
81 | + |
|
82 | + foreach ($this->_oForm->getFormInObject()->form as $sKey => $mValue) { |
|
83 | + |
|
84 | + if ($mValue instanceof Container) { |
|
85 | + |
|
86 | + $oNewForm = $mValue->createView(); |
|
87 | + $oView->form_row[$sKey] = $oNewForm->form_row; |
|
88 | + } else { |
|
89 | + |
|
90 | + $oView->form_row[$sKey] = $mValue; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + return $oView; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * set the Value |
|
99 | + * |
|
100 | + * @access public |
|
101 | + * @param string $sView Display of form; |
|
102 | + * @return \Venus\lib\Form\Container |
|
103 | + */ |
|
104 | + public function setView(string $sView) : Container |
|
105 | + { |
|
106 | + $this->_sView = $sView; |
|
107 | + return $this; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * handle the request to do many actions on it |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @param array $aRequest request like $_POST |
|
115 | + * @return bool |
|
116 | + */ |
|
117 | + public function handleRequest(array $aRequest) : bool |
|
118 | + { |
|
119 | + if (!count($_POST)) { return true; } |
|
120 | + |
|
121 | + // Validation |
|
122 | + foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
123 | + |
|
124 | + if (!$sValue instanceof self && !$this->_validate($sValue)) { |
|
125 | + |
|
126 | + return false; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + // Save |
|
131 | + if ($this->_oForm->getIdEntity() > 0 && $this->_oForm->getSynchronizeEntity() !== null && count($aRequest) > 0) { |
|
132 | + |
|
133 | + $sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity()); |
|
134 | + $oModel = new $sModelName; |
|
135 | + |
|
136 | + $oEntity = new $this->_oForm->getSynchronizeEntity(); |
|
137 | + $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
138 | + $sMethodName = 'set_'.$sPrimaryKey; |
|
139 | + |
|
140 | + call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity())); |
|
141 | + |
|
142 | + foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
143 | + |
|
144 | + $sMethodName = 'set_'.$sValue->getName().''; |
|
145 | + call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
146 | + } |
|
147 | + |
|
148 | + $oEntity->save(); |
|
149 | + } else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) { |
|
150 | + |
|
151 | + $oEntity = new $this->_oForm->_sSynchronizeEntity; |
|
152 | + |
|
153 | + foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
154 | + |
|
155 | + $sMethodName = 'set_'.$sValue->getName().''; |
|
156 | + call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
157 | + } |
|
158 | + |
|
159 | + $this->_oForm->setIdEntityCreated($oEntity->save()); |
|
160 | + } |
|
161 | + |
|
162 | + $this->_bHandleRequestActivate = true; |
|
163 | + $this->_aRequest = $aRequest; |
|
164 | + return true; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * set Form lib with its entity |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @param Form $oForm request like $_POST |
|
172 | + * @return \Venus\lib\Form\Container |
|
173 | + */ |
|
174 | + public function setForm(Form $oForm) : Container |
|
175 | + { |
|
176 | + $this->_oForm = $oForm; |
|
177 | + return $this; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * if this form is validate and save |
|
182 | + * |
|
183 | + * @access public |
|
184 | + * @return boolean |
|
185 | + */ |
|
186 | + public function isValid() : bool |
|
187 | + { |
|
188 | + if ($this->_bHandleRequestActivate === true) { return true; } else { return false; } |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * if this form is validate and save |
|
193 | + * |
|
194 | + * @access public |
|
195 | + * @return boolean |
|
196 | + */ |
|
197 | + public function isSubmitted() : bool |
|
198 | + { |
|
199 | + if (isset($_POST['validform'.$this->_oForm->getFormNumber()]) && $_POST['validform'.$this->_oForm->getFormNumber()] == 1) { |
|
200 | + |
|
201 | + return true; |
|
202 | + } else { |
|
203 | + |
|
204 | + return false; |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * if this form is validate and save |
|
210 | + * |
|
211 | + * @access public |
|
212 | + * @param string $sElementName element name what we want test the click |
|
213 | + * @return boolean |
|
214 | + */ |
|
215 | + public function isClicked(string $sElementName) : bool |
|
216 | + { |
|
217 | + if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } else { return false; } |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * if the element is valide or not (with the constraint) |
|
222 | + * |
|
223 | + * @access private |
|
224 | + * @param object $oElement element of formular |
|
225 | + * @return boolean |
|
226 | + */ |
|
227 | + private function _validate($oElement) : bool |
|
228 | + { |
|
229 | + foreach ($oElement->getConstraint() as $oConstraint) { |
|
230 | + |
|
231 | + if (!$oConstraint->validate($_POST[$oElement->getName()])) { |
|
232 | + |
|
233 | + return false; |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + return true; |
|
238 | + } |
|
239 | 239 | } |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date |
43 | 43 | { |
44 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
44 | + $iFirstDayInYear = date("N", mktime(0, 0, 0, 1, 1, $iYear)); |
|
45 | 45 | |
46 | 46 | if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
47 | 47 | |
48 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
48 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek - 1) * 604800; } else { $iWeekInSeconds = 0; } |
|
49 | 49 | |
50 | 50 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
51 | 51 | $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800; |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array |
158 | 158 | { |
159 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
159 | + $iFirstDayInYear = date("N", mktime(0, 0, 0, 1, 1, $iYear)); |
|
160 | 160 | |
161 | 161 | if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
162 | 162 | else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
163 | 163 | |
164 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
164 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek - 1) * 604800; } |
|
165 | 165 | else { $iWeekInSeconds = 0; } |
166 | 166 | |
167 | 167 | if (date('N') > 2) { |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) { |
181 | 181 | |
182 | 182 | $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]); |
183 | - $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]); |
|
183 | + $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y') + 1).'$1', $aDates[1]); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | return $aDates; |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime); |
222 | 222 | $iTimeStamp = time() - $oDateTime->getTimestamp(); |
223 | 223 | |
224 | - if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
|
225 | - if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
|
226 | - if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
|
227 | - if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
228 | - else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
224 | + if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp / 60).' '.$sMinutes.$sEndReturn; } |
|
225 | + if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp / 3600).' '.$sHours.$sEndReturn; } |
|
226 | + if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp / 86400).' '.$sDays.$sEndReturn; } |
|
227 | + if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp / 2592000).' '.$sMonths.$sEndReturn; } |
|
228 | + else { return $sStartReturn.' '.(int)($iTimeStamp / 31536000).' '.$sYears.$sEndReturn; } |
|
229 | 229 | } |
230 | 230 | } |
@@ -76,18 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | if ($sLanguage == 'fr') { |
78 | 78 | |
79 | - if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } |
|
80 | - else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } |
|
81 | - else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } |
|
82 | - else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } |
|
83 | - else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } |
|
84 | - else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } |
|
85 | - else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } |
|
86 | - else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } |
|
87 | - else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } |
|
88 | - else if ($sMonth == 10) { return 'Octobre'; } |
|
89 | - else if ($sMonth == 11) { return 'Novembre'; } |
|
90 | - else if ($sMonth == 12) { return 'Décembre'; } |
|
79 | + if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } else if ($sMonth == 10) { return 'Octobre'; } else if ($sMonth == 11) { return 'Novembre'; } else if ($sMonth == 12) { return 'Décembre'; } |
|
91 | 80 | } |
92 | 81 | } |
93 | 82 | |
@@ -103,13 +92,7 @@ discard block |
||
103 | 92 | { |
104 | 93 | if ($sLanguage == 'fr') { |
105 | 94 | |
106 | - if ($sDay == 0) { return 'dimanche'; } |
|
107 | - else if ($sDay == 1) { return 'lundi'; } |
|
108 | - else if ($sDay == 2) { return 'mardi'; } |
|
109 | - else if ($sDay == 3) { return 'mercredi'; } |
|
110 | - else if ($sDay == 4) { return 'jeudi'; } |
|
111 | - else if ($sDay == 5) { return 'vendredi'; } |
|
112 | - else if ($sDay == 6) { return 'samedi'; } |
|
95 | + if ($sDay == 0) { return 'dimanche'; } else if ($sDay == 1) { return 'lundi'; } else if ($sDay == 2) { return 'mardi'; } else if ($sDay == 3) { return 'mercredi'; } else if ($sDay == 4) { return 'jeudi'; } else if ($sDay == 5) { return 'vendredi'; } else if ($sDay == 6) { return 'samedi'; } |
|
113 | 96 | } |
114 | 97 | } |
115 | 98 | |
@@ -136,8 +119,7 @@ discard block |
||
136 | 119 | if ($iMonth == $aToday['mois']) { |
137 | 120 | |
138 | 121 | if ($iDay > $aToday['jour']) { $iYears--; } |
139 | - } |
|
140 | - else { |
|
122 | + } else { |
|
141 | 123 | |
142 | 124 | $iYears--; |
143 | 125 | } |
@@ -158,18 +140,15 @@ discard block |
||
158 | 140 | { |
159 | 141 | $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
160 | 142 | |
161 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
162 | - else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
143 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
163 | 144 | |
164 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
165 | - else { $iWeekInSeconds = 0; } |
|
145 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
166 | 146 | |
167 | 147 | if (date('N') > 2) { |
168 | 148 | |
169 | 149 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800; |
170 | 150 | $iTimestampLastDay = $iTimestamp + 604800; |
171 | - } |
|
172 | - else { |
|
151 | + } else { |
|
173 | 152 | |
174 | 153 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000; |
175 | 154 | $iTimestampLastDay = $iTimestamp + 604800; |
@@ -224,7 +203,6 @@ discard block |
||
224 | 203 | if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
225 | 204 | if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
226 | 205 | if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
227 | - if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
228 | - else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
206 | + if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
229 | 207 | } |
230 | 208 | } |
@@ -30,210 +30,210 @@ |
||
30 | 30 | */ |
31 | 31 | class Date |
32 | 32 | { |
33 | - /** |
|
34 | - * set name of image |
|
35 | - * |
|
36 | - * @access public |
|
37 | - * @param int $iWeek number of week |
|
38 | - * @param int $iYear year |
|
39 | - * @param string $sFormat |
|
40 | - * @return Date |
|
41 | - */ |
|
42 | - public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date |
|
43 | - { |
|
44 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
45 | - |
|
46 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
47 | - |
|
48 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
49 | - |
|
50 | - $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
|
51 | - $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800; |
|
52 | - |
|
53 | - return array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * set name of image |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @return \Venus\lib\Date |
|
61 | - */ |
|
62 | - public static function getActualWeek() : Date |
|
63 | - { |
|
64 | - return self::getWeek(date('W'), date('Y')); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * set name of image |
|
69 | - * |
|
70 | - * @access public |
|
71 | - * @param string $sMonth number of week |
|
72 | - * @param string $sLanguage language |
|
73 | - * @return \Venus\lib\Date |
|
74 | - */ |
|
75 | - public static function getMonthInWord(string $sMonth, string $sLanguage = 'fr') : Date |
|
76 | - { |
|
77 | - if ($sLanguage == 'fr') { |
|
78 | - |
|
79 | - if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } |
|
80 | - else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } |
|
81 | - else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } |
|
82 | - else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } |
|
83 | - else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } |
|
84 | - else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } |
|
85 | - else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } |
|
86 | - else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } |
|
87 | - else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } |
|
88 | - else if ($sMonth == 10) { return 'Octobre'; } |
|
89 | - else if ($sMonth == 11) { return 'Novembre'; } |
|
90 | - else if ($sMonth == 12) { return 'Décembre'; } |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * set name of image |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @param mixed $sDay number of day |
|
99 | - * @param string $sLanguage language |
|
100 | - * @return \Venus\lib\Date |
|
101 | - */ |
|
102 | - public static function getDayInWord(string $sDay, string $sLanguage = 'fr') : Date |
|
103 | - { |
|
104 | - if ($sLanguage == 'fr') { |
|
105 | - |
|
106 | - if ($sDay == 0) { return 'dimanche'; } |
|
107 | - else if ($sDay == 1) { return 'lundi'; } |
|
108 | - else if ($sDay == 2) { return 'mardi'; } |
|
109 | - else if ($sDay == 3) { return 'mercredi'; } |
|
110 | - else if ($sDay == 4) { return 'jeudi'; } |
|
111 | - else if ($sDay == 5) { return 'vendredi'; } |
|
112 | - else if ($sDay == 6) { return 'samedi'; } |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * get age by date |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @param string $sBirthday |
|
121 | - * @return int |
|
122 | - */ |
|
123 | - public static function getAgeByDate(string $sBirthday) : int |
|
124 | - { |
|
125 | - list($iYear, $iMonth, $iDay) = preg_split('/[-.]/', $sBirthday); |
|
126 | - |
|
127 | - $aToday = array(); |
|
128 | - $aToday['mois'] = date('n'); |
|
129 | - $aToday['jour'] = date('j'); |
|
130 | - $aToday['annee'] = date('Y'); |
|
131 | - |
|
132 | - $iYears = $aToday['annee'] - $iYear; |
|
133 | - |
|
134 | - if ($aToday['mois'] <= $iMonth) { |
|
135 | - |
|
136 | - if ($iMonth == $aToday['mois']) { |
|
137 | - |
|
138 | - if ($iDay > $aToday['jour']) { $iYears--; } |
|
139 | - } |
|
140 | - else { |
|
141 | - |
|
142 | - $iYears--; |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - return $iYears; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * set name of image |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param int $iWeek number of week |
|
154 | - * @param int $iYear year |
|
155 | - * @param string $sFormat |
|
156 | - * @return array|Date |
|
157 | - */ |
|
158 | - public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array |
|
159 | - { |
|
160 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
161 | - |
|
162 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
163 | - else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
164 | - |
|
165 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
166 | - else { $iWeekInSeconds = 0; } |
|
167 | - |
|
168 | - if (date('N') > 2) { |
|
169 | - |
|
170 | - $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800; |
|
171 | - $iTimestampLastDay = $iTimestamp + 604800; |
|
172 | - } |
|
173 | - else { |
|
174 | - |
|
175 | - $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000; |
|
176 | - $iTimestampLastDay = $iTimestamp + 604800; |
|
177 | - } |
|
178 | - |
|
179 | - $aDates = array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
180 | - |
|
181 | - if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) { |
|
182 | - |
|
183 | - $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]); |
|
184 | - $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]); |
|
185 | - } |
|
186 | - |
|
187 | - return $aDates; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * set name of image |
|
192 | - * |
|
193 | - * @access public |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public static function getActualMiddleWeek() : array |
|
197 | - { |
|
198 | - return self::getMiddleWeek(date('W'), date('Y')); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * get time of kind "X hour ago" |
|
203 | - * |
|
204 | - * @access public |
|
205 | - * @param string $sDateTime datetime to convert |
|
206 | - * @param string $sLanguage language |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - public static function getTimeAgoInString(string $sDateTime, string $sLanguage = 'fr') : string |
|
210 | - { |
|
211 | - if ($sLanguage == 'fr') { |
|
212 | - |
|
213 | - $sStartReturn = 'Il y a'; |
|
214 | - $sEndReturn = ''; |
|
215 | - $sMinutes = 'minute(s) '; |
|
216 | - $sHours = 'heure(s) '; |
|
217 | - $sDays = 'jour(s) '; |
|
218 | - $sMonths = 'mois '; |
|
219 | - $sYears = 'années '; |
|
220 | - } else { |
|
221 | - $sStartReturn = 'Ago'; |
|
222 | - $sEndReturn = ''; |
|
223 | - $sMinutes = 'minute(s) '; |
|
224 | - $sHours = 'hour(s) '; |
|
225 | - $sDays = 'day(s) '; |
|
226 | - $sMonths = 'month '; |
|
227 | - $sYears = 'years '; |
|
228 | - } |
|
229 | - |
|
230 | - $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime); |
|
231 | - $iTimeStamp = time() - $oDateTime->getTimestamp(); |
|
232 | - |
|
233 | - if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
|
234 | - if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
|
235 | - if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
|
236 | - if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
237 | - else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
238 | - } |
|
33 | + /** |
|
34 | + * set name of image |
|
35 | + * |
|
36 | + * @access public |
|
37 | + * @param int $iWeek number of week |
|
38 | + * @param int $iYear year |
|
39 | + * @param string $sFormat |
|
40 | + * @return Date |
|
41 | + */ |
|
42 | + public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date |
|
43 | + { |
|
44 | + $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
45 | + |
|
46 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
47 | + |
|
48 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
49 | + |
|
50 | + $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
|
51 | + $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800; |
|
52 | + |
|
53 | + return array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * set name of image |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @return \Venus\lib\Date |
|
61 | + */ |
|
62 | + public static function getActualWeek() : Date |
|
63 | + { |
|
64 | + return self::getWeek(date('W'), date('Y')); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * set name of image |
|
69 | + * |
|
70 | + * @access public |
|
71 | + * @param string $sMonth number of week |
|
72 | + * @param string $sLanguage language |
|
73 | + * @return \Venus\lib\Date |
|
74 | + */ |
|
75 | + public static function getMonthInWord(string $sMonth, string $sLanguage = 'fr') : Date |
|
76 | + { |
|
77 | + if ($sLanguage == 'fr') { |
|
78 | + |
|
79 | + if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } |
|
80 | + else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } |
|
81 | + else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } |
|
82 | + else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } |
|
83 | + else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } |
|
84 | + else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } |
|
85 | + else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } |
|
86 | + else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } |
|
87 | + else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } |
|
88 | + else if ($sMonth == 10) { return 'Octobre'; } |
|
89 | + else if ($sMonth == 11) { return 'Novembre'; } |
|
90 | + else if ($sMonth == 12) { return 'Décembre'; } |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * set name of image |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @param mixed $sDay number of day |
|
99 | + * @param string $sLanguage language |
|
100 | + * @return \Venus\lib\Date |
|
101 | + */ |
|
102 | + public static function getDayInWord(string $sDay, string $sLanguage = 'fr') : Date |
|
103 | + { |
|
104 | + if ($sLanguage == 'fr') { |
|
105 | + |
|
106 | + if ($sDay == 0) { return 'dimanche'; } |
|
107 | + else if ($sDay == 1) { return 'lundi'; } |
|
108 | + else if ($sDay == 2) { return 'mardi'; } |
|
109 | + else if ($sDay == 3) { return 'mercredi'; } |
|
110 | + else if ($sDay == 4) { return 'jeudi'; } |
|
111 | + else if ($sDay == 5) { return 'vendredi'; } |
|
112 | + else if ($sDay == 6) { return 'samedi'; } |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * get age by date |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @param string $sBirthday |
|
121 | + * @return int |
|
122 | + */ |
|
123 | + public static function getAgeByDate(string $sBirthday) : int |
|
124 | + { |
|
125 | + list($iYear, $iMonth, $iDay) = preg_split('/[-.]/', $sBirthday); |
|
126 | + |
|
127 | + $aToday = array(); |
|
128 | + $aToday['mois'] = date('n'); |
|
129 | + $aToday['jour'] = date('j'); |
|
130 | + $aToday['annee'] = date('Y'); |
|
131 | + |
|
132 | + $iYears = $aToday['annee'] - $iYear; |
|
133 | + |
|
134 | + if ($aToday['mois'] <= $iMonth) { |
|
135 | + |
|
136 | + if ($iMonth == $aToday['mois']) { |
|
137 | + |
|
138 | + if ($iDay > $aToday['jour']) { $iYears--; } |
|
139 | + } |
|
140 | + else { |
|
141 | + |
|
142 | + $iYears--; |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + return $iYears; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * set name of image |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param int $iWeek number of week |
|
154 | + * @param int $iYear year |
|
155 | + * @param string $sFormat |
|
156 | + * @return array|Date |
|
157 | + */ |
|
158 | + public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array |
|
159 | + { |
|
160 | + $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
161 | + |
|
162 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
163 | + else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
164 | + |
|
165 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
166 | + else { $iWeekInSeconds = 0; } |
|
167 | + |
|
168 | + if (date('N') > 2) { |
|
169 | + |
|
170 | + $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800; |
|
171 | + $iTimestampLastDay = $iTimestamp + 604800; |
|
172 | + } |
|
173 | + else { |
|
174 | + |
|
175 | + $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000; |
|
176 | + $iTimestampLastDay = $iTimestamp + 604800; |
|
177 | + } |
|
178 | + |
|
179 | + $aDates = array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
180 | + |
|
181 | + if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) { |
|
182 | + |
|
183 | + $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]); |
|
184 | + $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]); |
|
185 | + } |
|
186 | + |
|
187 | + return $aDates; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * set name of image |
|
192 | + * |
|
193 | + * @access public |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public static function getActualMiddleWeek() : array |
|
197 | + { |
|
198 | + return self::getMiddleWeek(date('W'), date('Y')); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * get time of kind "X hour ago" |
|
203 | + * |
|
204 | + * @access public |
|
205 | + * @param string $sDateTime datetime to convert |
|
206 | + * @param string $sLanguage language |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public static function getTimeAgoInString(string $sDateTime, string $sLanguage = 'fr') : string |
|
210 | + { |
|
211 | + if ($sLanguage == 'fr') { |
|
212 | + |
|
213 | + $sStartReturn = 'Il y a'; |
|
214 | + $sEndReturn = ''; |
|
215 | + $sMinutes = 'minute(s) '; |
|
216 | + $sHours = 'heure(s) '; |
|
217 | + $sDays = 'jour(s) '; |
|
218 | + $sMonths = 'mois '; |
|
219 | + $sYears = 'années '; |
|
220 | + } else { |
|
221 | + $sStartReturn = 'Ago'; |
|
222 | + $sEndReturn = ''; |
|
223 | + $sMinutes = 'minute(s) '; |
|
224 | + $sHours = 'hour(s) '; |
|
225 | + $sDays = 'day(s) '; |
|
226 | + $sMonths = 'month '; |
|
227 | + $sYears = 'years '; |
|
228 | + } |
|
229 | + |
|
230 | + $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime); |
|
231 | + $iTimeStamp = time() - $oDateTime->getTimestamp(); |
|
232 | + |
|
233 | + if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
|
234 | + if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
|
235 | + if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
|
236 | + if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
237 | + else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
238 | + } |
|
239 | 239 | } |
@@ -180,8 +180,7 @@ |
||
180 | 180 | |
181 | 181 | for ($i = 1; $i <= 31; $i++) { |
182 | 182 | |
183 | - if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
|
184 | - else { $aDay[$i] = $i; } |
|
183 | + if ($i < 10) { $aDay['0'.$i] = '0'.$i; } else { $aDay[$i] = $i; } |
|
185 | 184 | } |
186 | 185 | |
187 | 186 | $this->_aElement[$sName.'_day'] = new Select($sName, $aDay); |
@@ -60,408 +60,408 @@ |
||
60 | 60 | */ |
61 | 61 | class Form |
62 | 62 | { |
63 | - /** |
|
64 | - * Elements of the form |
|
65 | - * |
|
66 | - * @access private |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - private $_aElement = array(); |
|
70 | - |
|
71 | - /** |
|
72 | - * Increment for form |
|
73 | - * |
|
74 | - * @access private |
|
75 | - * @var int |
|
76 | - */ |
|
77 | - private static $_iFormIncrement = 0; |
|
78 | - |
|
79 | - /** |
|
80 | - * number of form |
|
81 | - * |
|
82 | - * @access private |
|
83 | - * @var int |
|
84 | - */ |
|
85 | - private $_iFormNumber = 0; |
|
86 | - |
|
87 | - /** |
|
88 | - * Separator between fields of form |
|
89 | - * |
|
90 | - * @access private |
|
91 | - * @var string |
|
92 | - */ |
|
93 | - private $_sSeparator = '<br/>'; |
|
94 | - |
|
95 | - /** |
|
96 | - * The entity to save with the formular |
|
97 | - * |
|
98 | - * @access private |
|
99 | - * @var string |
|
100 | - */ |
|
101 | - private $_sSynchronizeEntity = null; |
|
102 | - |
|
103 | - /** |
|
104 | - * The id of entity |
|
105 | - * |
|
106 | - * @access private |
|
107 | - * @var int |
|
108 | - */ |
|
109 | - private $_iIdEntity = null; |
|
110 | - |
|
111 | - /** |
|
112 | - * The entity to save with the formular |
|
113 | - * |
|
114 | - * @access private |
|
115 | - * @var int |
|
116 | - */ |
|
117 | - private $_iIdEntityCreated = null; |
|
118 | - |
|
119 | - /** |
|
120 | - * constructor that it increment (static) for all use |
|
121 | - * |
|
122 | - * @access public |
|
123 | - */ |
|
124 | - public function __construct() |
|
125 | - { |
|
126 | - self::$_iFormIncrement++; |
|
127 | - $this->_iFormNumber = self::$_iFormIncrement; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * add an element in the form |
|
132 | - * |
|
133 | - * @access public |
|
134 | - * @param string $sName name |
|
135 | - * @param string|\Venus\lib\Form $mType type of field |
|
136 | - * @param string $sLabel label of field |
|
137 | - * @param mixed $mValue value of field |
|
138 | - * @parma mixed $mOptions options (for select) |
|
139 | - * @return \Venus\lib\Form |
|
140 | - */ |
|
141 | - public function add($sName, $mType, $sLabel = null, $mValue = null, $mOptions = null) |
|
142 | - { |
|
143 | - if ($mType instanceof Container) { |
|
144 | - |
|
145 | - $this->_aElement[$sName] = $mType; |
|
146 | - } else if ($mType === 'text' || $mType === 'submit' || $mType === 'password' || $mType === 'file' || $mType === 'tel' |
|
147 | - || $mType === 'url' || $mType === 'email' || $mType === 'search' || $mType === 'date' || $mType === 'time' |
|
148 | - || $mType === 'datetime' || $mType === 'month' || $mType === 'week' || $mType === 'number' || $mType === 'range' |
|
149 | - || $mType === 'color') { |
|
150 | - |
|
151 | - $this->_aElement[$sName] = new Input($sName, $mType, $sLabel, $mValue); |
|
152 | - } elseif ($mType === 'textarea') { |
|
153 | - |
|
154 | - $this->_aElement[$sName] = new Textarea($sName, $sLabel, $mValue); |
|
155 | - } else if ($mType === 'select') { |
|
156 | - |
|
157 | - $this->_aElement[$sName] = new Select($sName, $mOptions, $sLabel, $mValue); |
|
158 | - } else if ($mType === 'label') { |
|
159 | - |
|
160 | - $this->_aElement[$sName] = new Label($sName); |
|
161 | - } else if ($mType === 'list_checkbox') { |
|
162 | - |
|
163 | - $i = 0; |
|
164 | - |
|
165 | - $this->_aElement[$sName.'_'.$i++] = new Label($sLabel); |
|
166 | - |
|
167 | - foreach ($mValue as $mKey => $sValue) { |
|
168 | - |
|
169 | - $this->_aElement[$sName.'_'.$i++] = new Checkbox($sName, $sValue, $mKey, $mOptions); |
|
170 | - } |
|
171 | - } else if ($mType === 'checkbox') { |
|
172 | - |
|
173 | - $this->_aElement[$sName] = new Checkbox($sName, $sLabel, $mValue, $mOptions); |
|
174 | - } else if ($mType === 'radio') { |
|
175 | - |
|
176 | - $this->_aElement[$sName.rand(100000, 999999)] = new Radio($sName, $sLabel, $mValue, $mOptions); |
|
177 | - } else if ($mType === 'date') { |
|
178 | - |
|
179 | - $aDay = array(); |
|
180 | - |
|
181 | - for ($i = 1; $i <= 31; $i++) { |
|
182 | - |
|
183 | - if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
|
184 | - else { $aDay[$i] = $i; } |
|
185 | - } |
|
186 | - |
|
187 | - $this->_aElement[$sName.'_day'] = new Select($sName, $aDay); |
|
188 | - |
|
189 | - $aMonth = array( |
|
190 | - '01' => 'Jan', |
|
191 | - '02' => 'Feb', |
|
192 | - '03' => 'Mar', |
|
193 | - '04' => 'Apr', |
|
194 | - '05' => 'May', |
|
195 | - '06' => 'Jun', |
|
196 | - '07' => 'Jui', |
|
197 | - '08' => 'Aug', |
|
198 | - '09' => 'Sep', |
|
199 | - '10' => 'Oct', |
|
200 | - '11' => 'Nov', |
|
201 | - '12' => 'Dec', |
|
202 | - ); |
|
203 | - |
|
204 | - $this->_aElement[$sName.'_month'] = new Select($sName, $aMonth); |
|
205 | - |
|
206 | - $aYear = array(); |
|
207 | - |
|
208 | - for ($i = 1900; $i <= 2013; $i++) { |
|
209 | - |
|
210 | - $aYear[$i] = $i; |
|
211 | - } |
|
212 | - |
|
213 | - $this->_aElement[$sName.'_year'] = new Select($sName, $aMonth); |
|
214 | - } |
|
215 | - |
|
216 | - return $this; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * get id entity created by the formular |
|
221 | - * |
|
222 | - * @access public |
|
223 | - * @return int |
|
224 | - */ |
|
225 | - public function getIdEntityCreated() : int |
|
226 | - { |
|
227 | - return $this->_iIdEntityCreated; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * set id entity created by the formular |
|
232 | - * |
|
233 | - * @access public |
|
234 | - * @param int $iIdEntityCreated |
|
235 | - * @return Form |
|
236 | - */ |
|
237 | - public function setIdEntityCreated(int $iIdEntityCreated) : Form |
|
238 | - { |
|
239 | - $this->_iIdEntityCreated = $iIdEntityCreated; |
|
240 | - return $this; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * get form number |
|
245 | - * |
|
246 | - * @access public |
|
247 | - * @return int |
|
248 | - */ |
|
249 | - public function getFormNumber() : int |
|
250 | - { |
|
251 | - return $this->_iFormNumber; |
|
252 | - } |
|
63 | + /** |
|
64 | + * Elements of the form |
|
65 | + * |
|
66 | + * @access private |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + private $_aElement = array(); |
|
70 | + |
|
71 | + /** |
|
72 | + * Increment for form |
|
73 | + * |
|
74 | + * @access private |
|
75 | + * @var int |
|
76 | + */ |
|
77 | + private static $_iFormIncrement = 0; |
|
78 | + |
|
79 | + /** |
|
80 | + * number of form |
|
81 | + * |
|
82 | + * @access private |
|
83 | + * @var int |
|
84 | + */ |
|
85 | + private $_iFormNumber = 0; |
|
86 | + |
|
87 | + /** |
|
88 | + * Separator between fields of form |
|
89 | + * |
|
90 | + * @access private |
|
91 | + * @var string |
|
92 | + */ |
|
93 | + private $_sSeparator = '<br/>'; |
|
94 | + |
|
95 | + /** |
|
96 | + * The entity to save with the formular |
|
97 | + * |
|
98 | + * @access private |
|
99 | + * @var string |
|
100 | + */ |
|
101 | + private $_sSynchronizeEntity = null; |
|
102 | + |
|
103 | + /** |
|
104 | + * The id of entity |
|
105 | + * |
|
106 | + * @access private |
|
107 | + * @var int |
|
108 | + */ |
|
109 | + private $_iIdEntity = null; |
|
110 | + |
|
111 | + /** |
|
112 | + * The entity to save with the formular |
|
113 | + * |
|
114 | + * @access private |
|
115 | + * @var int |
|
116 | + */ |
|
117 | + private $_iIdEntityCreated = null; |
|
118 | + |
|
119 | + /** |
|
120 | + * constructor that it increment (static) for all use |
|
121 | + * |
|
122 | + * @access public |
|
123 | + */ |
|
124 | + public function __construct() |
|
125 | + { |
|
126 | + self::$_iFormIncrement++; |
|
127 | + $this->_iFormNumber = self::$_iFormIncrement; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * add an element in the form |
|
132 | + * |
|
133 | + * @access public |
|
134 | + * @param string $sName name |
|
135 | + * @param string|\Venus\lib\Form $mType type of field |
|
136 | + * @param string $sLabel label of field |
|
137 | + * @param mixed $mValue value of field |
|
138 | + * @parma mixed $mOptions options (for select) |
|
139 | + * @return \Venus\lib\Form |
|
140 | + */ |
|
141 | + public function add($sName, $mType, $sLabel = null, $mValue = null, $mOptions = null) |
|
142 | + { |
|
143 | + if ($mType instanceof Container) { |
|
144 | + |
|
145 | + $this->_aElement[$sName] = $mType; |
|
146 | + } else if ($mType === 'text' || $mType === 'submit' || $mType === 'password' || $mType === 'file' || $mType === 'tel' |
|
147 | + || $mType === 'url' || $mType === 'email' || $mType === 'search' || $mType === 'date' || $mType === 'time' |
|
148 | + || $mType === 'datetime' || $mType === 'month' || $mType === 'week' || $mType === 'number' || $mType === 'range' |
|
149 | + || $mType === 'color') { |
|
150 | + |
|
151 | + $this->_aElement[$sName] = new Input($sName, $mType, $sLabel, $mValue); |
|
152 | + } elseif ($mType === 'textarea') { |
|
153 | + |
|
154 | + $this->_aElement[$sName] = new Textarea($sName, $sLabel, $mValue); |
|
155 | + } else if ($mType === 'select') { |
|
156 | + |
|
157 | + $this->_aElement[$sName] = new Select($sName, $mOptions, $sLabel, $mValue); |
|
158 | + } else if ($mType === 'label') { |
|
159 | + |
|
160 | + $this->_aElement[$sName] = new Label($sName); |
|
161 | + } else if ($mType === 'list_checkbox') { |
|
162 | + |
|
163 | + $i = 0; |
|
164 | + |
|
165 | + $this->_aElement[$sName.'_'.$i++] = new Label($sLabel); |
|
166 | + |
|
167 | + foreach ($mValue as $mKey => $sValue) { |
|
168 | + |
|
169 | + $this->_aElement[$sName.'_'.$i++] = new Checkbox($sName, $sValue, $mKey, $mOptions); |
|
170 | + } |
|
171 | + } else if ($mType === 'checkbox') { |
|
172 | + |
|
173 | + $this->_aElement[$sName] = new Checkbox($sName, $sLabel, $mValue, $mOptions); |
|
174 | + } else if ($mType === 'radio') { |
|
175 | + |
|
176 | + $this->_aElement[$sName.rand(100000, 999999)] = new Radio($sName, $sLabel, $mValue, $mOptions); |
|
177 | + } else if ($mType === 'date') { |
|
178 | + |
|
179 | + $aDay = array(); |
|
180 | + |
|
181 | + for ($i = 1; $i <= 31; $i++) { |
|
182 | + |
|
183 | + if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
|
184 | + else { $aDay[$i] = $i; } |
|
185 | + } |
|
186 | + |
|
187 | + $this->_aElement[$sName.'_day'] = new Select($sName, $aDay); |
|
188 | + |
|
189 | + $aMonth = array( |
|
190 | + '01' => 'Jan', |
|
191 | + '02' => 'Feb', |
|
192 | + '03' => 'Mar', |
|
193 | + '04' => 'Apr', |
|
194 | + '05' => 'May', |
|
195 | + '06' => 'Jun', |
|
196 | + '07' => 'Jui', |
|
197 | + '08' => 'Aug', |
|
198 | + '09' => 'Sep', |
|
199 | + '10' => 'Oct', |
|
200 | + '11' => 'Nov', |
|
201 | + '12' => 'Dec', |
|
202 | + ); |
|
203 | + |
|
204 | + $this->_aElement[$sName.'_month'] = new Select($sName, $aMonth); |
|
205 | + |
|
206 | + $aYear = array(); |
|
207 | + |
|
208 | + for ($i = 1900; $i <= 2013; $i++) { |
|
209 | + |
|
210 | + $aYear[$i] = $i; |
|
211 | + } |
|
212 | + |
|
213 | + $this->_aElement[$sName.'_year'] = new Select($sName, $aMonth); |
|
214 | + } |
|
215 | + |
|
216 | + return $this; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * get id entity created by the formular |
|
221 | + * |
|
222 | + * @access public |
|
223 | + * @return int |
|
224 | + */ |
|
225 | + public function getIdEntityCreated() : int |
|
226 | + { |
|
227 | + return $this->_iIdEntityCreated; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * set id entity created by the formular |
|
232 | + * |
|
233 | + * @access public |
|
234 | + * @param int $iIdEntityCreated |
|
235 | + * @return Form |
|
236 | + */ |
|
237 | + public function setIdEntityCreated(int $iIdEntityCreated) : Form |
|
238 | + { |
|
239 | + $this->_iIdEntityCreated = $iIdEntityCreated; |
|
240 | + return $this; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * get form number |
|
245 | + * |
|
246 | + * @access public |
|
247 | + * @return int |
|
248 | + */ |
|
249 | + public function getFormNumber() : int |
|
250 | + { |
|
251 | + return $this->_iFormNumber; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * set id entity created by the formular |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @param int $iFormNumber |
|
259 | - * @return Form |
|
260 | - */ |
|
261 | - public function setFormNumber(int $iFormNumber) : Form |
|
262 | - { |
|
263 | - $this->_iFormNumber = $iFormNumber; |
|
264 | - return $this; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * get global form |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @return \Venus\lib\Form\Container |
|
272 | - */ |
|
273 | - public function getForm() |
|
274 | - { |
|
275 | - $oForm = $this->getFormInObject(); |
|
276 | - |
|
277 | - $sFormContent = $oForm->start; |
|
278 | - |
|
279 | - foreach ($oForm->form as $sValue) { |
|
280 | - |
|
281 | - $sFormContent .= $sValue.$this->_sSeparator; |
|
282 | - } |
|
283 | - |
|
284 | - $sFormContent .= $oForm->end; |
|
285 | - |
|
286 | - $oContainer = new Container; |
|
287 | - $oContainer->setView($sFormContent) |
|
288 | - ->setForm($this); |
|
289 | - |
|
290 | - return $oContainer; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * get global object form |
|
296 | - * |
|
297 | - * @access public |
|
298 | - * @return \stdClass |
|
299 | - */ |
|
300 | - public function getFormInObject() |
|
301 | - { |
|
302 | - $sExKey = null; |
|
303 | - |
|
304 | - if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) { |
|
305 | - |
|
306 | - $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity); |
|
307 | - $oModel = new $sModelName; |
|
308 | - |
|
309 | - $oEntity = new $this->_sSynchronizeEntity; |
|
310 | - $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
311 | - $sMethodName = 'findOneBy'.$sPrimaryKey; |
|
312 | - $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity)); |
|
313 | - |
|
314 | - if (is_object($oCompleteEntity)) { |
|
315 | - |
|
316 | - foreach ($this->_aElement as $sKey => $sValue) { |
|
317 | - |
|
318 | - if ($sValue instanceof \Venus\lib\Form\Radio) { |
|
319 | - |
|
320 | - $sExKey = $sKey; |
|
321 | - $sKey = substr($sKey, 0, -6); |
|
322 | - } |
|
323 | - |
|
324 | - if ($sValue instanceof Form) { |
|
325 | - |
|
326 | - ; |
|
327 | - } else { |
|
328 | - |
|
329 | - $sMethodNameInEntity = 'get_'.$sKey; |
|
330 | - $mValue = $oCompleteEntity->$sMethodNameInEntity(); |
|
331 | - |
|
332 | - if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) { |
|
333 | - |
|
334 | - $this->_aElement[$sExKey]->setValueChecked($mValue); |
|
335 | - } else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
336 | - |
|
337 | - $this->_aElement[$sKey]->setValue($mValue); |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - $oForm = new \StdClass(); |
|
345 | - $oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">'; |
|
346 | - $oForm->form = array(); |
|
347 | - |
|
348 | - foreach ($this->_aElement as $sKey => $sValue) { |
|
349 | - |
|
350 | - if ($sValue instanceof Container) { |
|
351 | - |
|
352 | - $oForm->form[$sKey] = $sValue; |
|
353 | - } else { |
|
354 | - |
|
355 | - $oForm->form[$sKey] = $sValue->fetch(); |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - $oForm->end = '</form>'; |
|
360 | - |
|
361 | - return $oForm; |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * get an element of formular |
|
366 | - * |
|
367 | - * @access public |
|
368 | - * @param string $sName name |
|
369 | - * @return object |
|
370 | - */ |
|
371 | - public function get($sName) |
|
372 | - { |
|
373 | - return $this->_aElement[$sName]; |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * get the form separator |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @return string |
|
381 | - */ |
|
382 | - public function getSeparator() |
|
383 | - { |
|
384 | - return $this->_sSeparator; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * set the form separator |
|
389 | - * |
|
390 | - * @access public |
|
391 | - * @param string $sSeparator separator between the fields |
|
392 | - * @return \Venus\lib\Form |
|
393 | - */ |
|
394 | - public function setSeparator($sSeparator) |
|
395 | - { |
|
396 | - $this->_sSeparator = $sSeparator; |
|
397 | - return $this; |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * set the entity to synchronize with the formular |
|
402 | - * |
|
403 | - * @access public |
|
404 | - * @param $sSynchronizeEntity |
|
405 | - * @param int $iId id of the primary key |
|
406 | - * @return Form |
|
407 | - * @internal param string $sSeparator separator between the fields |
|
408 | - */ |
|
409 | - public function synchronizeEntity($sSynchronizeEntity, $iId = null) |
|
410 | - { |
|
411 | - if ($iId !== null) { $this->_iIdEntity = $iId; } |
|
412 | - |
|
413 | - $this->_sSynchronizeEntity = $sSynchronizeEntity; |
|
414 | - return $this; |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * add constraint |
|
419 | - * |
|
420 | - * @access public |
|
421 | - * @param string $sName field name |
|
422 | - * @param object $oConstraint constraint on the field |
|
423 | - * @return \Venus\lib\Form |
|
424 | - */ |
|
425 | - public function addConstraint($sName, $oConstraint) |
|
426 | - { |
|
427 | - if ($this->_aElement[$sName] instanceof Input || $this->_aElement[$sName] instanceof Textarea) { |
|
428 | - |
|
429 | - $this->_aElement[$sName]->setConstraint($oConstraint); |
|
430 | - } |
|
431 | - |
|
432 | - return $this; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * get all elements |
|
437 | - * |
|
438 | - * @access public |
|
439 | - * @return array |
|
440 | - */ |
|
441 | - public function getElement() { |
|
442 | - |
|
443 | - return $this->_aElement; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * get all elements |
|
448 | - * |
|
449 | - * @access public |
|
450 | - * @return int |
|
451 | - */ |
|
452 | - public function getIdEntity() { |
|
453 | - |
|
454 | - return $this->_iIdEntity; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * get all elements |
|
459 | - * |
|
460 | - * @access public |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public function getSynchronizeEntity() { |
|
464 | - |
|
465 | - return $this->_sSynchronizeEntity; |
|
466 | - } |
|
254 | + /** |
|
255 | + * set id entity created by the formular |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @param int $iFormNumber |
|
259 | + * @return Form |
|
260 | + */ |
|
261 | + public function setFormNumber(int $iFormNumber) : Form |
|
262 | + { |
|
263 | + $this->_iFormNumber = $iFormNumber; |
|
264 | + return $this; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * get global form |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @return \Venus\lib\Form\Container |
|
272 | + */ |
|
273 | + public function getForm() |
|
274 | + { |
|
275 | + $oForm = $this->getFormInObject(); |
|
276 | + |
|
277 | + $sFormContent = $oForm->start; |
|
278 | + |
|
279 | + foreach ($oForm->form as $sValue) { |
|
280 | + |
|
281 | + $sFormContent .= $sValue.$this->_sSeparator; |
|
282 | + } |
|
283 | + |
|
284 | + $sFormContent .= $oForm->end; |
|
285 | + |
|
286 | + $oContainer = new Container; |
|
287 | + $oContainer->setView($sFormContent) |
|
288 | + ->setForm($this); |
|
289 | + |
|
290 | + return $oContainer; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * get global object form |
|
296 | + * |
|
297 | + * @access public |
|
298 | + * @return \stdClass |
|
299 | + */ |
|
300 | + public function getFormInObject() |
|
301 | + { |
|
302 | + $sExKey = null; |
|
303 | + |
|
304 | + if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) { |
|
305 | + |
|
306 | + $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity); |
|
307 | + $oModel = new $sModelName; |
|
308 | + |
|
309 | + $oEntity = new $this->_sSynchronizeEntity; |
|
310 | + $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
311 | + $sMethodName = 'findOneBy'.$sPrimaryKey; |
|
312 | + $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity)); |
|
313 | + |
|
314 | + if (is_object($oCompleteEntity)) { |
|
315 | + |
|
316 | + foreach ($this->_aElement as $sKey => $sValue) { |
|
317 | + |
|
318 | + if ($sValue instanceof \Venus\lib\Form\Radio) { |
|
319 | + |
|
320 | + $sExKey = $sKey; |
|
321 | + $sKey = substr($sKey, 0, -6); |
|
322 | + } |
|
323 | + |
|
324 | + if ($sValue instanceof Form) { |
|
325 | + |
|
326 | + ; |
|
327 | + } else { |
|
328 | + |
|
329 | + $sMethodNameInEntity = 'get_'.$sKey; |
|
330 | + $mValue = $oCompleteEntity->$sMethodNameInEntity(); |
|
331 | + |
|
332 | + if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) { |
|
333 | + |
|
334 | + $this->_aElement[$sExKey]->setValueChecked($mValue); |
|
335 | + } else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
336 | + |
|
337 | + $this->_aElement[$sKey]->setValue($mValue); |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + $oForm = new \StdClass(); |
|
345 | + $oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">'; |
|
346 | + $oForm->form = array(); |
|
347 | + |
|
348 | + foreach ($this->_aElement as $sKey => $sValue) { |
|
349 | + |
|
350 | + if ($sValue instanceof Container) { |
|
351 | + |
|
352 | + $oForm->form[$sKey] = $sValue; |
|
353 | + } else { |
|
354 | + |
|
355 | + $oForm->form[$sKey] = $sValue->fetch(); |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + $oForm->end = '</form>'; |
|
360 | + |
|
361 | + return $oForm; |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * get an element of formular |
|
366 | + * |
|
367 | + * @access public |
|
368 | + * @param string $sName name |
|
369 | + * @return object |
|
370 | + */ |
|
371 | + public function get($sName) |
|
372 | + { |
|
373 | + return $this->_aElement[$sName]; |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * get the form separator |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @return string |
|
381 | + */ |
|
382 | + public function getSeparator() |
|
383 | + { |
|
384 | + return $this->_sSeparator; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * set the form separator |
|
389 | + * |
|
390 | + * @access public |
|
391 | + * @param string $sSeparator separator between the fields |
|
392 | + * @return \Venus\lib\Form |
|
393 | + */ |
|
394 | + public function setSeparator($sSeparator) |
|
395 | + { |
|
396 | + $this->_sSeparator = $sSeparator; |
|
397 | + return $this; |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * set the entity to synchronize with the formular |
|
402 | + * |
|
403 | + * @access public |
|
404 | + * @param $sSynchronizeEntity |
|
405 | + * @param int $iId id of the primary key |
|
406 | + * @return Form |
|
407 | + * @internal param string $sSeparator separator between the fields |
|
408 | + */ |
|
409 | + public function synchronizeEntity($sSynchronizeEntity, $iId = null) |
|
410 | + { |
|
411 | + if ($iId !== null) { $this->_iIdEntity = $iId; } |
|
412 | + |
|
413 | + $this->_sSynchronizeEntity = $sSynchronizeEntity; |
|
414 | + return $this; |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * add constraint |
|
419 | + * |
|
420 | + * @access public |
|
421 | + * @param string $sName field name |
|
422 | + * @param object $oConstraint constraint on the field |
|
423 | + * @return \Venus\lib\Form |
|
424 | + */ |
|
425 | + public function addConstraint($sName, $oConstraint) |
|
426 | + { |
|
427 | + if ($this->_aElement[$sName] instanceof Input || $this->_aElement[$sName] instanceof Textarea) { |
|
428 | + |
|
429 | + $this->_aElement[$sName]->setConstraint($oConstraint); |
|
430 | + } |
|
431 | + |
|
432 | + return $this; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * get all elements |
|
437 | + * |
|
438 | + * @access public |
|
439 | + * @return array |
|
440 | + */ |
|
441 | + public function getElement() { |
|
442 | + |
|
443 | + return $this->_aElement; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * get all elements |
|
448 | + * |
|
449 | + * @access public |
|
450 | + * @return int |
|
451 | + */ |
|
452 | + public function getIdEntity() { |
|
453 | + |
|
454 | + return $this->_iIdEntity; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * get all elements |
|
459 | + * |
|
460 | + * @access public |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public function getSynchronizeEntity() { |
|
464 | + |
|
465 | + return $this->_sSynchronizeEntity; |
|
466 | + } |
|
467 | 467 | } |
@@ -30,69 +30,69 @@ |
||
30 | 30 | */ |
31 | 31 | class Mock implements CacheInterface |
32 | 32 | { |
33 | - /** |
|
34 | - * get a value |
|
35 | - * |
|
36 | - * @access public |
|
37 | - * @param string $sName name of the session |
|
38 | - * @param int $iFlags flags |
|
39 | - * @param int $iTimeout expiration of cache |
|
40 | - * @return boolean |
|
41 | - */ |
|
42 | - public function get(string $sName, int&$iFlags = null, int $iTimeout = 0) |
|
43 | - { |
|
44 | - return false; |
|
45 | - } |
|
33 | + /** |
|
34 | + * get a value |
|
35 | + * |
|
36 | + * @access public |
|
37 | + * @param string $sName name of the session |
|
38 | + * @param int $iFlags flags |
|
39 | + * @param int $iTimeout expiration of cache |
|
40 | + * @return boolean |
|
41 | + */ |
|
42 | + public function get(string $sName, int&$iFlags = null, int $iTimeout = 0) |
|
43 | + { |
|
44 | + return false; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * set a value |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @param string $sName name of the session |
|
52 | - * @param mixed $mValue value of this sesion var |
|
53 | - * @param int $iFlag unused |
|
54 | - * @param int $iExpire expiration of cache |
|
55 | - * @return boolean |
|
56 | - */ |
|
57 | - public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false) |
|
58 | - { |
|
59 | - return true; |
|
60 | - } |
|
47 | + /** |
|
48 | + * set a value |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @param string $sName name of the session |
|
52 | + * @param mixed $mValue value of this sesion var |
|
53 | + * @param int $iFlag unused |
|
54 | + * @param int $iExpire expiration of cache |
|
55 | + * @return boolean |
|
56 | + */ |
|
57 | + public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false) |
|
58 | + { |
|
59 | + return true; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * flush the cache |
|
64 | - * |
|
65 | - * @access public |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public function flush() |
|
69 | - { |
|
70 | - return false; |
|
71 | - } |
|
62 | + /** |
|
63 | + * flush the cache |
|
64 | + * |
|
65 | + * @access public |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public function flush() |
|
69 | + { |
|
70 | + return false; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * delete a value |
|
75 | - * |
|
76 | - * @access public |
|
77 | - * @param string $sName name of the session |
|
78 | - * @return boolean |
|
79 | - */ |
|
80 | - public function delete(string $sName) |
|
81 | - { |
|
82 | - return false; |
|
83 | - } |
|
73 | + /** |
|
74 | + * delete a value |
|
75 | + * |
|
76 | + * @access public |
|
77 | + * @param string $sName name of the session |
|
78 | + * @return boolean |
|
79 | + */ |
|
80 | + public function delete(string $sName) |
|
81 | + { |
|
82 | + return false; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * add |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @param string $sName name of the session |
|
90 | - * @param mixed $mValue value of this sesion var |
|
91 | - * @param int $iExpire expiration of cache |
|
92 | - * @return boolean |
|
93 | - */ |
|
94 | - public function add($sName, $mValue, $iExpire = false) |
|
95 | - { |
|
96 | - return true; |
|
97 | - } |
|
85 | + /** |
|
86 | + * add |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @param string $sName name of the session |
|
90 | + * @param mixed $mValue value of this sesion var |
|
91 | + * @param int $iExpire expiration of cache |
|
92 | + * @return boolean |
|
93 | + */ |
|
94 | + public function add($sName, $mValue, $iExpire = false) |
|
95 | + { |
|
96 | + return true; |
|
97 | + } |
|
98 | 98 | } |