Skip to content

Commit 115cd91

Browse files
committed
use date time interface
1 parent 8ce0a3a commit 115cd91

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/Entity/Session.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace Shapecode\Bundle\Doctrine\SessionHandlerBundle\Entity;
66

7-
use DateTime;
7+
use Carbon\Carbon;
8+
use DateTimeInterface;
89
use Doctrine\ORM\Mapping as ORM;
910

1011
use function is_resource;
@@ -31,16 +32,16 @@ class Session
3132
private $sessionData;
3233

3334
/** @ORM\Column(type="datetime") */
34-
private DateTime $createdAt;
35+
private DateTimeInterface $createdAt;
3536

3637
/** @ORM\Column(type="datetime") */
37-
private DateTime $updatedAt;
38+
private DateTimeInterface $updatedAt;
3839

3940
public function __construct(string $sessionId)
4041
{
4142
$this->sessionId = $sessionId;
42-
$this->createdAt = new DateTime();
43-
$this->updatedAt = new DateTime();
43+
$this->createdAt = Carbon::now();
44+
$this->updatedAt = Carbon::now();
4445
}
4546

4647
public function getSessionId(): string
@@ -68,17 +69,17 @@ public function setSessionData(?string $sessionData): void
6869
$this->sessionData = $sessionData;
6970
}
7071

71-
public function getCreatedAt(): DateTime
72+
public function getCreatedAt(): DateTimeInterface
7273
{
7374
return $this->createdAt;
7475
}
7576

76-
public function getUpdatedAt(): DateTime
77+
public function getUpdatedAt(): DateTimeInterface
7778
{
7879
return $this->updatedAt;
7980
}
8081

81-
public function setUpdatedAt(DateTime $updatedAt): void
82+
public function setUpdatedAt(DateTimeInterface $updatedAt): void
8283
{
8384
$this->updatedAt = $updatedAt;
8485
}

src/Session/Handler/DoctrineHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Shapecode\Bundle\Doctrine\SessionHandlerBundle\Session\Handler;
66

7-
use DateTime;
7+
use Carbon\Carbon;
88
use Doctrine\ORM\EntityManagerInterface;
99
use SessionHandlerInterface;
1010
use Shapecode\Bundle\Doctrine\SessionHandlerBundle\Entity\Session;
@@ -70,7 +70,7 @@ public function write($sessionId, $sessionData): bool
7070
$session = $this->getSession($sessionId);
7171

7272
$session->setSessionData($sessionData);
73-
$session->setUpdatedAt(new DateTime());
73+
$session->setUpdatedAt(Carbon::now());
7474

7575
$this->entityManager->persist($session);
7676
$this->entityManager->flush($session);

0 commit comments

Comments
 (0)