forked from Respect/Stringifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTimeStringifier.php
More file actions
36 lines (28 loc) · 832 Bytes
/
DateTimeStringifier.php
File metadata and controls
36 lines (28 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/*
* This file is part of Respect/Stringifier.
* Copyright (c) Henrique Moody <henriquemoody@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Stringifier\Stringifiers;
use DateTimeInterface;
use Respect\Stringifier\Helpers\ObjectHelper;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;
final class DateTimeStringifier implements Stringifier
{
use ObjectHelper;
public function __construct(
private readonly Quoter $quoter,
private readonly string $format,
) {
}
public function stringify(mixed $raw, int $depth): string|null
{
if (!$raw instanceof DateTimeInterface) {
return null;
}
return $this->quoter->quote($this->format($raw, $raw->format($this->format)), $depth);
}
}