October\Rain\Parse\Syntax\FieldParser

FieldParser for dynamic syntax parser

Protected properties

protected string $template

Template contents

protected array $fields

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 array $tags

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 string $tagPrefix

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

protected array $registeredTags

Registered template tags

Public methods

public void __construct(string $template=NULL, $options=array())

Constructor

Parameters
  • string $template - Template to parse.
  • $options

public array getDefaultParams(array $fields=NULL)

Returns default values for all fields.

Parameters
  • array $fields

public array getFieldParams(string $field)

Returns defined parameters for a single field

Parameters
  • string $field

public array getFieldTags(string $field)

Returns tag strings for a specific field

Parameters
  • string $field

public array getFields()

Returns all field definitions found in the template

public array getTags()

Returns all tag strings found in the template

public static FieldParser parse(string $template, array $options=array())

Static helper for new instances of this class.

Parameters
  • string $template
  • array $options

Protected methods

protected array processOptionsToArray(string $optionsString)

Splits an option string to an array.

one|two -> [one, two] one:One|two:Two -> [one => 'One', two => 'Two'] ClassName::method -> [...]

Parameters
  • string $optionsString

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

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

Parameters
  • string $value
  • string $tagName

protected array processParamsRegex(string $string)

Converts parameter string to an array.

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

Parameters
  • string $string

protected void processRepeaterTags(string $template)

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

Parameters
  • string $template

protected void processTags(string $template, bool $usingTags=NULL)

Processes all registered tags against a template.

Parameters
  • string $template
  • bool $usingTags

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

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
  • string $string
  • string $tags

protected void processTemplate($template)

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

Parameters
  • $template