‪TYPO3CMS  ‪main
MutationSuggestion.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 
22 
28 final class ‪MutationSuggestion implements \JsonSerializable
29 {
35  public function ‪__construct(
36  public readonly ‪MutationCollection $collection,
37  public readonly string ‪$identifier,
38  public readonly ?int $priority = null,
39  public readonly ?string $label = null,
40  ) {
41  if ($this->priority !== null && ($this->priority < 0 || $this->priority > 10)) {
42  throw new \LogicException('Priority must be in range [0; 10]', 1679601774);
43  }
44  if ($this->identifier === '') {
45  throw new \LogicException('Identifer cannot be empty', 1679601795);
46  }
47  }
48 
49  public function ‪hash(): string
50  {
51  return sha1(json_encode($this->‪getHashProperties()));
52  }
53 
54  public function ‪hmac(): string
55  {
56  $hashService = GeneralUtility::makeInstance(HashService::class);
57  return $hashService->hmac(json_encode($this->‪getHashProperties()), self::class);
58  }
59 
60  public function ‪jsonSerialize(): array
61  {
62  $properties = [
63  'collection' => $this->collection,
64  'identifier' => ‪$this->identifier,
65  'priority' => $this->priority,
66  'label' => $this->label,
67  ];
68  $hashService = GeneralUtility::makeInstance(HashService::class);
69  $hashContent = json_encode($this->‪getHashProperties());
70  $properties['hash'] = sha1($hashContent);
71  $properties['hmac'] = $hashService->hmac($hashContent, self::class);
72  return $properties;
73  }
74 
75  private function ‪getHashProperties(): array
76  {
77  return [
78  'collection' => $this->collection,
79  'identifier' => ‪$this->identifier,
80  ];
81  }
82 }
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationSuggestion\hash
‪hash()
Definition: MutationSuggestion.php:49
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationSuggestion\getHashProperties
‪getHashProperties()
Definition: MutationSuggestion.php:75
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationSuggestion\jsonSerialize
‪jsonSerialize()
Definition: MutationSuggestion.php:60
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationSuggestion\__construct
‪__construct(public readonly MutationCollection $collection, public readonly string $identifier, public readonly ?int $priority=null, public readonly ?string $label=null,)
Definition: MutationSuggestion.php:35
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationSuggestion\hmac
‪hmac()
Definition: MutationSuggestion.php:54
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationSuggestion
Definition: MutationSuggestion.php:29
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy
Definition: ConsumableNonce.php:18
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationCollection
Definition: MutationCollection.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Crypto\HashService
Definition: HashService.php:27
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37