ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
DefaultValueBinder.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35  require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36 }
37 
38 
47 {
55  public function bindValue(PHPExcel_Cell $cell, $value = null)
56  {
57  // sanitize UTF-8 strings
58  if (is_string($value)) {
59  $value = PHPExcel_Shared_String::SanitizeUTF8($value);
60  } elseif (is_object($value)) {
61  // Handle any objects that might be injected
62  if ($value instanceof DateTime) {
63  $value = $value->format('Y-m-d H:i:s');
64  } elseif (!($value instanceof PHPExcel_RichText)) {
65  $value = (string) $value;
66  }
67  }
68 
69  // Set value explicit
70  $cell->setValueExplicit( $value, self::dataTypeForValue($value) );
71 
72  // Done!
73  return true;
74  }
75 
82  public static function dataTypeForValue($pValue = null) {
83  // Match the value against a few data types
84  if ($pValue === null) {
86  } elseif ($pValue === '') {
88  } elseif ($pValue instanceof PHPExcel_RichText) {
90  } elseif ($pValue{0} === '=' && strlen($pValue) > 1) {
92  } elseif (is_bool($pValue)) {
94  } elseif (is_float($pValue) || is_int($pValue)) {
96  } elseif (preg_match('/^[\+\-]?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $pValue)) {
97  $tValue = ltrim($pValue, '+-');
98  if (is_string($pValue) && $tValue{0} === '0' && strlen($tValue) > 1 && $tValue{1} !== '.' ) {
100  } elseif((strpos($pValue, '.') === false) && ($pValue > PHP_INT_MAX)) {
102  }
104  } elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) {
106  }
107 
109  }
110 }
Add rich text string
The name of the decorator.
static dataTypeForValue($pValue=null)
DataType for value.
setValueExplicit($pValue=NULL, $pDataType=PHPExcel_Cell_DataType::TYPE_STRING)
Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the ...
Definition: Cell.php:225
static getErrorCodes()
Get list of error codes.
Definition: DataType.php:68
bindValue(PHPExcel_Cell $cell, $value=null)
Bind value to a cell.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
static SanitizeUTF8($value)
Try to sanitize UTF8, stripping invalid byte sequences.
Definition: String.php:383