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