ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder Class Reference
+ Inheritance diagram for PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder:
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder:

Public Member Functions

 bindValue (Cell $cell, $value)
 Bind value to a cell. More...
 

Static Public Member Functions

static dataTypeForValue ($value)
 DataType for value. More...
 

Detailed Description

Definition at line 9 of file DefaultValueBinder.php.

Member Function Documentation

◆ bindValue()

PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder::bindValue ( Cell  $cell,
  $value 
)

Bind value to a cell.

Parameters
Cell$cellCell to bind value to
mixed$valueValue to bind in cell
Returns
bool

Implements PhpOffice\PhpSpreadsheet\Cell\IValueBinder.

Definition at line 19 of file DefaultValueBinder.php.

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\sanitizeUTF8(), and PhpOffice\PhpSpreadsheet\Cell\Cell\setValueExplicit().

20  {
21  // sanitize UTF-8 strings
22  if (is_string($value)) {
23  $value = StringHelper::sanitizeUTF8($value);
24  } elseif (is_object($value)) {
25  // Handle any objects that might be injected
26  if ($value instanceof DateTimeInterface) {
27  $value = $value->format('Y-m-d H:i:s');
28  } elseif (!($value instanceof RichText)) {
29  $value = (string) $value;
30  }
31  }
32 
33  // Set value explicit
34  $cell->setValueExplicit($value, static::dataTypeForValue($value));
35 
36  // Done!
37  return true;
38  }
static sanitizeUTF8($value)
Try to sanitize UTF8, stripping invalid byte sequences.
+ Here is the call graph for this function:

◆ dataTypeForValue()

static PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder::dataTypeForValue (   $value)
static

DataType for value.

Parameters
mixed$value
Returns
string

Definition at line 47 of file DefaultValueBinder.php.

References PhpOffice\PhpSpreadsheet\Cell\DataType\getErrorCodes(), PhpOffice\PhpSpreadsheet\Cell\DataType\TYPE_BOOL, PhpOffice\PhpSpreadsheet\Cell\DataType\TYPE_ERROR, PhpOffice\PhpSpreadsheet\Cell\DataType\TYPE_FORMULA, PhpOffice\PhpSpreadsheet\Cell\DataType\TYPE_INLINE, PhpOffice\PhpSpreadsheet\Cell\DataType\TYPE_NULL, PhpOffice\PhpSpreadsheet\Cell\DataType\TYPE_NUMERIC, and PhpOffice\PhpSpreadsheet\Cell\DataType\TYPE_STRING.

48  {
49  // Match the value against a few data types
50  if ($value === null) {
51  return DataType::TYPE_NULL;
52  } elseif (is_float($value) || is_int($value)) {
54  } elseif (is_bool($value)) {
55  return DataType::TYPE_BOOL;
56  } elseif ($value === '') {
57  return DataType::TYPE_STRING;
58  } elseif ($value instanceof RichText) {
59  return DataType::TYPE_INLINE;
60  } elseif (is_string($value) && $value[0] === '=' && strlen($value) > 1) {
62  } elseif (preg_match('/^[\+\-]?(\d+\\.?\d*|\d*\\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $value)) {
63  $tValue = ltrim($value, '+-');
64  if (is_string($value) && $tValue[0] === '0' && strlen($tValue) > 1 && $tValue[1] !== '.') {
65  return DataType::TYPE_STRING;
66  } elseif ((strpos($value, '.') === false) && ($value > PHP_INT_MAX)) {
67  return DataType::TYPE_STRING;
68  } elseif (!is_numeric($value)) {
69  return DataType::TYPE_STRING;
70  }
71 
73  } elseif (is_string($value)) {
74  $errorCodes = DataType::getErrorCodes();
75  if (isset($errorCodes[$value])) {
76  return DataType::TYPE_ERROR;
77  }
78  }
79 
80  return DataType::TYPE_STRING;
81  }
static static getErrorCodes()
Get list of error codes.
Definition: DataType.php:40
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: