ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
DefaultValueBinder.php
Go to the documentation of this file.
1<?php
2
4
5use DateTimeInterface;
8
10{
19 public function bindValue(Cell $cell, $value)
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 }
39
47 public static function dataTypeForValue($value)
48 {
49 // Match the value against a few data types
50 if ($value === null) {
52 } elseif (is_float($value) || is_int($value)) {
54 } elseif (is_bool($value)) {
56 } elseif ($value === '') {
58 } elseif ($value instanceof RichText) {
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] !== '.') {
66 } elseif ((strpos($value, '.') === false) && ($value > PHP_INT_MAX)) {
68 } elseif (!is_numeric($value)) {
70 }
71
73 } elseif (is_string($value)) {
74 $errorCodes = DataType::getErrorCodes();
75 if (isset($errorCodes[$value])) {
77 }
78 }
79
81 }
82}
An exception for terminatinating execution or to throw for unit testing.
setValueExplicit($pValue, $pDataType)
Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the ...
Definition: Cell.php:195
static getErrorCodes()
Get list of error codes.
Definition: DataType.php:40
static dataTypeForValue($value)
DataType for value.
bindValue(Cell $cell, $value)
Bind value to a cell.
static sanitizeUTF8($value)
Try to sanitize UTF8, stripping invalid byte sequences.