‪TYPO3CMS  ‪main
StringFragment.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 
23 class ‪StringFragment implements \Stringable
24 {
25  public readonly int ‪$length;
26  public readonly string ‪$ident;
27 
28  public static function ‪raw(string $value): self
29  {
30  return new self($value, ‪StringFragmentSplitter::TYPE_RAW);
31  }
32 
33  public static function ‪expression(string $value): self
34  {
35  return new self($value, ‪StringFragmentSplitter::TYPE_EXPRESSION);
36  }
37 
38  public function ‪__construct(
39  public readonly string $value,
40  public readonly string $type
41  ) {
42  if ($this->value === '') {
43  throw new \LogicException('Value must not be empty', 1651671582);
44  }
45  $this->‪length = strlen($this->value);
46  $this->ident = md5($this->type . '::' . ($this->value));
47  }
48 
49  public function ‪__toString(): string
50  {
51  return $this->value;
52  }
53 }
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\length
‪@ length
Definition: HashType.php:33
‪TYPO3\CMS\Core\Utility\String\StringFragmentSplitter\TYPE_RAW
‪const TYPE_RAW
Definition: StringFragmentSplitter.php:31
‪TYPO3\CMS\Core\Utility\String\StringFragment\__construct
‪__construct(public readonly string $value, public readonly string $type)
Definition: StringFragment.php:38
‪TYPO3\CMS\Core\Utility\String\StringFragment\expression
‪static expression(string $value)
Definition: StringFragment.php:33
‪TYPO3\CMS\Core\Utility\String\StringFragment\$length
‪readonly int $length
Definition: StringFragment.php:25
‪TYPO3\CMS\Core\Utility\String\StringFragment\raw
‪static raw(string $value)
Definition: StringFragment.php:28
‪TYPO3\CMS\Core\Utility\String
Definition: StringFragment.php:18
‪TYPO3\CMS\Core\Utility\String\StringFragment\$ident
‪readonly string $ident
Definition: StringFragment.php:26
‪TYPO3\CMS\Core\Utility\String\StringFragmentSplitter\TYPE_EXPRESSION
‪const TYPE_EXPRESSION
Definition: StringFragmentSplitter.php:36
‪TYPO3\CMS\Core\Utility\String\StringFragment
Definition: StringFragment.php:24
‪TYPO3\CMS\Core\Utility\String\StringFragment\__toString
‪__toString()
Definition: StringFragment.php:49