‪TYPO3CMS  ‪main
Resolution.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 
24 
28 class ‪Resolution implements \JsonSerializable
29 {
30  public readonly \DateTimeImmutable ‪$created;
31 
32  public static function ‪fromArray(array $array): static
33  {
34  if (!isset($array['summary'])) {
35  throw new \LogicException('Summary must be given', 1677263951);
36  }
37  $service = GeneralUtility::makeInstance(ModelService::class);
38  $mutationCollection = $array['mutation_collection'] ?? null;
39  if (is_string($mutationCollection)) {
40  $mutationCollection = json_decode($mutationCollection, true, 16, JSON_THROW_ON_ERROR);
41  }
42  $mutationCollection = $service->buildMutationCollectionFromArray(
43  is_array($mutationCollection) ? $mutationCollection : []
44  );
45  $meta = json_decode($array['meta'] ?? '', true, 16, JSON_THROW_ON_ERROR);
46  return new static(
47  $array['summary'],
48  ‪Scope::from($array['scope'] ?? ''),
49  $array['mutation_identifier'],
50  $mutationCollection,
51  $meta ?: [],
52  (new \DateTimeImmutable())->setTimestamp((int)($array['created'] ?? 0)),
53  );
54  }
55 
56  final public function ‪__construct(
57  public readonly string $summary,
58  public readonly ‪Scope $scope,
59  public readonly string $mutationIdentifier,
60  public readonly ‪MutationCollection $mutationCollection,
61  public readonly array $meta = [],
62  \DateTimeImmutable ‪$created = null,
63  ) {
64  $this->created = ‪$created ?? new \DateTimeImmutable();
65  }
66 
67  public function ‪jsonSerialize(): array
68  {
69  return [
70  'summary' => $this->summary,
71  'created' => $this->created->format(\DateTimeInterface::ATOM),
72  'scope' => $this->scope,
73  'mutationIdentifier' => $this->mutationIdentifier,
74  'mutationCollection' => $this->mutationCollection,
75  'meta' => $this->meta,
76  ];
77  }
78 
79  public function ‪toArray(): array
80  {
81  return [
82  'summary' => $this->summary,
83  'created' => $this->created->getTimestamp(),
84  'scope' => (string)$this->scope,
85  'mutation_identifier' => $this->mutationIdentifier,
86  'mutation_collection' => json_encode($this->mutationCollection),
87  'meta' => json_encode($this->meta),
88  ];
89  }
90 }
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Resolution\$created
‪readonly DateTimeImmutable $created
Definition: Resolution.php:30
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\ModelService
Definition: ModelService.php:28
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Resolution\toArray
‪toArray()
Definition: Resolution.php:79
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Scope
Definition: Scope.php:30
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Resolution\jsonSerialize
‪jsonSerialize()
Definition: Resolution.php:67
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting
Definition: Report.php:18
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Resolution
Definition: Resolution.php:29
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Resolution\fromArray
‪static fromArray(array $array)
Definition: Resolution.php:32
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationCollection
Definition: MutationCollection.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Scope\from
‪static from(string $value)
Definition: Scope.php:69
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Resolution\__construct
‪__construct(public readonly string $summary, public readonly Scope $scope, public readonly string $mutationIdentifier, public readonly MutationCollection $mutationCollection, public readonly array $meta=[], \DateTimeImmutable $created=null,)
Definition: Resolution.php:56