TypoScriptParser
The TypoScript parser.
This class should not be used anymore. Switch to the new parser construct instead.
Table of Contents
Properties
- $errors : array<string|int, mixed>
- Error accumulation array.
- $lineNumberOffset : int
- Used for the error messages line number reporting. Set externally.
- $regComments : bool
- DO NOT register the comments. This is default for the ordinary sitetemplate!
- $regLinenumbers : bool
- DO NOT register the linenumbers. This is default for the ordinary sitetemplate!
- $sections : array<string|int, mixed>
- Tracking all conditions found
- $sectionsMatch : array<string|int, mixed>
- Tracking all matching conditions found
- $setup : array<string|int, mixed>
- TypoScript hierarchy being build during parsing.
- $commentSet : bool
- Internally set, used as internal flag to create a multi-line comment (one of those like /* ... * /
- $inBrace : int
- Internally set, when in brace. Counter.
- $lastComment : string
- Holding the value of the last comment
- $lastConditionTrue : bool
- For each condition this flag is set, if the condition is TRUE, else it's cleared. Then it's used by the [ELSE] condition to determine if the next part should be parsed.
- $multiLineEnabled : bool
- Internally set, when multiline value is accumulated
- $multiLineObject : string
- Internally set, when multiline value is accumulated
- $multiLineValue : array<string|int, mixed>
- Internally set, when multiline value is accumulated
- $raw : array<string|int, string>
- Raw data, the input string exploded by LF
- $rawP : int
- Pointer to entry in raw data array
Methods
- __construct() : mixed
- checkIncludeLines() : string|array<string|int, mixed>
- Checks the input string (un-parsed TypoScript) for include-commands ("<INCLUDE_TYPOSCRIPT: ....") Use: \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines()
- checkIncludeLines_array() : array<string|int, mixed>
- Parses the string in each value of the input array for include-commands
- extractIncludes() : string
- Search for commented INCLUDE_TYPOSCRIPT statements and save the content between the BEGIN and the END line to the specified file
- extractIncludes_array() : array<string|int, mixed>
- Processes the string in each value of the input array with extractIncludes
- getVal() : array<string|int, mixed>
- Get a value/property pair for an object path in TypoScript, eg. "myobject.myvalue.mysubproperty".
- includeFile() : mixed
- Include file $filename. Contents of the file will be prepended to &$newstring, filename to &$includedFiles Further include_typoscript tags in the contents are processed recursively
- parse() : mixed
- Start parsing the input TypoScript text piece. The result is stored in $this->setup
- addImportsFromExternalFiles() : string
- Splits the unparsed TypoScript content into import statements
- error() : mixed
- Stacks errors/messages from the TypoScript parser into an internal array, $this->error If "TT" is a global object (as it is in the frontend when backend users are logged in) the message will be registered here as well.
- executeValueModifier() : string|null
- Executes operator functions, called from TypoScript example: page.10.value := appendString(!)
- getLogger() : LoggerInterface
- Get a logger instance
- getTimeTracker() : TimeTracker
- importExternalTypoScriptFile() : string
- Include file $filename. Contents of the file will be returned, filename is added to &$includedFiles.
- includeDirectory() : mixed
- Include all files with matching Typoscript extensions in directory $dirPath. Contents of the files are prepended to &$newstring, filename to &$includedFiles.
- nextDivider() : string
- Will search for the next condition. When found it will return the line content (the condition value) and have advanced the internal $this->rawP pointer to point to the next line after the condition.
- parseNextKeySegment() : array<string|int, mixed>
- Determines the first key segment of a TypoScript key by searching for the first unescaped dot in the given key string.
- parseSub() : string
- Parsing the $this->raw TypoScript lines from pointer, $this->rawP
- rollParseSub() : string
- Parsing of TypoScript keys inside a curly brace where the key is composite of at least two keys, thus having to recursively call itself to get the value
- setVal() : mixed
- Setting a value/property of an object string in the setup array.
- typoscriptIncludeError() : string
- Process errors in INCLUDE_TYPOSCRIPT tags Errors are logged and printed in the concatenated TypoScript result (as can be seen in Template Analyzer)
Properties
$errors
Error accumulation array.
public
array<string|int, mixed>
$errors
= []
$lineNumberOffset
Used for the error messages line number reporting. Set externally.
public
int
$lineNumberOffset
= 0
$regComments
DO NOT register the comments. This is default for the ordinary sitetemplate!
public
bool
$regComments
= false
$regLinenumbers
DO NOT register the linenumbers. This is default for the ordinary sitetemplate!
public
bool
$regLinenumbers
= false
$sections
Tracking all conditions found
public
array<string|int, mixed>
$sections
= []
$sectionsMatch
Tracking all matching conditions found
public
array<string|int, mixed>
$sectionsMatch
= []
$setup
TypoScript hierarchy being build during parsing.
public
array<string|int, mixed>
$setup
= []
$commentSet
Internally set, used as internal flag to create a multi-line comment (one of those like /* ... * /
protected
bool
$commentSet
= false
$inBrace
Internally set, when in brace. Counter.
protected
int
$inBrace
= 0
$lastComment
Holding the value of the last comment
protected
string
$lastComment
= ''
$lastConditionTrue
For each condition this flag is set, if the condition is TRUE, else it's cleared. Then it's used by the [ELSE] condition to determine if the next part should be parsed.
protected
bool
$lastConditionTrue
= true
$multiLineEnabled
Internally set, when multiline value is accumulated
protected
bool
$multiLineEnabled
= false
$multiLineObject
Internally set, when multiline value is accumulated
protected
string
$multiLineObject
= ''
$multiLineValue
Internally set, when multiline value is accumulated
protected
array<string|int, mixed>
$multiLineValue
= []
$raw
Raw data, the input string exploded by LF
protected
array<string|int, string>
$raw
$rawP
Pointer to entry in raw data array
protected
int
$rawP
Methods
__construct()
public
__construct() : mixed
checkIncludeLines()
Checks the input string (un-parsed TypoScript) for include-commands ("<INCLUDE_TYPOSCRIPT: ....") Use: \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines()
public
static checkIncludeLines(string $string[, int $cycle_counter = 1 ][, bool $returnFiles = false ][, string $parentFilenameOrPath = '' ]) : string|array<string|int, mixed>
Parameters
- $string : string
-
Unparsed TypoScript
- $cycle_counter : int = 1
-
Counter for detecting endless loops
- $returnFiles : bool = false
-
When set an array containing the resulting typoscript and all included files will get returned
- $parentFilenameOrPath : string = ''
-
The parent file (with absolute path) or path for relative includes
Tags
Return values
string|array<string|int, mixed> —Complete TypoScript with includes added.
checkIncludeLines_array()
Parses the string in each value of the input array for include-commands
public
static checkIncludeLines_array(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
-
Array with TypoScript in each value
Return values
array<string|int, mixed> —Same array but where the values has been parsed for include-commands
extractIncludes()
Search for commented INCLUDE_TYPOSCRIPT statements and save the content between the BEGIN and the END line to the specified file
public
static extractIncludes(string $string[, int $cycle_counter = 1 ][, array<string|int, mixed> $extractedFileNames = [] ][, string $parentFilenameOrPath = '' ]) : string
Parameters
- $string : string
-
Template content
- $cycle_counter : int = 1
-
Counter for detecting endless loops
- $extractedFileNames : array<string|int, mixed> = []
- $parentFilenameOrPath : string = ''
Tags
Return values
string —Template content with uncommented include statements
extractIncludes_array()
Processes the string in each value of the input array with extractIncludes
public
static extractIncludes_array(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
-
Array with TypoScript in each value
Return values
array<string|int, mixed> —Same array but where the values has been processed with extractIncludes
getVal()
Get a value/property pair for an object path in TypoScript, eg. "myobject.myvalue.mysubproperty".
public
getVal(string $string, array<string|int, mixed> $setup) : array<string|int, mixed>
Here: Used by the "copy" operator, <
Parameters
- $string : string
-
Object path for which to get the value
- $setup : array<string|int, mixed>
-
Global setup code if $string points to a global object path. But if string is prefixed with "." then its the local setup array.
Return values
array<string|int, mixed> —An array with keys 0/1 being value/property respectively
includeFile()
Include file $filename. Contents of the file will be prepended to &$newstring, filename to &$includedFiles Further include_typoscript tags in the contents are processed recursively
public
static includeFile(string $filename[, int $cycle_counter = 1 ][, bool $returnFiles = false ][, string &$newString = '' ][, array<string|int, mixed> &$includedFiles = [] ][, string $optionalProperties = '' ][, string $parentFilenameOrPath = '' ]) : mixed
Parameters
- $filename : string
-
Relative path to the typoscript file to be included
- $cycle_counter : int = 1
-
Counter for detecting endless loops
- $returnFiles : bool = false
-
When set, filenames of included files will be prepended to the array $includedFiles
- $newString : string = ''
-
The output string to which the content of the file will be prepended (referenced
- $includedFiles : array<string|int, mixed> = []
-
Array to which the filenames of included files will be prepended (referenced)
- $optionalProperties : string = ''
- $parentFilenameOrPath : string = ''
-
The parent file (with absolute path) or path for relative includes
Tags
parse()
Start parsing the input TypoScript text piece. The result is stored in $this->setup
public
parse(string $string[, object|string $matchObj = '' ]) : mixed
Parameters
- $string : string
-
The TypoScript text
- $matchObj : object|string = ''
-
If is object, then this is used to match conditions found in the TypoScript code. If matchObj not specified, then no conditions will work! (Except [GLOBAL])
addImportsFromExternalFiles()
Splits the unparsed TypoScript content into import statements
protected
static addImportsFromExternalFiles(string $typoScript, int $cycleCounter, bool $returnFiles, array<string|int, mixed> &$includedFiles, string &$parentFilenameOrPath) : string
Parameters
- $typoScript : string
-
unparsed TypoScript
- $cycleCounter : int
-
counter to stop recursion
- $returnFiles : bool
-
whether to populate the included Files or not
- $includedFiles : array<string|int, mixed>
-
- by reference - if any included files are added, they are added here
- $parentFilenameOrPath : string
-
the current imported file to resolve relative paths - handled by reference
Return values
string —the unparsed TypoScript with included external files
error()
Stacks errors/messages from the TypoScript parser into an internal array, $this->error If "TT" is a global object (as it is in the frontend when backend users are logged in) the message will be registered here as well.
protected
error(string $message[, int|string $logLevel = LogLevel::WARNING ]) : mixed
Parameters
- $message : string
-
The error message string
- $logLevel : int|string = LogLevel::WARNING
-
The error severity (in the scale of TimeTracker::setTSlogMessage: Approx: 2=warning, 1=info, 0=nothing, 3=fatal.)
executeValueModifier()
Executes operator functions, called from TypoScript example: page.10.value := appendString(!)
protected
executeValueModifier(string $modifierName[, string $modifierArgument = null ][, string $currentValue = null ]) : string|null
Parameters
- $modifierName : string
-
TypoScript function called
- $modifierArgument : string = null
-
Function arguments; In case of multiple arguments, the method must split on its own
- $currentValue : string = null
-
Current TypoScript value
Return values
string|null —Modified result or null for no modification
getLogger()
Get a logger instance
protected
static getLogger() : LoggerInterface
This class uses logging mostly in static functions, hence we need a static getter for the logger. Injection of a logger instance via GeneralUtility::makeInstance is not possible.
Return values
LoggerInterfacegetTimeTracker()
protected
getTimeTracker() : TimeTracker
Return values
TimeTrackerimportExternalTypoScriptFile()
Include file $filename. Contents of the file will be returned, filename is added to &$includedFiles.
protected
static importExternalTypoScriptFile(string $filename, int $cycleCounter, bool $returnFiles, array<string|int, mixed> &$includedFiles) : string
Further include/import statements in the contents are processed recursively.
Parameters
- $filename : string
-
Full absolute path+filename to the typoscript file to be included
- $cycleCounter : int
-
Counter for detecting endless loops
- $returnFiles : bool
-
When set, filenames of included files will be prepended to the array $includedFiles
- $includedFiles : array<string|int, mixed>
-
Array to which the filenames of included files will be prepended (referenced)
Return values
string —the unparsed TypoScript content from external files
includeDirectory()
Include all files with matching Typoscript extensions in directory $dirPath. Contents of the files are prepended to &$newstring, filename to &$includedFiles.
protected
static includeDirectory(string $dirPath[, int $cycle_counter = 1 ][, bool $returnFiles = false ][, string &$newString = '' ][, array<string|int, mixed> &$includedFiles = [] ][, string $optionalProperties = '' ][, string $parentFilenameOrPath = '' ]) : mixed
Order of the directory items to be processed: files first, then directories, both in alphabetical order. Further include_typoscript tags in the contents of the files are processed recursively.
Parameters
- $dirPath : string
-
Relative path to the directory to be included
- $cycle_counter : int = 1
-
Counter for detecting endless loops
- $returnFiles : bool = false
-
When set, filenames of included files will be prepended to the array $includedFiles
- $newString : string = ''
-
The output string to which the content of the file will be prepended (referenced)
- $includedFiles : array<string|int, mixed> = []
-
Array to which the filenames of included files will be prepended (referenced)
- $optionalProperties : string = ''
- $parentFilenameOrPath : string = ''
-
The parent file (with absolute path) or path for relative includes
Tags
nextDivider()
Will search for the next condition. When found it will return the line content (the condition value) and have advanced the internal $this->rawP pointer to point to the next line after the condition.
protected
nextDivider() : string
Tags
Return values
string —The condition value
parseNextKeySegment()
Determines the first key segment of a TypoScript key by searching for the first unescaped dot in the given key string.
protected
parseNextKeySegment(string $key) : array<string|int, mixed>
Since the escape characters are only needed to correctly determine the key segment any escape characters before the first unescaped dot are stripped from the key.
Parameters
- $key : string
-
The key, possibly consisting of multiple key segments separated by unescaped dots
Return values
array<string|int, mixed> —Array with key segment and remaining part of $key
parseSub()
Parsing the $this->raw TypoScript lines from pointer, $this->rawP
protected
parseSub(array<string|int, mixed> &$setup) : string
Parameters
- $setup : array<string|int, mixed>
-
Reference to the setup array in which to accumulate the values.
Return values
string —Returns the string of the condition found, the exit signal or possible nothing (if it completed parsing with no interruptions)
rollParseSub()
Parsing of TypoScript keys inside a curly brace where the key is composite of at least two keys, thus having to recursively call itself to get the value
protected
rollParseSub(string $string, array<string|int, mixed> &$setup) : string
Parameters
- $string : string
-
The object sub-path, eg "thisprop.another_prot
- $setup : array<string|int, mixed>
-
The local setup array from the function calling this function
Tags
Return values
string —Returns the exitSignal
setVal()
Setting a value/property of an object string in the setup array.
protected
setVal(string $string, array<string|int, mixed> &$setup, array<string|int, mixed>|string $value[, bool $wipeOut = false ]) : mixed
Parameters
- $string : string
-
The object sub-path, eg "thisprop.another_prot
- $setup : array<string|int, mixed>
-
The local setup array from the function calling this function.
- $value : array<string|int, mixed>|string
-
The value/property pair array to set. If only one of them is set, then the other is not touched (unless $wipeOut is set, which it is when copies are made which must include both value and property)
- $wipeOut : bool = false
-
If set, then both value and property is wiped out when a copy is made of another value.
typoscriptIncludeError()
Process errors in INCLUDE_TYPOSCRIPT tags Errors are logged and printed in the concatenated TypoScript result (as can be seen in Template Analyzer)
protected
static typoscriptIncludeError(string $error) : string
Parameters
- $error : string
-
Text of the error message
Tags
Return values
string —The error message encapsulated in comments