TYPO3  7.6
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
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=array(), $optionalProperties= '', $parentFilenameOrPath= '')
 
static checkIncludeLines_array (array $array)
 
static extractIncludes ($string, $cycle_counter=1, array $extractedFileNames=array(), $parentFilenameOrPath= '')
 
static extractIncludes_array (array $array)
 

Public Attributes

 $strict = true
 
 $setup = array()
 
 $raw
 
 $rawP
 
 $lastComment = ''
 
 $commentSet = false
 
 $multiLineEnabled = false
 
 $multiLineObject = ''
 
 $multiLineValue = array()
 
 $inBrace = 0
 
 $lastConditionTrue = true
 
 $sections = array()
 
 $sectionsMatch = array()
 
 $syntaxHighLight = false
 
 $highLightData = array()
 
 $highLightData_bracelevel = array()
 
 $regComments = false
 
 $regLinenumbers = false
 
 $errors = array()
 
 $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=array(), $optionalProperties= '', $parentFilenameOrPath= '')
 
static typoscriptIncludeError ($error)
 

Detailed Description

The TypoScript parser

Definition at line 28 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 1029 of file TypoScriptParser.php.

Referenced by 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 1220 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 $GLOBALS['TT']->setTSlogMessage: Approx: 2=warning, 1=info, 0=nothing, 3=fatal.)
Returns
void

Definition at line 777 of file TypoScriptParser.php.

References 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 528 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 = array(),
  $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 1050 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 1198 of file TypoScriptParser.php.

Referenced by TypoScriptTemplateInformationModuleFunctionController\processTemplateRowBeforeSaving().

getTimeTracker ( )
protected
Returns
TimeTracker

Definition at line 1314 of file TypoScriptParser.php.

References $GLOBALS.

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 637 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 = array(),
  $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 975 of file TypoScriptParser.php.

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

static includeFile (   $filename,
  $cycle_counter = 1,
  $returnFiles = false,
$newString = '',
array &  $includedFiles = array(),
  $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 926 of file TypoScriptParser.php.

References $filename, elseif, PathUtility\getAbsolutePathOfRelativeReferencedFileOrPath(), GeneralUtility\getFileAbsFileName(), GeneralUtility\getUrl(), 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 1330 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 1347 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 289 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 238 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 728 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 307 of file TypoScriptParser.php.

References TypoScriptParser\$lastComment, TypoScriptParser\$multiLineObject, TypoScriptParser\$rawP, StringUtility\beginsWith(), elseif, 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 1241 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 612 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 671 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 1260 of file TypoScriptParser.php.

References TypoScriptParser\$rawP, debug(), elseif, 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 1017 of file TypoScriptParser.php.

References GeneralUtility\SYSLOG_SEVERITY_WARNING.

Member Data Documentation

$breakPointLN = 0

Definition at line 176 of file TypoScriptParser.php.

$commentSet = false

Definition at line 70 of file TypoScriptParser.php.

$errors = array()

Definition at line 162 of file TypoScriptParser.php.

$highLightBlockStyles = ''

Definition at line 216 of file TypoScriptParser.php.

$highLightBlockStyles_basecolor = '#cccccc'

Definition at line 223 of file TypoScriptParser.php.

$highLightData = array()

Definition at line 134 of file TypoScriptParser.php.

$highLightData_bracelevel = array()

Definition at line 141 of file TypoScriptParser.php.

$highLightStyles
Initial value:
= array(
'prespace' => array('<span class="ts-prespace">', '</span>'),
'objstr_postspace' => array('<span class="ts-objstr_postspace">', '</span>'),
'operator_postspace' => array('<span class="ts-operator_postspace">', '</span>'),
'operator' => array('<span class="ts-operator">', '</span>'),
'value' => array('<span class="ts-value">', '</span>'),
'objstr' => array('<span class="ts-objstr">', '</span>'),
'value_copy' => array('<span class="ts-value_copy">', '</span>'),
'value_unset' => array('<span class="ts-value_unset">', '</span>'),
'ignored' => array('<span class="ts-ignored">', '</span>'),
'default' => array('<span class="ts-default">', '</span>'),
'comment' => array('<span class="ts-comment">', '</span>'),
'condition' => array('<span class="ts-condition">', '</span>'),
'error' => array('<span class="ts-error">', '</span>'),
'linenum' => array('<span class="ts-linenum">', '</span>')
)

Definition at line 181 of file TypoScriptParser.php.

$inBrace = 0

Definition at line 98 of file TypoScriptParser.php.

Referenced by TypoScriptParser\regHighLight().

$lastComment = ''

Definition at line 63 of file TypoScriptParser.php.

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

$lastConditionTrue = true

Definition at line 106 of file TypoScriptParser.php.

$lineNumberOffset = 0

Definition at line 169 of file TypoScriptParser.php.

$multiLineEnabled = false

Definition at line 77 of file TypoScriptParser.php.

$multiLineObject = ''

Definition at line 84 of file TypoScriptParser.php.

Referenced by TypoScriptParser\parseSub().

$multiLineValue = array()

Definition at line 91 of file TypoScriptParser.php.

$parentObject

Definition at line 228 of file TypoScriptParser.php.

$raw

Definition at line 49 of file TypoScriptParser.php.

$rawP
$regComments = false

Definition at line 148 of file TypoScriptParser.php.

$regLinenumbers = false

Definition at line 155 of file TypoScriptParser.php.

$sections = array()

Definition at line 113 of file TypoScriptParser.php.

$sectionsMatch = array()

Definition at line 120 of file TypoScriptParser.php.

$setup = array()

Definition at line 42 of file TypoScriptParser.php.

Referenced by TypoScriptParser\getVal().

$strict = true

Definition at line 35 of file TypoScriptParser.php.

$syntaxHighLight = false

Definition at line 127 of file TypoScriptParser.php.

Referenced by TypoScriptParser\parse().