TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
TypoScriptParser Class Reference
Inheritance diagram for TypoScriptParser:
TsConfigParser

Public Member Functions

 parse ($string, $matchObj= '')
 
 nextDivider ()
 
 parseSub (array &$setup)
 
 rollParseSub ($string, array &$setup)
 
 getVal ($string, $setup)
 
 setVal ($string, array &$setup, $value, $wipeOut=false)
 
 error ($err, $num=2)
 
 doSyntaxHighlight ($string, $lineNum= '', $highlightBlockMode=false)
 
 regHighLight ($code, $pointer, $strlen=-1)
 
 syntaxHighlight_print ($lineNumDat, $highlightBlockMode)
 

Static Public Member Functions

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

Public Attributes

 $setup = []
 
 $raw
 
 $rawP
 
 $lastComment = ''
 
 $commentSet = false
 
 $multiLineEnabled = false
 
 $multiLineObject = ''
 
 $multiLineValue = []
 
 $inBrace = 0
 
 $lastConditionTrue = true
 
 $sections = []
 
 $sectionsMatch = []
 
 $syntaxHighLight = false
 
 $highLightData = []
 
 $highLightData_bracelevel = []
 
 $regComments = false
 
 $regLinenumbers = false
 
 $errors = []
 
 $lineNumberOffset = 0
 
 $breakPointLN = 0
 
 $highLightStyles
 
 $highLightBlockStyles = ''
 
 $highLightBlockStyles_basecolor = '#cccccc'
 
 $parentObject
 

Protected Member Functions

 executeValueModifier ($modifierName, $modifierArgument=null, $currentValue=null)
 
 parseNextKeySegment ($key)
 
 getTimeTracker ()
 
 modifyHTMLColor ($color, $R, $G, $B)
 
 modifyHTMLColorAll ($color, $all)
 

Static Protected Member Functions

static includeDirectory ($dirPath, $cycle_counter=1, $returnFiles=false, &$newString= '', array &$includedFiles=[], $optionalProperties= '', $parentFilenameOrPath= '')
 
static typoscriptIncludeError ($error)
 

Detailed Description

The TypoScript parser

Definition at line 27 of file TypoScriptParser.php.

Member Function Documentation

static checkIncludeLines_array ( array  $array)
static

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

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

Definition at line 1024 of file TypoScriptParser.php.

Referenced by BackendUserAuthentication\fetchGroupData(), BackendUtility\getPagesTSconfig(), TypoScriptFrontendController\getPagesTSconfig(), and FrontendUserAuthentication\getUserTSconf().

doSyntaxHighlight (   $string,
  $lineNum = '',
  $highlightBlockMode = false 
)

Syntax highlight a TypoScript text Will parse the content. Remember, the internal setup array may contain invalid parsed content since conditions are ignored!

Parameters
string$stringThe TypoScript text
mixed$lineNumIf blank, linenumbers are NOT printed. If array then the first key is the linenumber offset to add to the internal counter.
bool$highlightBlockModeIf set, then the highlighted output will be formatted in blocks based on the brace levels. prespace will be ignored and empty lines represented with a single no-break-space.
Returns
string HTML code for the syntax highlighted string

Definition at line 1215 of file TypoScriptParser.php.

References TypoScriptParser\parse(), and TypoScriptParser\syntaxHighlight_print().

error (   $err,
  $num = 2 
)

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$errThe error message string
int$numThe error severity (in the scale of TimeTracker::setTSlogMessage: Approx: 2=warning, 1=info, 0=nothing, 3=fatal.)
Returns
void

Definition at line 773 of file TypoScriptParser.php.

References TypoScriptParser\$lineNumberOffset, and TypoScriptParser\getTimeTracker().

Referenced by TypoScriptParser\parse(), and TypoScriptParser\parseSub().

executeValueModifier (   $modifierName,
  $modifierArgument = null,
  $currentValue = null 
)
protected

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

Parameters
string$modifierNameTypoScript function called
string$modifierArgumentFunction arguments; In case of multiple arguments, the method must split on its own
string$currentValueCurrent TypoScript value
Returns
string Modification result

Definition at line 524 of file TypoScriptParser.php.

References $GLOBALS, GeneralUtility\callUserFunction(), GeneralUtility\SYSLOG_SEVERITY_WARNING, and GeneralUtility\trimExplode().

Referenced by TypoScriptParser\parseSub().

static 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$stringTemplate content
int$cycle_counterCounter for detecting endless loops
array$extractedFileNames
string$parentFilenameOrPath
Exceptions
RuntimeException
UnexpectedValueException
Returns
string Template content with uncommented include statements

Definition at line 1045 of file TypoScriptParser.php.

References PathUtility\getAbsolutePathOfRelativeReferencedFileOrPath(), GeneralUtility\getFileAbsFileName(), GeneralUtility\SYSLOG_SEVERITY_WARNING, GeneralUtility\verifyFilenameAgainstDenyPattern(), and GeneralUtility\writeFile().

static extractIncludes_array ( array  $array)
static

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

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

Definition at line 1193 of file TypoScriptParser.php.

Referenced by TypoScriptTemplateInformationModuleFunctionController\processTemplateRowBeforeSaving().

getTimeTracker ( )
protected
Returns
TimeTracker

Definition at line 1309 of file TypoScriptParser.php.

References GeneralUtility\makeInstance().

Referenced by TypoScriptParser\error().

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$stringObject path for which to get the value
array$setupGlobal 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 633 of file TypoScriptParser.php.

References TypoScriptParser\$setup, and TypoScriptParser\parseNextKeySegment().

Referenced by TypoScriptParser\parseSub().

static 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$dirPathRelative path to the directory to be included
int$cycle_counterCounter for detecting endless loops
bool$returnFilesWhen set, filenames of included files will be prepended to the array &$includedFiles
string&$newStringThe output string to which the content of the file will be prepended (referenced)
array&$includedFilesArray to which the filenames of included files will be prepended (referenced)
string$optionalProperties
string$parentFilenameOrPathThe parent file (with absolute path) or path for relative includes

Definition at line 970 of file TypoScriptParser.php.

References PathUtility\getAbsolutePathOfRelativeReferencedFileOrPath(), GeneralUtility\getAllFilesAndFoldersInPath(), and GeneralUtility\getFileAbsFileName().

static 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$filenameRelative path to the typoscript file to be included
int$cycle_counterCounter for detecting endless loops
bool$returnFilesWhen set, filenames of included files will be prepended to the array &$includedFiles
string&$newStringThe output string to which the content of the file will be prepended (referenced
array&$includedFilesArray to which the filenames of included files will be prepended (referenced)
string$optionalProperties
string$parentFilenameOrPathThe parent file (with absolute path) or path for relative includes

Definition at line 921 of file TypoScriptParser.php.

References PathUtility\getAbsolutePathOfRelativeReferencedFileOrPath(), GeneralUtility\getFileAbsFileName(), and GeneralUtility\verifyFilenameAgainstDenyPattern().

modifyHTMLColor (   $color,
  $R,
  $G,
  $B 
)
protected

Modifies a HTML Hex color by adding/subtracting $R,$G and $B integers

Parameters
string$colorA hexadecimal color code, #xxxxxx
int$ROffset value 0-255
int$GOffset value 0-255
int$BOffset value 0-255
Returns
string A hexadecimal color code, #xxxxxx, modified according to input vars
See also
modifyHTMLColorAll()

Definition at line 1324 of file TypoScriptParser.php.

References MathUtility\forceIntegerInRange().

Referenced by TypoScriptParser\modifyHTMLColorAll().

modifyHTMLColorAll (   $color,
  $all 
)
protected

Modifies a HTML Hex color by adding/subtracting $all integer from all R/G/B channels

Parameters
string$colorA hexadecimal color code, #xxxxxx
int$allOffset value 0-255 for all three channels.
Returns
string A hexadecimal color code, #xxxxxx, modified according to input vars
See also
modifyHTMLColor()

Definition at line 1341 of file TypoScriptParser.php.

References TypoScriptParser\modifyHTMLColor().

Referenced by TypoScriptParser\syntaxHighlight_print().

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.

Returns
string The condition value
See also
parse()

Definition at line 281 of file TypoScriptParser.php.

Referenced by TypoScriptParser\parse().

parse (   $string,
  $matchObj = '' 
)

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

Parameters
string$stringThe TypoScript text
object | string$matchObjIf 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])
Returns
void

Definition at line 230 of file TypoScriptParser.php.

References TypoScriptParser\$syntaxHighLight, TypoScriptParser\error(), TypoScriptParser\nextDivider(), and TypoScriptParser\parseSub().

Referenced by TypoScriptParser\doSyntaxHighlight().

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$keyThe 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 724 of file TypoScriptParser.php.

Referenced by TypoScriptParser\getVal(), TypoScriptParser\rollParseSub(), and TypoScriptParser\setVal().

parseSub ( array &  $setup)

Parsing the $this->raw TypoScript lines from pointer, $this->rawP

Parameters
array$setupReference to the setup array in which to accumulate the values.
Returns
string|NULL Returns the string of the condition found, the exit signal or possible nothing (if it completed parsing with no interruptions)

Definition at line 299 of file TypoScriptParser.php.

References TypoScriptParser\$lastComment, TypoScriptParser\$multiLineObject, TypoScriptParser\$rawP, TypoScriptParser\error(), TypoScriptParser\executeValueModifier(), TypoScriptParser\getVal(), TypoScriptParser\regHighLight(), TypoScriptParser\rollParseSub(), and TypoScriptParser\setVal().

Referenced by TypoScriptParser\parse(), and TypoScriptParser\rollParseSub().

regHighLight (   $code,
  $pointer,
  $strlen = -1 
)

Registers a part of a TypoScript line for syntax highlighting.

Parameters
string$codeKey from the internal array $this->highLightStyles
int$pointerPointer to the line in $this->raw which this is about
int$strlenThe number of chars LEFT on this line before the end is reached.
Returns
void private
See also
parse()

Definition at line 1236 of file TypoScriptParser.php.

References TypoScriptParser\$inBrace.

Referenced by TypoScriptParser\parseSub().

rollParseSub (   $string,
array &  $setup 
)

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$stringThe object sub-path, eg "thisprop.another_prot
array$setupThe local setup array from the function calling this function
Returns
string Returns the exitSignal
See also
parseSub()

Definition at line 608 of file TypoScriptParser.php.

References TypoScriptParser\parseNextKeySegment(), and TypoScriptParser\parseSub().

Referenced by TypoScriptParser\parseSub().

setVal (   $string,
array &  $setup,
  $value,
  $wipeOut = false 
)

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

Parameters
string$stringThe object sub-path, eg "thisprop.another_prot
array$setupThe local setup array from the function calling this function.
array | string$valueThe 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$wipeOutIf set, then both value and property is wiped out when a copy is made of another value.
Returns
void

Definition at line 667 of file TypoScriptParser.php.

References TypoScriptParser\$lastComment, and TypoScriptParser\parseNextKeySegment().

Referenced by TypoScriptParser\parseSub().

syntaxHighlight_print (   $lineNumDat,
  $highlightBlockMode 
)

Formatting the TypoScript code in $this->raw based on the data collected by $this->regHighLight in $this->highLightData

Parameters
mixed$lineNumDatIf blank, linenumbers are NOT printed. If array then the first key is the linenumber offset to add to the internal counter.
bool$highlightBlockModeIf set, then the highlighted output will be formatted in blocks based on the brace levels. prespace will be ignored and empty lines represented with a single no-break-space.
Returns
string HTML content private
See also
doSyntaxHighlight()

Definition at line 1255 of file TypoScriptParser.php.

References TypoScriptParser\$rawP, debug(), and TypoScriptParser\modifyHTMLColorAll().

Referenced by TypoScriptParser\doSyntaxHighlight().

static typoscriptIncludeError (   $error)
staticprotected

Process errors in INCLUDE_TYPOSCRIPT tags Errors are logged in sysLog 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 1012 of file TypoScriptParser.php.

References GeneralUtility\SYSLOG_SEVERITY_WARNING.

Member Data Documentation

$breakPointLN = 0

Definition at line 168 of file TypoScriptParser.php.

$commentSet = false

Definition at line 62 of file TypoScriptParser.php.

$errors = []

Definition at line 154 of file TypoScriptParser.php.

$highLightBlockStyles = ''

Definition at line 208 of file TypoScriptParser.php.

$highLightBlockStyles_basecolor = '#cccccc'

Definition at line 215 of file TypoScriptParser.php.

$highLightData = []

Definition at line 126 of file TypoScriptParser.php.

$highLightData_bracelevel = []

Definition at line 133 of file TypoScriptParser.php.

$highLightStyles
Initial value:
= [
'prespace' => ['<span class="ts-prespace">', '</span>']

Definition at line 173 of file TypoScriptParser.php.

$inBrace = 0

Definition at line 90 of file TypoScriptParser.php.

Referenced by TypoScriptParser\regHighLight().

$lastComment = ''

Definition at line 55 of file TypoScriptParser.php.

Referenced by TypoScriptParser\parseSub(), and TypoScriptParser\setVal().

$lastConditionTrue = true

Definition at line 98 of file TypoScriptParser.php.

$lineNumberOffset = 0

Definition at line 161 of file TypoScriptParser.php.

Referenced by TypoScriptParser\error().

$multiLineEnabled = false

Definition at line 69 of file TypoScriptParser.php.

$multiLineObject = ''

Definition at line 76 of file TypoScriptParser.php.

Referenced by TypoScriptParser\parseSub().

$multiLineValue = []

Definition at line 83 of file TypoScriptParser.php.

$parentObject

Definition at line 220 of file TypoScriptParser.php.

$raw

Definition at line 41 of file TypoScriptParser.php.

$regComments = false

Definition at line 140 of file TypoScriptParser.php.

$regLinenumbers = false

Definition at line 147 of file TypoScriptParser.php.

$sections = []

Definition at line 105 of file TypoScriptParser.php.

$sectionsMatch = []

Definition at line 112 of file TypoScriptParser.php.

$setup = []

Definition at line 34 of file TypoScriptParser.php.

Referenced by TypoScriptParser\getVal().

$syntaxHighLight = false

Definition at line 119 of file TypoScriptParser.php.

Referenced by TypoScriptParser\parse().