1 <?php
2 /* --------------------------------------------------------------
3 IdType.inc.php 2015-01-16 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 /**
13 * Class IdType
14 *
15 * IMPORTANT:
16 * When you need to cast an Id object to integer, cast it first to string,
17 * because otherwise the following command will return always 1:
18 *
19 * EXAMPLE:
20 * $id = new IdType(948);
21 * bad - (int)$id >> 1
22 * good - (int)(string)$id >> 948
23 *
24 * @category System
25 * @package Shared
26 * @subpackage Types
27 */
28 class IdType extends IntType implements IdInterface
29 {
30 /**
31 * Instance Value
32 *
33 * @var int
34 */
35 protected $value;
36
37
38 /**
39 * Class Constructor
40 *
41 * @param int $p_value
42 *
43 * @throws InvalidArgumentException On negative values.
44 */
45 public function __construct($p_value)
46 {
47 parent::__construct($p_value);
48
49 if((int)$p_value < 0)
50 {
51 throw new InvalidArgumentException(__CLASS__
52 . ': Invalid argument value given (expected positive integer got '
53 . gettype($p_value) . '): ' . $p_value);
54 }
55 }
56
57
58 /**
59 * To string method is left for backwards compatibility.
60 *
61 * @return string
62 */
63 public function __toString()
64 {
65 return (string)$this->value;
66 }
67 }