Overview

Namespaces

  • PHP
  • PhpOptions
    • Types

Classes

  • AType
  • CharType
  • DatetimeType
  • DateType
  • DirectoryType
  • EmailType
  • EnumType
  • FileType
  • InifileType
  • IntegerType
  • RealType
  • SeriesType
  • StringType
  • TimeType
  • Types
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: /**
 4:  * PhpOptions
 5:  * @link https://github.com/masicek/PhpOptions
 6:  * @author Viktor Mašíček <viktor@masicek.net>
 7:  * @license "New" BSD License
 8:  */
 9: 
10: namespace PhpOptions\Types;
11: 
12: require_once __DIR__ . '/AType.php';
13: 
14: /**
15:  * Integer type
16:  *
17:  * @author Viktor Mašíček <viktor@masicek.net>
18:  */
19: class IntegerType extends AType
20: {
21: 
22:     /**
23:      * Flag for check signed/unsigned
24:      *
25:      * @var bool
26:      */
27:     private $unsigned = FALSE;
28: 
29: 
30:     /**
31:      * Set object
32:      * 'unsigned' => accept only unsigned value
33:      *
34:      * @param array $setting Array of setting of object
35:      */
36:     public function __construct($settings = array())
37:     {
38:         parent::__construct($settings);
39:         if ($this->settingsHasFlag('unsigned', $settings))
40:         {
41:             $this->unsigned = TRUE;
42:         }
43:     }
44: 
45: 
46:     /**
47:      * Check type of value.
48:      *
49:      * @param mixed $value Checked value
50:      *
51:      * @return bool
52:      */
53:     public function check($value)
54:     {
55:         if ($this->unsigned)
56:         {
57:             return (bool) preg_match('/^[+]?[0-9]+$/', $value);
58:         }
59:         else
60:         {
61:             return (bool) preg_match('/^[-+]?[0-9]+$/', $value);
62:         }
63:     }
64: 
65: 
66:     /**
67:      * Return uppercase name of type
68:      *
69:      * @return string
70:      */
71:     public function getName()
72:     {
73:         return parent::getName() . ($this->unsigned ? ' UNSIGNED' : '');
74:     }
75: 
76: 
77:     /**
78:      * Return modified value
79:      *
80:      * @param mixed $value Filtered value
81:      *
82:      * @return mixed
83:      */
84:     protected function useFilter($value)
85:     {
86:         return (integer)$value;
87:     }
88: 
89: 
90: }
91: 
PhpOptions API documentation generated by ApiGen.
Generated using the TokenReflection library.