‪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, private readonly SetRegistry $setRegistry,)
 
 getTreeBySysTemplateRowsAndSite (string $type, array $sysTemplateRows, TokenizerInterface $tokenizer, ?SiteInterface $site=null, PhpFrontend $cache=null)
 

Private Member Functions

 createSiteTemplateInclude (Site $site, string $cacheIdentifier)
 
 handleSetInclude (IncludeInterface $parentNode, string $path, string $label)
 
 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)
 
 addScopedStaticsFromGlobals (IncludeInterface $parentNode, string $identifier)
 
 addContentRenderingFromGlobals (IncludeInterface $parentNode, string $name)
 
 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
 
bool $enableStaticMagicIncludes = false
 

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 TreeFromLineStreamBuilder 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 73 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,
private readonly SetRegistry  $setRegistry 
)

Definition at line 91 of file SysTemplateTreeBuilder.php.

Member Function Documentation

◆ addContentRenderingFromGlobals()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::addContentRenderingFromGlobals ( IncludeInterface  $parentNode,
string  $name 
)
private

◆ addDefaultTypoScriptConstantsFromSite()

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

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

Definition at line 514 of file SysTemplateTreeBuilder.php.

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

◆ addDefaultTypoScriptFromGlobals()

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

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 490 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)
private

◆ addScopedStaticsFromGlobals()

TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::addScopedStaticsFromGlobals ( IncludeInterface  $parentNode,
string  $identifier 
)
private

◆ addStaticMagicFromGlobals()

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

◆ createSiteTemplateInclude()

◆ getBasedOnSysTemplateRowsFromDatabase()

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

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 587 of file SysTemplateTreeBuilder.php.

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

◆ getSysTemplateQueryRestrictionContainer()

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

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

Definition at line 648 of file SysTemplateTreeBuilder.php.

◆ getSysTemplateRowIdentifier()

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

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 619 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 
)
private

◆ handleIncludeStaticFileArray()

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

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 316 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(), TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\prepareNodeForCache(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

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

◆ handleSetInclude()

◆ handleSingleIncludeStaticFile()

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

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 389 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(), TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

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

◆ handleSysTemplateRecordInclude()

◆ prepareNodeForCache()

Member Data Documentation

◆ $cache

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

◆ $enableStaticMagicIncludes

bool TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::$enableStaticMagicIncludes = false
private

Definition at line 89 of file SysTemplateTreeBuilder.php.

◆ $includedSysTemplateUids

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

Definition at line 81 of file SysTemplateTreeBuilder.php.

◆ $tokenizer

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

◆ $type