mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-12 19:16:45 +00:00
Now it's Scrutinizer's turn
This commit is contained in:
@@ -71,27 +71,18 @@ class StringValueBinder implements IValueBinder
|
||||
*
|
||||
* @param Cell $cell Cell to bind value to
|
||||
* @param mixed $value Value to bind in cell
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function bindValue(Cell $cell, $value)
|
||||
{
|
||||
if (is_object($value)) {
|
||||
return $this->bindObjectValue($cell, $value);
|
||||
}
|
||||
|
||||
// sanitize UTF-8 strings
|
||||
if (is_string($value)) {
|
||||
$value = StringHelper::sanitizeUTF8($value);
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
// Handle any objects that might be injected
|
||||
if ($value instanceof DateTimeInterface) {
|
||||
$value = $value->format('Y-m-d H:i:s');
|
||||
} elseif ($value instanceof RichText) {
|
||||
$cell->setValueExplicit($value, DataType::TYPE_INLINE);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($value === null && $this->convertNull === false) {
|
||||
$cell->setValueExplicit($value, DataType::TYPE_NULL);
|
||||
} elseif (is_bool($value) && $this->convertBoolean === false) {
|
||||
@@ -109,4 +100,20 @@ class StringValueBinder implements IValueBinder
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function bindObjectValue(Cell $cell, $value): bool
|
||||
{
|
||||
// Handle any objects that might be injected
|
||||
if ($value instanceof DateTimeInterface) {
|
||||
$value = $value->format('Y-m-d H:i:s');
|
||||
} elseif ($value instanceof RichText) {
|
||||
$cell->setValueExplicit($value, DataType::TYPE_INLINE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$cell->setValueExplicit((string) $value, DataType::TYPE_STRING);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user