1 | <?php |
||
12 | class Cell |
||
13 | { |
||
14 | /** |
||
15 | * Numeric cell type (whole numbers, fractional numbers, dates) |
||
16 | */ |
||
17 | const TYPE_NUMERIC = 0; |
||
18 | |||
19 | /** |
||
20 | * String (text) cell type |
||
21 | */ |
||
22 | const TYPE_STRING = 1; |
||
23 | |||
24 | /** |
||
25 | * Formula cell type |
||
26 | * Not used at the moment |
||
27 | */ |
||
28 | const TYPE_FORMULA = 2; |
||
29 | |||
30 | /** |
||
31 | * Empty cell type |
||
32 | */ |
||
33 | const TYPE_EMPTY = 3; |
||
34 | |||
35 | /** |
||
36 | * Boolean cell type |
||
37 | */ |
||
38 | const TYPE_BOOLEAN = 4; |
||
39 | |||
40 | /** |
||
41 | * Error cell type |
||
42 | */ |
||
43 | const TYPE_ERROR = 5; |
||
44 | |||
45 | /** |
||
46 | * The value of this cell |
||
47 | * @var mixed|null |
||
48 | */ |
||
49 | protected $value = null; |
||
50 | |||
51 | /** |
||
52 | * The cell type |
||
53 | * @var int|null |
||
54 | */ |
||
55 | protected $type = null; |
||
56 | |||
57 | /** |
||
58 | * Cell constructor. |
||
59 | * @param $value mixed |
||
60 | */ |
||
61 | 65 | public function __construct($value) |
|
62 | { |
||
63 | 65 | $this->setValue($value); |
|
64 | 65 | } |
|
65 | |||
66 | /** |
||
67 | * @param $value mixed |
||
68 | */ |
||
69 | 65 | public function setValue($value) |
|
70 | { |
||
71 | 65 | $this->value = $value; |
|
72 | 65 | $this->type = $this->detectType($value); |
|
73 | 65 | } |
|
74 | |||
75 | /** |
||
76 | * @return mixed|null |
||
77 | */ |
||
78 | 64 | public function getValue() |
|
79 | { |
||
80 | 64 | return $this->value; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return int|null |
||
85 | */ |
||
86 | public function getType() |
||
87 | { |
||
88 | return $this->type; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Get the current value type |
||
93 | * @return int |
||
94 | */ |
||
95 | 65 | protected function detectType($value) |
|
109 | |||
110 | /** |
||
111 | * @return bool |
||
112 | */ |
||
113 | 12 | public function isBoolean() |
|
114 | { |
||
115 | 12 | return $this->type === self::TYPE_BOOLEAN; |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * @return bool |
||
120 | */ |
||
121 | 8 | public function isEmpty() |
|
122 | { |
||
123 | 8 | return $this->type === self::TYPE_EMPTY; |
|
124 | } |
||
125 | |||
126 | /** |
||
127 | * Not used at the moment |
||
128 | * @return bool |
||
129 | */ |
||
130 | public function isFormula() |
||
134 | |||
135 | /** |
||
136 | * @return bool |
||
137 | */ |
||
138 | 11 | public function isNumeric() |
|
139 | { |
||
140 | 11 | return $this->type === self::TYPE_NUMERIC; |
|
141 | } |
||
142 | |||
143 | /** |
||
144 | * @return bool |
||
145 | */ |
||
146 | 64 | public function isString() |
|
147 | { |
||
148 | 64 | return $this->type === self::TYPE_STRING; |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * @return bool |
||
153 | */ |
||
154 | public function isError() |
||
158 | |||
159 | /** |
||
160 | * @return string |
||
161 | */ |
||
162 | 1 | public function __toString() |
|
163 | { |
||
164 | 1 | return (string)$this->value; |
|
165 | } |
||
166 | } |
||
167 |