FieldParser

Dynamic Syntax parser

 class Winter\Storm\Parse\Syntax\FieldParser

Properties

protected $fields : array

Extracted fields from the template The array key should match a unique field name, and the value is another array with values:

  • type: the tag name, eg: text
  • default: the default tag text
  • *: defined parameters

protected $registeredTags : array

Registered template tags

protected $tagPrefix : string

A prefix to place before all tag references eg: {namespace:text}{/namespace:text}

protected $tags : array

Complete tag strings for each field. The array key will match the unique field name and the value is the complete tag string, eg: {text}...{/text}

protected $template : string

Template contents

Methods

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

Constructor.

Parameters
Property Description
$template
string

Template to parse.

$options
array
Returns
mixed

public getDefaultParams (array $fields = null) : array

Returns default values for all fields.

Parameters
Property Description
$fields
array
Returns
array

public getFieldParams (string $field) : array

Returns defined parameters for a single field

Parameters
Property Description
$field
string
Returns
array

public getFieldTags (string $field) : array

Returns tag strings for a specific field

Parameters
Property Description
$field
string
Returns
array

public getFields () : array

Returns all field definitions found in the template

Returns
array

public getTags () : array

Returns all tag strings found 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

protected processOptionsToArray (string $optionsString) : array

Splits an option string to an array.

one|two -> [one, two] one:One|two:Two -> [one => 'One', two => 'Two'] \Path\To\Class::method -> \Path\To\Class::method(): array

Parameters
Property Description
$optionsString
string
Returns
array

protected processParams (string $value, string $tagName) : array

Processes group 2 from the Tag regex and returns an array of captured parameters.

Parameters
Property Description
$value
string
$tagName
string
Returns
array

protected processParamsRegex (string $string) : array

Converts parameter string to an array.

In: name="test" comment="This is a test" Out: ['name' => 'test', 'comment' => 'This is a test']

Parameters
Property Description
$string
string
Returns
array

protected processRepeaterTags (string $template) : array

Processes all repeating tags against a template, this will strip any repeaters from the template for further processing.

Parameters
Property Description
$template
string
Returns
array

protected processTags (string $template, array $usingTags = null) : array

Processes all registered tags against a template.

Parameters
Property Description
$template
string
$usingTags
array
Returns
array

protected processTagsRegex (string $string, array $tags) : array

Performs a regex looking for a field type (key) and returns an array where:

0 - The full tag definition, eg: {text name="test"}Foobar{/text} 1 - The opening and closing tag name 2 - The tag parameters as a string, eg: name="test"} and; 2 - The default text inside the tag (optional), eg: Foobar

Parameters
Property Description
$string
string
$tags
array
Returns
array

protected processTemplate (string $template) : void

Processes repeating tags first, then registered tags and assigns the results to local object properties.

Parameters
Property Description
$template
string
Returns
void
Copyright © 2024 Winter CMS