1: <?php
2:
3: /**
4: * Pry Framework
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file LICENSE.txt.
10: *
11: */
12:
13: namespace Pry\Validate\Validator;
14:
15: use Pry\Validate\ValidateAbstract;
16:
17: /**
18: * Validateur d'heure format sql.
19: * @category Pry
20: * @package Validate
21: * @subpackage Validate_Validator
22: * @version 1.0.0
23: * @author Olivier ROGER <oroger.fr>
24: *
25: */
26: class Time extends ValidateAbstract
27: {
28:
29: /**
30: * Constructeur
31: * @access public
32: */
33: public function __construct()
34: {
35: $this->errorMsg = "n'est pas une heure valide";
36: }
37:
38: /**
39: * Validation
40: *
41: * @param string $string Elément à valider
42: * @return boolean
43: */
44: public function isValid($string)
45: {
46: $string = $this->cleanString((string) $string);
47: $pattern = '`^([0-9]{2}:[0-9]{2}:[0-9]{2})$`';
48: if (preg_match($pattern, $string))
49: {
50: list($heure, $min, $sec) = explode(':', $string);
51: if (($heure >= 0 && $heure < 24) && ($min >= 0 && $min < 60) && ($sec >= 0 && $sec < 60))
52: return true;
53: }
54: return false;
55: }
56:
57: }