1 | <?php |
||
47 | class Id implements SerializablePropertyInterface |
||
48 | { |
||
49 | /** |
||
50 | * Object ID |
||
51 | * |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $uid = null; |
||
55 | /** |
||
56 | * Provisional ID |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | const PROVISIONAL = 0; |
||
61 | |||
62 | /** |
||
63 | * ID constructor |
||
64 | * |
||
65 | * @param int $uid Object ID |
||
66 | */ |
||
67 | 47 | public function __construct($uid) |
|
68 | { |
||
69 | // If the ID is invalid |
||
70 | 47 | if (!is_int($uid) || ($uid < self::PROVISIONAL)) { |
|
71 | 1 | throw new InvalidArgumentException( |
|
72 | 1 | sprintf('Invalid object ID "%s"', $uid), |
|
73 | InvalidArgumentException::INVALID_OBJECT_ID |
||
74 | 1 | ); |
|
75 | } |
||
76 | |||
77 | 46 | $this->uid = $uid; |
|
78 | 46 | } |
|
79 | |||
80 | /** |
||
81 | * Unserialize the string representation of this property |
||
82 | * |
||
83 | * @param string $str Serialized property |
||
84 | * @return Id ID property |
||
85 | */ |
||
86 | 7 | public static function unserialize($str) |
|
90 | |||
91 | /** |
||
92 | * Serialize the property |
||
93 | * |
||
94 | * @return mixed Property serialization |
||
95 | */ |
||
96 | 2 | public function serialize() |
|
100 | |||
101 | /** |
||
102 | * Return the object ID |
||
103 | * |
||
104 | * @return int Object ID |
||
105 | */ |
||
106 | 24 | public function getId() |
|
110 | |||
111 | /** |
||
112 | * Test if this ID is provisional |
||
113 | * |
||
114 | * @return bool Provisional ID |
||
115 | */ |
||
116 | 8 | public function isProvisional() { |
|
119 | } |
||
120 |