1 <?php
2
3 /* --------------------------------------------------------------
4 IntType.inc.php 2015-11-04 gm
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13 /**
14 * Class IntType
15 *
16 * Shared int type class. Use the "asInt" method for getting the plain value.
17 *
18 * @category System
19 * @package Shared
20 * @subpackage Types
21 */
22 class IntType
23 {
24 /**
25 * Instance Value
26 *
27 * @var int
28 */
29 protected $value;
30
31
32 /**
33 * Class Constructor
34 *
35 * @throws InvalidArgumentException
36 *
37 * @param int $p_value
38 */
39 public function __construct($p_value)
40 {
41 if(!is_numeric($p_value) || (int)$p_value != $p_value || is_float($p_value)
42 || (is_string($p_value) && strpos($p_value, '.'))
43 )
44 {
45 throw new InvalidArgumentException('IntType: Invalid argument value given (expected numeric int got '
46 . gettype($p_value) . '): ' . $p_value);
47 }
48
49 $this->value = (int)$p_value;
50 }
51
52
53 /**
54 * Get the instance value as int.
55 *
56 * @return int
57 */
58 public function asInt()
59 {
60 return $this->value;
61 }
62 }