Parser

Dynamic Syntax parser

 class Winter\Storm\Parse\Syntax\Parser

Constants

Constant Description
CHAR_CLOSE
string "}"
CHAR_OPEN
string "{"

Properties

protected $fieldParser : Winter\Storm\Parse\Syntax\FieldParser

Field parser instance.

protected $template : string

The template content to parse.

protected $textParser : Winter\Storm\Parse\Bracket

Text parser instance.

protected $varPrefix : string

A prefix to place before all variable references when rendering the view.

Methods

public final __construct (string $template, array $options = [])

Constructor.

Available options:

  • varPrefix: Prefix to add to every top level parameter.
  • tagPrefix: Prefix to add to all tags, in addition to tags without a prefix.
Parameters
Property Description
$template
string

Template to parse.

$options
array
Returns
mixed

public getFieldValues () : array

Returns the default field values defined in the template

Returns
array

public static parse (string $template, array $options = []) : static

Static helper for new instances of this class.

Parameters
Property Description
$template
string
$options
array
Returns
static

public render (array $vars = [], array $options = []) : string

Renders the template fields to their actual values

Parameters
Property Description
$vars
array
$options
array
Returns
string

public toEditor () : array

Returns an array of all fields and their options.

Returns
array

public toTwig () : string

Returns the template with fields replaced with Twig markup

Returns
string

public toView () : string

Returns the template with fields replaced with the simple templating engine used by the TextParser class.

Returns
string

protected evalSimpleViewField (string $field, array $params, $prefix = null) : string

Processes a field type and converts it to the Simple engine.

Parameters
Property Description
$field
string
$params
array
$prefix
mixed
Returns
string

protected evalTwigViewField (string $field, array $params, string $prefix = null) : string

Processes a field type and converts it to the Twig engine.

Parameters
Property Description
$field
string
$params
array
$prefix
string
Returns
string

protected processRepeatingTag ($engine, $template, $field, $tagDetails)

Parameters
Property Description
$engine
mixed
$template
mixed
$field
mixed
$tagDetails
mixed
Returns
mixed

protected processTag ($engine, $template, $field, $tagString)

Parameters
Property Description
$engine
mixed
$template
mixed
$field
mixed
$tagString
mixed
Returns
mixed

protected toViewEngine (string $engine) : string

Parses the template to a specific view engine (Twig, Simple)

Parameters
Property Description
$engine
string
Returns
string
Copyright © 2024 Winter CMS