PHP Class Phly\Mustache\Lexer

Compiles mustache templates into a list of tokens.
Datei anzeigen Open project: phly/phly_mustache Class Usage Examples

Protected Properties

Property Type Description
$manager Phly\Mustache\Mustache The Mustache manager
$nestingLevel integer Current nesting level in hierarchical templates
$patterns array Patterns referenced by lexer
$placeholders array Array is keyed based on current $nestingLevel
$stripWhitespaceFlag boolean Whether or not to strip whitespace
$whitespaceCharacters Whitespace characters that occur in tags.

Public Methods

Method Description
compile ( string $string, null | string $templateName = null ) : array Compile a string into a set of tokens
disableStripWhitespace ( null | boolean $flag = null ) : boolean | Lexer Set or get the flag indicating whether or not to strip whitespace
getManager ( ) : null | Phly\Mustache\Mustache Retrieve the mustache manager
setManager ( Phly\Mustache\Mustache $manager ) : Lexer Set mustache manager

Protected Methods

Method Description
implodePregQuote ( string $glue, array $pieces, string $delimiter = null ) : string Implode and preg_quote() an array of $pieces
replaceTokens ( array $originalTokens, array $replacements ) : array Inject replacements from template inheritance
stripWhitespace ( ref &$tokens, integer $position ) : void Strip whitespace in content tokens surrounding a given token

Method Details

compile() public method

Compile a string into a set of tokens
public compile ( string $string, null | string $templateName = null ) : array
$string string
$templateName null | string Template to use in the case of a partial
return array

disableStripWhitespace() public method

Set or get the flag indicating whether or not to strip whitespace
public disableStripWhitespace ( null | boolean $flag = null ) : boolean | Lexer
$flag null | boolean Null indicates retrieving; boolean value sets
return boolean | Lexer

getManager() public method

Retrieve the mustache manager
public getManager ( ) : null | Phly\Mustache\Mustache
return null | Phly\Mustache\Mustache

implodePregQuote() protected method

Implode and preg_quote() an array of $pieces
protected implodePregQuote ( string $glue, array $pieces, string $delimiter = null ) : string
$glue string String to join $pieces with
$pieces array Strings to be quoted then joined
$delimiter string The delimiter required by PCRE functions If included, it will also be escaped
return string

replaceTokens() protected method

Inject replacements from template inheritance
protected replaceTokens ( array $originalTokens, array $replacements ) : array
$originalTokens array
$replacements array
return array

setManager() public method

Used internally to resolve and tokenize partials
public setManager ( Phly\Mustache\Mustache $manager ) : Lexer
$manager Phly\Mustache\Mustache
return Lexer

stripWhitespace() protected method

Strip whitespace in content tokens surrounding a given token
protected stripWhitespace ( ref &$tokens, integer $position ) : void
$tokens ref Reference to the tokens array
$position integer
return void

Property Details

$manager protected_oe property

The Mustache manager
protected Mustache,Phly\Mustache $manager
return Phly\Mustache\Mustache

$nestingLevel protected_oe property

Current nesting level in hierarchical templates
protected int $nestingLevel
return integer

$patterns protected_oe property

Patterns referenced by lexer
protected array $patterns
return array

$placeholders protected_oe property

Array is keyed based on current $nestingLevel
protected array $placeholders
return array

$stripWhitespaceFlag protected_oe property

Whether or not to strip whitespace
protected bool $stripWhitespaceFlag
return boolean

$whitespaceCharacters protected_oe property

Whitespace characters that occur in tags.
protected $whitespaceCharacters