Skip to content

Commit e2278da

Browse files
Jan Petersenjordisala1991
authored andcommitted
Implementing type safe method call to DateTime::setTimestamp()
When loading serialized snapshot contents, this Transformer passes string values to the \DateTime::setTimestamp()" method, resulting in an uncaught FatalThrowableError: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Type error: DateTime::setTimestamp() expects parameter 1 to be integer, string given" at Transformer.php line 165 Example call (taken from my Symfony Exception page): DateTime->setTimestamp('1510846884') in vendor/sonata-project/page-bundle/src/Entity/Transformer.php (line 165)
1 parent 9ab4729 commit e2278da

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Entity/Transformer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ public function load(SnapshotInterface $snapshot)
161161
$page->setRequestMethod($content['request_method']);
162162

163163
$createdAt = new \DateTime();
164-
$createdAt->setTimestamp($content['created_at']);
164+
$createdAt->setTimestamp((int) $content['created_at']);
165165
$page->setCreatedAt($createdAt);
166166

167167
$updatedAt = new \DateTime();
168-
$updatedAt->setTimestamp($content['updated_at']);
168+
$updatedAt->setTimestamp((int) $content['updated_at']);
169169
$page->setUpdatedAt($updatedAt);
170170

171171
return $page;
@@ -189,11 +189,11 @@ public function loadBlock(array $content, PageInterface $page)
189189
$block->setType($content['type']);
190190

191191
$createdAt = new \DateTime();
192-
$createdAt->setTimestamp($content['created_at']);
192+
$createdAt->setTimestamp((int) $content['created_at']);
193193
$block->setCreatedAt($createdAt);
194194

195195
$updatedAt = new \DateTime();
196-
$updatedAt->setTimestamp($content['updated_at']);
196+
$updatedAt->setTimestamp((int) $content['updated_at']);
197197
$block->setUpdatedAt($updatedAt);
198198

199199
foreach ($content['blocks'] as $child) {

0 commit comments

Comments
 (0)