FieldParser
in package
Dynamic Syntax parser
Table of Contents
- $fields : array<string|int, mixed>
- $registeredTags : array<string|int, mixed>
- $tagPrefix : string
- $tags : array<string|int, mixed>
- $template : string
- __construct() : mixed
- Constructor
- getDefaultParams() : array<string|int, mixed>
- Returns default values for all fields.
- getFieldParams() : array<string|int, mixed>
- Returns defined parameters for a single field
- getFields() : array<string|int, mixed>
- Returns all field definitions found in the template
- getFieldTags() : array<string|int, mixed>
- Returns tag strings for a specific field
- getTags() : array<string|int, mixed>
- Returns all tag strings found in the template
- parse() : FieldParser
- Static helper for new instances of this class.
- processOptionsToArray() : array<string|int, mixed>
- Splits an option string to an array.
- processParams() : array<string|int, mixed>
- Processes group 2 from the Tag regex and returns an array of captured parameters.
- processParamsRegex() : mixed
- Converts parameter string to an array.
- processRepeaterTags() : void
- Processes all repeating tags against a template, this will strip any repeaters from the template for further processing.
- processTags() : void
- Processes all registered tags against a template.
- processTagsRegex() : array<string|int, mixed>
- Performs a regex looking for a field type (key) and returns an array where:
- processTemplate() : void
- Processes repeating tags first, then registered tags and assigns the results to local object properties.
Properties
$fields
protected
array<string|int, mixed>
$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
$registeredTags
protected
array<string|int, mixed>
$registeredTags
= ['text', 'textarea', 'richeditor', 'markdown', 'fileupload', 'mediafinder', 'dropdown', 'radio', 'checkbox', 'checkboxlist', 'datepicker', 'balloon-selector', 'repeater', 'variable']
Registered template tags
$tagPrefix
protected
string
$tagPrefix
= ''
A prefix to place before all tag references eg: {namespace:text}{/namespace:text}
$tags
protected
array<string|int, mixed>
$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}
$template
protected
string
$template
= ''
Template contents
Methods
__construct()
Constructor
public
__construct([string $template = null ][, mixed $options = [] ]) : mixed
Parameters
- $template : string = null
-
Template to parse.
- $options : mixed = []
Return values
mixed —getDefaultParams()
Returns default values for all fields.
public
getDefaultParams([array<string|int, mixed> $fields = null ]) : array<string|int, mixed>
Parameters
- $fields : array<string|int, mixed> = null
Return values
array<string|int, mixed> —getFieldParams()
Returns defined parameters for a single field
public
getFieldParams(string $field) : array<string|int, mixed>
Parameters
- $field : string
Return values
array<string|int, mixed> —getFields()
Returns all field definitions found in the template
public
getFields() : array<string|int, mixed>
Return values
array<string|int, mixed> —getFieldTags()
Returns tag strings for a specific field
public
getFieldTags(string $field) : array<string|int, mixed>
Parameters
- $field : string
Return values
array<string|int, mixed> —getTags()
Returns all tag strings found in the template
public
getTags() : array<string|int, mixed>
Return values
array<string|int, mixed> —parse()
Static helper for new instances of this class.
public
static parse(string $template[, array<string|int, mixed> $options = [] ]) : FieldParser
Parameters
- $template : string
- $options : array<string|int, mixed> = []
Return values
FieldParser —processOptionsToArray()
Splits an option string to an array.
protected
processOptionsToArray(string $optionsString) : array<string|int, mixed>
one|two -> [one, two] one:One|two:Two -> [one => 'One', two => 'Two']
Parameters
- $optionsString : string
Return values
array<string|int, mixed> —processParams()
Processes group 2 from the Tag regex and returns an array of captured parameters.
protected
processParams(string $value, string $tagName) : array<string|int, mixed>
Parameters
- $value : string
- $tagName : string
Return values
array<string|int, mixed> —processParamsRegex()
Converts parameter string to an array.
protected
processParamsRegex(mixed $string) : mixed
In: name="test" comment="This is a test" Out: ['name' => 'test', 'comment' => 'This is a test']
Parameters
- $string : mixed
Return values
mixed —processRepeaterTags()
Processes all repeating tags against a template, this will strip any repeaters from the template for further processing.
protected
processRepeaterTags(string $template) : void
Parameters
- $template : string
Return values
void —processTags()
Processes all registered tags against a template.
protected
processTags(string $template[, bool $usingTags = null ]) : void
Parameters
- $template : string
- $usingTags : bool = null
Return values
void —processTagsRegex()
Performs a regex looking for a field type (key) and returns an array where:
protected
processTagsRegex(string $string, string $tags) : array<string|int, mixed>
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
- $tags : string
Return values
array<string|int, mixed> —processTemplate()
Processes repeating tags first, then registered tags and assigns the results to local object properties.
protected
processTemplate(mixed $template) : void
Parameters
- $template : mixed