‪TYPO3CMS  ‪main
TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder Class Reference

Public Member Functions

 __construct (private readonly ConnectionPool $connectionPool, private readonly PackageManager $packageManager, private readonly Context $context, private readonly TreeFromLineStreamBuilder $treeFromTokenStreamBuilder,)
 getTreeBySysTemplateRowsAndSite (string $type, array $sysTemplateRows, TokenizerInterface $tokenizer, ?SiteInterface $site=null, PhpFrontend $cache=null)

Private Member Functions

 handleSysTemplateRecordInclude (IncludeInterface $parentNode, array $row, ?SiteInterface $site)
 handleIncludeStaticFileArray (IncludeInterface $parentNode, string $includeStaticFileString)
 handleIncludeBasedOnTemplates (IncludeInterface $parentNode, string $basedOnList, ?SiteInterface $site)
 handleSingleIncludeStaticFile (IncludeInterface $parentNode, $includeStaticFileString)
 addExtensionStatics (IncludeInterface $parentNode)
 addDefaultTypoScriptFromGlobals (IncludeInterface $parentConstantNode)
 addDefaultTypoScriptConstantsFromSite (IncludeInterface $parentConstantNode, ?SiteInterface $site)
 addStaticMagicFromGlobals (IncludeInterface $parentNode, string $identifier)
 getBasedOnSysTemplateRowsFromDatabase (array $basedOnTemplateUids)
 getSysTemplateRowIdentifier (array $sysTemplateRow, ?SiteInterface $site)
 prepareNodeForCache (IncludeInterface $node)
 getSysTemplateQueryRestrictionContainer ()

Private Attributes

array $includedSysTemplateUids = []
string $type
TokenizerInterface $tokenizer
PhpFrontend $cache = null

Detailed Description

Create a tree representing all TypoScript includes.

This is the 'middle' part of the TypoScript parsing process: The tokenizers as "lowest" structure create line streams from TypoScript, the AST builder as "highest" structure create the TypoScript object tree.

This structure gathers all TypoScript snippets that have to be tokenized, and creates a tree with include nodes and sub include nodes.

It is called in frontend (and backend "Template" module) with the page rootline, gets all attached sys_template records, gets their content and various sub includes and takes care of correct include order.

This class together with TreeFromTokenLineStreamBuilder also takes care of conditions and imports ("@import" and "<INCLUDE_TYPOSCRIPT:"): Those create child nodes in the tree. To evaluate conditions, the tree is later traversed, condition verdicts (true / false) are determined, to see if condition's child nodes should be considered in AST.

The IncludeTree is "runtime stateless": Constants values and conditions are not evaluated here, so the tree is always the same for a given rootline. This makes this structure cache-able: In frontend, the tree (or sub parts of it) is cached and fetched from cache for next call. This means the entire tree-building and tokenizing is suppressed. After that runtime information is added: Conditions are evaluated, and the AST is built from given IncludeTree.

: Internal tree structure.

Definition at line 71 of file SysTemplateTreeBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::__construct ( private readonly ConnectionPool  $connectionPool,
private readonly PackageManager  $packageManager,
private readonly Context  $context,
private readonly TreeFromLineStreamBuilder  $treeFromTokenStreamBuilder 

Definition at line 87 of file SysTemplateTreeBuilder.php.

Member Function Documentation

◆ addDefaultTypoScriptConstantsFromSite()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::addDefaultTypoScriptConstantsFromSite ( IncludeInterface  $parentConstantNode,
?SiteInterface  $site 

Load default TS constants from site configuration if that page has a site in rootline.

Definition at line 417 of file SysTemplateTreeBuilder.php.

Referenced by TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\handleSysTemplateRecordInclude().

◆ addDefaultTypoScriptFromGlobals()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::addDefaultTypoScriptFromGlobals ( IncludeInterface  $parentConstantNode)

Load default constants TS from $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_[constants|setup]'] whenever 'root=1' is set for a sys_template.

Definition at line 393 of file SysTemplateTreeBuilder.php.

References $GLOBALS, TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\$type, and TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\addChild().

Referenced by TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\handleSysTemplateRecordInclude().

◆ addExtensionStatics()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::addExtensionStatics ( IncludeInterface  $parentNode)

◆ addStaticMagicFromGlobals()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::addStaticMagicFromGlobals ( IncludeInterface  $parentNode,
string  $identifier 

◆ getBasedOnSysTemplateRowsFromDatabase()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::getBasedOnSysTemplateRowsFromDatabase ( array  $basedOnTemplateUids)

Get 'basedOn' sys_template sub-rows of sys_templates that use this. Note the 'IN()' query implementation below delivers rows in any order. To preserve basedOn list order, we re-index result rows by uid and then iterate on the original order of $basedOnTemplateUids in handleIncludeBasedOnTemplates().

Definition at line 480 of file SysTemplateTreeBuilder.php.

Referenced by TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\handleIncludeBasedOnTemplates().

◆ getSysTemplateQueryRestrictionContainer()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::getSysTemplateQueryRestrictionContainer ( )

Get sys_template record query builder restrictions. Allows hidden records if enabled in context.

Definition at line 541 of file SysTemplateTreeBuilder.php.

◆ getSysTemplateRowIdentifier()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::getSysTemplateRowIdentifier ( array  $sysTemplateRow,
?SiteInterface  $site 

Calculate a cache identifier for a sys_template row. This is a bit nifty: There are instances in the wild that add the same TypoScript sys_template over and over again in a page tree to for instance toggle a single value. Those content-identical template rows create only one cache entry: We create a hash from the relevant row fields like 'constants' and 'config', but we do NOT include the sys_template row 'uid' and 'pid'. So different sys_template rows with the same content lead to the same identifier, and we cache that just once.

One additional dependency influences the identifier as well: If the 'clear constants' flag is set, this row will later trigger loading of constants from given site settings. When two "first" template rows have the exact same field content in different sites, the site identifier needs to be added to the hash to still create two different cache entries.

Definition at line 512 of file SysTemplateTreeBuilder.php.

Referenced by TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\getTreeBySysTemplateRowsAndSite().

◆ getTreeBySysTemplateRowsAndSite()

◆ handleIncludeBasedOnTemplates()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::handleIncludeBasedOnTemplates ( IncludeInterface  $parentNode,
string  $basedOnList,
?SiteInterface  $site 

◆ handleIncludeStaticFileArray()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::handleIncludeStaticFileArray ( IncludeInterface  $parentNode,
string  $includeStaticFileString 

Handle includes defined in a sys_template['include_static_file'] row. Extracted as methods since it depends on 'includeStaticAfterBasedOn' field if this is included before or after other 'basedOn' includes.

The cache implemented here does not take the content of files into account. This means changing a file does not automatically void the cache since that would lead to lots of file_exists() and file_get_contents() calls in production. Instances in development context should thus set the typoscript-cache to NullFrontend. Note this cache-usage is the main-cache that kicks in whenever different sys_template records include the same file. For instance, when multiple sites include ext:seo XmlSitemap, the cache implementation here takes care the ext:seo subtree is calculated only once.

Definition at line 221 of file SysTemplateTreeBuilder.php.

References TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\$type, TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\addChild(), TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\handleSingleIncludeStaticFile(), and TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\prepareNodeForCache().

Referenced by TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\handleSysTemplateRecordInclude().

◆ handleSingleIncludeStaticFile()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::handleSingleIncludeStaticFile ( IncludeInterface  $parentNode,

Handle a single sys_template ['include_static_file'] include. Looks up file "EXT:/My/Path/include_static_file.txt' in an extension and includes this. Also loads "EXT:/My/Path/[constants|setup].[typoscript|ts|txt]. Warning: Recursive since an include_static_file.txt file can include other extension's include_static_file.txt again. This method has no cache-layer usage on its own: handleSingleIncludeStaticFile() which calls this method is the cache layer here.

Definition at line 294 of file SysTemplateTreeBuilder.php.

References TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\addChild(), TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\addStaticMagicFromGlobals(), TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath(), TYPO3\CMS\Core\Utility\PathUtility\isExtensionPath(), and TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded().

Referenced by TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\handleIncludeStaticFileArray().

◆ handleSysTemplateRecordInclude()

◆ prepareNodeForCache()

Member Data Documentation

◆ $cache

PhpFrontend TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::$cache = null

◆ $includedSysTemplateUids

array TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::$includedSysTemplateUids = []

Definition at line 79 of file SysTemplateTreeBuilder.php.

◆ $tokenizer

TokenizerInterface TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::$tokenizer

◆ $type