PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.7
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Cell / DefaultValueBinder.php

DefaultValueBinder.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.4.7, at vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php

83 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Cell;
4
5 use DateTimeInterface;
6 use PhpOffice\PhpSpreadsheet\RichText\RichText;
7 use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
8
9 class DefaultValueBinder implements IValueBinder
10 {
11 /**
12 * Bind value to a cell.
13 *
14 * @param Cell $cell Cell to bind value to
15 * @param mixed $value Value to bind in cell
16 *
17 * @throws \PhpOffice\PhpSpreadsheet\Exception
18 *
19 * @return bool
20 */
21 public function bindValue(Cell $cell, $value)
22 {
23 // sanitize UTF-8 strings
24 if (is_string($value)) {
25 $value = StringHelper::sanitizeUTF8($value);
26 } elseif (is_object($value)) {
27 // Handle any objects that might be injected
28 if ($value instanceof DateTimeInterface) {
29 $value = $value->format('Y-m-d H:i:s');
30 } elseif (!($value instanceof RichText)) {
31 $value = (string) $value;
32 }
33 }
34
35 // Set value explicit
36 $cell->setValueExplicit($value, static::dataTypeForValue($value));
37
38 // Done!
39 return true;
40 }
41
42 /**
43 * DataType for value.
44 *
45 * @param mixed $pValue
46 *
47 * @return string
48 */
49 public static function dataTypeForValue($pValue)
50 {
51 // Match the value against a few data types
52 if ($pValue === null) {
53 return DataType::TYPE_NULL;
54 } elseif ($pValue === '') {
55 return DataType::TYPE_STRING;
56 } elseif ($pValue instanceof RichText) {
57 return DataType::TYPE_INLINE;
58 } elseif ($pValue[0] === '=' && strlen($pValue) > 1) {
59 return DataType::TYPE_FORMULA;
60 } elseif (is_bool($pValue)) {
61 return DataType::TYPE_BOOL;
62 } elseif (is_float($pValue) || is_int($pValue)) {
63 return DataType::TYPE_NUMERIC;
64 } elseif (preg_match('/^[\+\-]?(\d+\\.?\d*|\d*\\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $pValue)) {
65 $tValue = ltrim($pValue, '+-');
66 if (is_string($pValue) && $tValue[0] === '0' && strlen($tValue) > 1 && $tValue[1] !== '.') {
67 return DataType::TYPE_STRING;
68 } elseif ((strpos($pValue, '.') === false) && ($pValue > PHP_INT_MAX)) {
69 return DataType::TYPE_STRING;
70 }
71
72 return DataType::TYPE_NUMERIC;
73 } elseif (is_string($pValue)) {
74 $errorCodes = DataType::getErrorCodes();
75 if (isset($errorCodes[$pValue])) {
76 return DataType::TYPE_ERROR;
77 }
78 }
79
80 return DataType::TYPE_STRING;
81 }
82 }
83