‪TYPO3CMS  ‪main
TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser Class Reference

Public Member Functions

 __construct ()
 
 parse ($string, $matchObj='')
 
array getVal ($string, $setup)
 

Static Public Member Functions

static string array checkIncludeLines ($string, $cycle_counter=1, $returnFiles=false, $parentFilenameOrPath='')
 
static includeFile ($filename, $cycle_counter=1, $returnFiles=false, &$newString='', array &$includedFiles=[], $optionalProperties='', $parentFilenameOrPath='')
 
static array checkIncludeLines_array (array $array)
 
static string extractIncludes ($string, $cycle_counter=1, array $extractedFileNames=[], $parentFilenameOrPath='')
 
static array extractIncludes_array (array $array)
 

Public Attributes

array $setup = array( )
 
array $sections = array( )
 
array $sectionsMatch = array( )
 
bool $regComments = false
 
bool $regLinenumbers = false
 
array $errors = array( )
 
int $lineNumberOffset = 0
 

Protected Member Functions

string nextDivider ()
 
string parseSub (array &$setup)
 
string null executeValueModifier ($modifierName, $modifierArgument=null, $currentValue=null)
 
string rollParseSub ($string, array &$setup)
 
 setVal ($string, array &$setup, $value, $wipeOut=false)
 
array parseNextKeySegment ($key)
 
 error ($message, $logLevel=LogLevel::WARNING)
 
TimeTracker getTimeTracker ()
 

Static Protected Member Functions

static string addImportsFromExternalFiles ($typoScript, $cycleCounter, $returnFiles, &$includedFiles, &$parentFilenameOrPath)
 
static string importExternalTypoScriptFile ($filename, $cycleCounter, $returnFiles, array &$includedFiles)
 
static includeDirectory ($dirPath, $cycle_counter=1, $returnFiles=false, &$newString='', array &$includedFiles=[], $optionalProperties='', $parentFilenameOrPath='')
 
static string typoscriptIncludeError ($error)
 
static LoggerInterface getLogger ()
 

Protected Attributes

string[] $raw
 
int $rawP
 
string $lastComment = ''
 
bool $commentSet = false
 
bool $multiLineEnabled = false
 
string $multiLineObject = ''
 
array $multiLineValue = array( )
 
int $inBrace = 0
 
bool $lastConditionTrue = true
 

Detailed Description

The TypoScript parser.

Deprecated:
‪This class should not be used anymore. Switch to the new parser construct instead.

Definition at line 37 of file TypoScriptParser.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::__construct ( )

Definition at line 136 of file TypoScriptParser.php.

Member Function Documentation

◆ addImportsFromExternalFiles()

static string TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::addImportsFromExternalFiles (   $typoScript,
  $cycleCounter,
  $returnFiles,
$includedFiles,
$parentFilenameOrPath 
)
staticprotected

Splits the unparsed TypoScript content into import statements

Parameters
string$typoScript‪unparsed TypoScript
int$cycleCounter‪counter to stop recursion
bool$returnFiles‪whether to populate the included Files or not
array$includedFiles‪- by reference - if any included files are added, they are added here
string$parentFilenameOrPath‪the current imported file to resolve relative paths - handled by reference
Returns
‪string the unparsed TypoScript with included external files

Definition at line 830 of file TypoScriptParser.php.

References TYPO3\CMS\Core\Utility\PathUtility\getAbsolutePathOfRelativeReferencedFileOrPath(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\importExternalTypoScriptFile().

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\checkIncludeLines().

◆ checkIncludeLines()

static string array TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines (   $string,
  $cycle_counter = 1,
  $returnFiles = false,
  $parentFilenameOrPath = '' 
)
static

Checks the input string (un-parsed TypoScript) for include-commands ("<INCLUDE_TYPOSCRIPT: ....") Use: \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines()

Parameters
string$string‪Unparsed TypoScript
int$cycle_counter‪Counter for detecting endless loops
bool$returnFiles‪When set an array containing the resulting typoscript and all included files will get returned
string$parentFilenameOrPath‪The parent file (with absolute path) or path for relative includes
Returns
‪string|array Complete TypoScript with includes added.

Definition at line 677 of file TypoScriptParser.php.

References $GLOBALS, TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\addImportsFromExternalFiles(), TYPO3\CMS\Core\Http\fromRequest, TYPO3\CMS\Core\Utility\PathUtility\getAbsolutePathOfRelativeReferencedFileOrPath(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\getLogger(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\includeDirectory(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\includeFile(), TYPO3\CMS\Core\Utility\StringUtility\removeByteOrderMark(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\typoscriptIncludeError().

Referenced by TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\Parser\TypoScriptParserTest\importFiles(), TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\Parser\TypoScriptParserTest\includeFilesWithConditions(), and TYPO3\CMS\Core\TypoScript\TemplateService\processIncludes().

◆ checkIncludeLines_array()

static array TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines_array ( array  $array)
static

Parses the string in each value of the input array for include-commands

Parameters
array$array‪Array with TypoScript in each value
Returns
‪array Same array but where the values has been parsed for include-commands

Definition at line 1082 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\collect(), and TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication\getUserTSconf().

◆ error()

TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::error (   $message,
  $logLevel = LogLevel::WARNING 
)
protected

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.

Parameters
string$message‪The error message string
int | string$logLevel‪The error severity (in the scale of TimeTracker::setTSlogMessage: Approx: 2=warning, 1=info, 0=nothing, 3=fatal.)

Definition at line 660 of file TypoScriptParser.php.

References TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$lineNumberOffset, TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\getTimeTracker(), and TYPO3\CMS\Core\TimeTracker\TimeTracker\setTSlogMessage().

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parse(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseSub().

◆ executeValueModifier()

string null TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::executeValueModifier (   $modifierName,
  $modifierArgument = null,
  $currentValue = null 
)
protected

Executes operator functions, called from TypoScript example: page.10.value := appendString(!)

Parameters
string$modifierNameTypoScript function called
string$modifierArgument‪Function arguments; In case of multiple arguments, the method must split on its own
string$currentValue‪Current TypoScript value
Returns
‪string|null Modified result or null for no modification

Definition at line 406 of file TypoScriptParser.php.

References $GLOBALS, TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\getLogger(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseSub().

◆ extractIncludes()

static string TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::extractIncludes (   $string,
  $cycle_counter = 1,
array  $extractedFileNames = [],
  $parentFilenameOrPath = '' 
)
static

Search for commented INCLUDE_TYPOSCRIPT statements and save the content between the BEGIN and the END line to the specified file

Parameters
string$string‪Template content
int$cycle_counter‪Counter for detecting endless loops
string$parentFilenameOrPath
Exceptions

Definition at line 1103 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\extractIncludes_array().

◆ extractIncludes_array()

static array TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::extractIncludes_array ( array  $array)
static

Processes the string in each value of the input array with extractIncludes

Parameters
array$array‪Array with TypoScript in each value
Returns
‪array Same array but where the values has been processed with extractIncludes

Definition at line 1250 of file TypoScriptParser.php.

References TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\extractIncludes().

◆ getLogger()

static LoggerInterface TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::getLogger ( )
staticprotected

Get a logger instance

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.

Returns
‪LoggerInterface

Definition at line 1274 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\checkIncludeLines(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\executeValueModifier().

◆ getTimeTracker()

TimeTracker TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::getTimeTracker ( )
protected

◆ getVal()

array TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::getVal (   $string,
  $setup 
)

Get a value/property pair for an object path in TypoScript, eg. "myobject.myvalue.mysubproperty". Here: Used by the "copy" operator, <

Parameters
string$string‪Object path for which to get the value
array$setup‪Global setup code if $string points to a global object path. But if string is prefixed with "." then its the local setup array.
Returns
‪array An array with keys 0/1 being value/property respectively

Definition at line 523 of file TypoScriptParser.php.

References TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$setup, and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseNextKeySegment().

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseSub().

◆ importExternalTypoScriptFile()

static string TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::importExternalTypoScriptFile (   $filename,
  $cycleCounter,
  $returnFiles,
array &  $includedFiles 
)
staticprotected

Include file $filename. Contents of the file will be returned, filename is added to &$includedFiles. Further include/import statements in the contents are processed recursively.

Parameters
string$filename‪Full absolute path+filename to the typoscript file to be included
int$cycleCounter‪Counter for detecting endless loops
bool$returnFiles‪When set, filenames of included files will be prepended to the array $includedFiles
array$includedFiles‪Array to which the filenames of included files will be prepended (referenced)
Returns
‪string the unparsed TypoScript content from external files

Definition at line 867 of file TypoScriptParser.php.

References $finder, TYPO3\CMS\Core\Utility\PathUtility\basename(), TYPO3\CMS\Core\Utility\PathUtility\dirname(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\typoscriptIncludeError().

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\addImportsFromExternalFiles().

◆ includeDirectory()

static TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::includeDirectory (   $dirPath,
  $cycle_counter = 1,
  $returnFiles = false,
$newString = '',
array &  $includedFiles = [],
  $optionalProperties = '',
  $parentFilenameOrPath = '' 
)
staticprotected

Include all files with matching Typoscript extensions in directory $dirPath. Contents of the files are prepended to &$newstring, filename to &$includedFiles. 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
string$dirPath‪Relative path to the directory to be included
int$cycle_counter‪Counter for detecting endless loops
bool$returnFiles‪When set, filenames of included files will be prepended to the array $includedFiles
string$newString‪The output string to which the content of the file will be prepended (referenced)
array$includedFiles‪Array to which the filenames of included files will be prepended (referenced)
string$optionalProperties
string$parentFilenameOrPath‪The parent file (with absolute path) or path for relative includes

Definition at line 1029 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\checkIncludeLines().

◆ includeFile()

static TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::includeFile (   $filename,
  $cycle_counter = 1,
  $returnFiles = false,
$newString = '',
array &  $includedFiles = [],
  $optionalProperties = '',
  $parentFilenameOrPath = '' 
)
static

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

Parameters
string$filename‪Relative path to the typoscript file to be included
int$cycle_counter‪Counter for detecting endless loops
bool$returnFiles‪When set, filenames of included files will be prepended to the array $includedFiles
string$newString‪The output string to which the content of the file will be prepended (referenced
array$includedFiles‪Array to which the filenames of included files will be prepended (referenced)
string$optionalProperties
string$parentFilenameOrPath‪The parent file (with absolute path) or path for relative includes

Definition at line 973 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\checkIncludeLines().

◆ nextDivider()

string TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::nextDivider ( )
protected

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.

Returns
‪string The condition value
See also
parse()

Definition at line 198 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parse().

◆ parse()

TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::parse (   $string,
  $matchObj = '' 
)

Start parsing the input TypoScript text piece. The result is stored in $this->setup

Parameters
string$string‪The TypoScript text
object | string$matchObj‪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])

Definition at line 147 of file TypoScriptParser.php.

References TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\error(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\nextDivider(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseSub().

◆ parseNextKeySegment()

array TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::parseNextKeySegment (   $key)
protected

Determines the first key segment of a TypoScript key by searching for the first unescaped dot in the given key string.

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
string$key‪The key, possibly consisting of multiple key segments separated by unescaped dots
Returns
‪array Array with key segment and remaining part of $key

Definition at line 612 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\getVal(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\rollParseSub(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\setVal().

◆ parseSub()

string TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::parseSub ( array &  $setup)
protected

◆ rollParseSub()

string TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::rollParseSub (   $string,
array &  $setup 
)
protected

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

Parameters
string$string‪The object sub-path, eg "thisprop.another_prot
array$setup‪The local setup array from the function calling this function
Returns
‪string Returns the exitSignal
See also
parseSub()

Definition at line 498 of file TypoScriptParser.php.

References TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$setup, TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseNextKeySegment(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseSub().

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseSub().

◆ setVal()

TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::setVal (   $string,
array &  $setup,
  $value,
  $wipeOut = false 
)
protected

Setting a value/property of an object string in the setup array.

Parameters
string$string‪The object sub-path, eg "thisprop.another_prot
array$setup‪The local setup array from the function calling this function.
array | string$value‪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)
bool$wipeOut‪If set, then both value and property is wiped out when a copy is made of another value.

Definition at line 555 of file TypoScriptParser.php.

References TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$lastComment, TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$setup, and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseNextKeySegment().

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseSub(), TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\Parser\TypoScriptParserTest\setValCanBeCalledWithArrayValueParameter(), and TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\Parser\TypoScriptParserTest\setValCanBeCalledWithStringValueParameter().

◆ typoscriptIncludeError()

static string TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::typoscriptIncludeError (   $error)
staticprotected

Process errors in INCLUDE_TYPOSCRIPT tags Errors are logged and printed in the concatenated TypoScript result (as can be seen in Template Analyzer)

Parameters
string$errorText of the error message
Returns
‪string The error message encapsulated in comments

Definition at line 1070 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\checkIncludeLines(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\importExternalTypoScriptFile().

Member Data Documentation

◆ $commentSet

bool TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$commentSet = false
protected

Internally set, used as internal flag to create a multi-line comment (one of those like /* ... * /

Definition at line 67 of file TypoScriptParser.php.

◆ $errors

array TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$errors = array( )

Error accumulation array.

Definition at line 128 of file TypoScriptParser.php.

◆ $inBrace

int TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$inBrace = 0
protected

Internally set, when in brace. Counter.

Definition at line 91 of file TypoScriptParser.php.

◆ $lastComment

string TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$lastComment = ''
protected

◆ $lastConditionTrue

bool TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$lastConditionTrue = true
protected

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.

Definition at line 98 of file TypoScriptParser.php.

◆ $lineNumberOffset

int TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$lineNumberOffset = 0

Used for the error messages line number reporting. Set externally.

Definition at line 134 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\error().

◆ $multiLineEnabled

bool TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$multiLineEnabled = false
protected

Internally set, when multiline value is accumulated

Definition at line 73 of file TypoScriptParser.php.

◆ $multiLineObject

string TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$multiLineObject = ''
protected

Internally set, when multiline value is accumulated

Definition at line 79 of file TypoScriptParser.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parseSub().

◆ $multiLineValue

array TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$multiLineValue = array( )
protected

Internally set, when multiline value is accumulated

Definition at line 85 of file TypoScriptParser.php.

◆ $raw

string [] TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$raw
protected

Raw data, the input string exploded by LF

Definition at line 49 of file TypoScriptParser.php.

◆ $rawP

int TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$rawP
protected

Pointer to entry in raw data array

Definition at line 55 of file TypoScriptParser.php.

◆ $regComments

bool TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$regComments = false

DO NOT register the comments. This is default for the ordinary sitetemplate!

Definition at line 116 of file TypoScriptParser.php.

◆ $regLinenumbers

bool TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$regLinenumbers = false

DO NOT register the linenumbers. This is default for the ordinary sitetemplate!

Definition at line 122 of file TypoScriptParser.php.

◆ $sections

array TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$sections = array( )

Tracking all conditions found

Definition at line 104 of file TypoScriptParser.php.

◆ $sectionsMatch

array TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::$sectionsMatch = array( )

Tracking all matching conditions found

Definition at line 110 of file TypoScriptParser.php.

◆ $setup