‪TYPO3CMS  ‪main
Report.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\Uid\UuidV4;
22 
26 class ‪Report implements \JsonSerializable
27 {
28  public readonly UuidV4 ‪$uuid;
29  public readonly \DateTimeImmutable ‪$created;
30  public readonly \DateTimeImmutable ‪$changed;
31 
32  public static function ‪fromArray(array $array): static
33  {
34  $meta = json_decode($array['meta'] ?? '', true, 16, JSON_THROW_ON_ERROR);
35  ‪$details = json_decode($array['details'] ?? '', true, 16, JSON_THROW_ON_ERROR);
36  return new static(
37  ‪Scope::from($array['scope'] ?? ''),
38  ReportStatus::from($array['status'] ?? 0),
39  $array['request_time'] ?? 0,
40  $meta ?: [],
41  new ‪ReportDetails(‪$details ?: []),
42  $array['summary'] ?? '',
43  UuidV4::fromString($array['uuid'] ?? ''),
44  new \DateTimeImmutable('@' . ($array['created'] ?? '0')),
45  new \DateTimeImmutable('@' . ($array['changed'] ?? '0'))
46  );
47  }
48 
49  final public function ‪__construct(
50  public readonly ‪Scope $scope,
51  public readonly ‪ReportStatus $status,
52  public readonly int $requestTime,
53  public readonly array $meta,
54  public readonly ‪ReportDetails ‪$details,
55  public readonly string $summary = '',
56  UuidV4 ‪$uuid = null,
57  \DateTimeImmutable ‪$created = null,
58  \DateTimeImmutable ‪$changed = null,
59  ) {
60  $this->uuid = ‪$uuid ?? new UuidV4();
61  $this->created = ‪$created ?? new \DateTimeImmutable();
62  $this->changed = ‪$changed ?? ‪$this->created;
63  }
64 
65  public function ‪jsonSerialize(): array
66  {
67  return [
68  'uuid' => ‪$this->uuid,
69  'status' => $this->status->value,
70  'created' => $this->created->format(\DateTimeInterface::ATOM),
71  'changed' => $this->changed->format(\DateTimeInterface::ATOM),
72  'scope' => $this->scope,
73  'request_time' => $this->requestTime,
74  'meta' => $this->meta,
75  'details' => ‪$this->details,
76  'summary' => $this->summary,
77  ];
78  }
79 
80  public function ‪toArray(): array
81  {
82  return [
83  'uuid' => (string)$this->uuid,
84  'status' => $this->status->value,
85  'created' => $this->created->getTimestamp(),
86  'changed' => $this->changed->getTimestamp(),
87  'scope' => (string)$this->scope,
88  'request_time' => $this->requestTime,
89  'meta' => json_encode($this->meta),
90  'details' => json_encode($this->details->getArrayCopy()),
91  'summary' => $this->summary,
92  ];
93  }
94 }
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report\jsonSerialize
‪jsonSerialize()
Definition: Report.php:65
‪TYPO3\CMS\Webhooks\Message\$details
‪identifier readonly UriInterface readonly array $details
Definition: MfaVerificationErrorOccurredMessage.php:37
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ReportStatus
‪ReportStatus
Definition: ReportStatus.php:24
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report\$created
‪readonly DateTimeImmutable $created
Definition: Report.php:29
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report\$changed
‪readonly DateTimeImmutable $changed
Definition: Report.php:30
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Scope
Definition: Scope.php:30
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting
Definition: Report.php:18
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report\fromArray
‪static fromArray(array $array)
Definition: Report.php:32
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report\toArray
‪toArray()
Definition: Report.php:80
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ReportDetails
Definition: ReportDetails.php:24
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report\__construct
‪__construct(public readonly Scope $scope, public readonly ReportStatus $status, public readonly int $requestTime, public readonly array $meta, public readonly ReportDetails $details, public readonly string $summary='', UuidV4 $uuid=null, \DateTimeImmutable $created=null, \DateTimeImmutable $changed=null,)
Definition: Report.php:49
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report
Definition: Report.php:27
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Scope\from
‪static from(string $value)
Definition: Scope.php:69
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report\$uuid
‪readonly UuidV4 $uuid
Definition: Report.php:28