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