‪TYPO3CMS  ‪main
StringTreeBuilder.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\DependencyInjection\Attribute\Autoconfigure;
25 
36 #[Autoconfigure(public: true)]
38 {
39  public function ‪__construct(
40  private readonly ‪TreeFromLineStreamBuilder $treeFromTokenStreamBuilder,
41  ) {}
42 
48  public function ‪getTreeFromString(
49  string ‪$name,
50  string $typoScriptString,
51  ‪TokenizerInterface $tokenizer,
52  ?‪PhpFrontend $cache = null,
53  ): ‪RootInclude {
54  $lowerCaseName = mb_strtolower(‪$name);
55  ‪$identifier = 'string-' . $lowerCaseName . '-' . hash('xxh3', $typoScriptString);
56  if ($cache) {
57  $includeTree = $cache->require(‪$identifier);
58  if ($includeTree instanceof ‪RootInclude) {
59  return $includeTree;
60  }
61  }
62  $includeTree = new ‪RootInclude();
63  $includeNode = new ‪StringInclude();
64  $includeNode->setName('[string] ' . ‪$name);
65  $includeNode->setLineStream($tokenizer->‪tokenize($typoScriptString));
66  $this->treeFromTokenStreamBuilder->buildTree($includeNode, 'other', $tokenizer);
67  $includeTree->addChild($includeNode);
68  $cache?->set(‪$identifier, $this->‪prepareTreeForCache($includeTree));
69  return $includeTree;
70  }
71 
72  private function ‪prepareTreeForCache(‪RootInclude $node): string
73  {
74  return 'return unserialize(\'' . addcslashes(serialize($node), '\'\\') . '\');';
75  }
76 }
‪TYPO3\CMS\Core\TypoScript\IncludeTree\StringTreeBuilder\__construct
‪__construct(private readonly TreeFromLineStreamBuilder $treeFromTokenStreamBuilder,)
Definition: StringTreeBuilder.php:39
‪TYPO3\CMS\Core\TypoScript\IncludeTree
‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend
Definition: PhpFrontend.php:25
‪TYPO3\CMS\Core\TypoScript\IncludeTree\TreeFromLineStreamBuilder
Definition: TreeFromLineStreamBuilder.php:59
‪TYPO3\CMS\Core\TypoScript\IncludeTree\StringTreeBuilder
Definition: StringTreeBuilder.php:38
‪$name
‪$name
Definition: phpIntegrityChecker.php:235
‪TYPO3\CMS\Core\TypoScript\IncludeTree\StringTreeBuilder\prepareTreeForCache
‪prepareTreeForCache(RootInclude $node)
Definition: StringTreeBuilder.php:72
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\StringInclude
Definition: StringInclude.php:26
‪TYPO3\CMS\Core\TypoScript\IncludeTree\StringTreeBuilder\getTreeFromString
‪getTreeFromString(string $name, string $typoScriptString, TokenizerInterface $tokenizer, ?PhpFrontend $cache=null,)
Definition: StringTreeBuilder.php:48
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\RootInclude
Definition: RootInclude.php:27
‪TYPO3\CMS\Core\TypoScript\Tokenizer\TokenizerInterface
Definition: TokenizerInterface.php:40
‪TYPO3\CMS\Core\TypoScript\Tokenizer\TokenizerInterface\tokenize
‪tokenize(string $source)
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37