Skip to content

Commit 23d532e

Browse files
authored
Fix Exception thrown at ObjectSerializer::toString() (#1)
Allow Guzzle 7, prevent exception "Trying to access array offset on value of type int".
1 parent ca7c057 commit 23d532e

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"ext-curl": "*",
3030
"ext-json": "*",
3131
"ext-mbstring": "*",
32-
"guzzlehttp/guzzle": "^6.3"
32+
"guzzlehttp/guzzle": "^6.3|7.*"
3333
},
3434
"require-dev": {
3535
"friendsofphp/php-cs-fixer": "2.10.*",
@@ -44,4 +44,4 @@
4444
"classmap": [ "src/", "tests/" ],
4545
"psr-4": { "GroupDocs\\Conversion\\" : "tests/" }
4646
}
47-
}
47+
}

src/GroupDocs/Conversion/ObjectSerializer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,17 @@ public static function toFormValue($value)
169169
*/
170170
public static function toString($value)
171171
{
172-
if (date(\DATE_ATOM, preg_match("/^[1-9][0-9]*$/", $value)[0]) instanceof \DateTime) { // datetime in ISO8601 format
173-
$datetime = preg_match("/^[1-9][0-9]*$/", $value)[0];
174-
return date(\DATE_ATOM, $datetime);
175-
} else {
172+
preg_match("/^[1-9][0-9]*$/", $value, $matches);
173+
174+
if (empty($matches)) {
176175
return $value;
177176
}
177+
178+
if (date(\DATE_ATOM, $matches[0]) instanceof \DateTime) { // datetime in ISO8601 format
179+
return date(\DATE_ATOM, $matches[0]);
180+
}
181+
182+
return $value;
178183
}
179184

180185
/*

0 commit comments

Comments
 (0)