1: <?php
2:
3: /**
4: * Jyxo PHP Library
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: * It is also available through the world-wide-web at this URL:
11: * https://github.com/jyxo/php/blob/master/license.txt
12: */
13:
14: /**
15: * Exception used by the Jyxo_Time_Composer.
16: *
17: * Stores information which unit was incorrectly provided.
18: *
19: * @category Jyxo
20: * @package Jyxo_Time
21: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
22: * @license https://github.com/jyxo/php/blob/master/license.txt
23: * @author Martin Šamšula
24: */
25: class Jyxo_Time_ComposerException extends Jyxo_Exception
26: {
27: /**
28: * Exception type - second.
29: *
30: * @var integer
31: */
32: const SECOND = 1;
33:
34: /**
35: * Exception type - minute.
36: *
37: * @var integer
38: */
39: const MINUTE = 2;
40:
41: /**
42: * Exception type - hour.
43: *
44: * @var integer
45: */
46: const HOUR = 3;
47:
48: /**
49: * Exception type - day.
50: *
51: * @var integer
52: */
53: const DAY = 4;
54:
55: /**
56: * Exception type - month.
57: *
58: * @var integer
59: */
60: const MONTH = 5;
61:
62: /**
63: * Exception type - year.
64: *
65: * @var integer
66: */
67: const YEAR = 6;
68:
69: /**
70: * Exception type - incomplete date.
71: *
72: * @var integer
73: */
74: const NOT_COMPLETE = 7;
75:
76: /**
77: * Exception type - invalid date.
78: *
79: * @var integer
80: */
81: const INVALID = 8;
82:
83: /**
84: * Exception type - unknown.
85: *
86: * @var integer
87: */
88: const UNKNOWN = 0;
89:
90: /**
91: * Constructor.
92: *
93: * @param string $message Exception message
94: * @param integer $code Exception code (type)
95: */
96: public function __construct($message, $code)
97: {
98: static $allowedUnits = array(
99: self::SECOND,
100: self::MINUTE,
101: self::HOUR,
102: self::DAY,
103: self::MONTH,
104: self::YEAR,
105: self::INVALID,
106: self::NOT_COMPLETE
107: );
108:
109: if (!in_array($code, $allowedUnits)) {
110: $code = self::UNKNOWN;
111: }
112:
113: parent::__construct($message, $code);
114: }
115: }
116: