October\Rain\Parse\Syntax\FieldParser
Overview
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 __construct()
public __construct(string $template = null, $options = []): void
Constructor
public getDefaultParams()
public getDefaultParams(array $fields = null): array
Returns default values for all fields.
public getFieldParams()
public getFieldParams(string $field): array
Returns defined parameters for a single field
public getFieldTags()
public getFieldTags(string $field): array
Returns tag strings for a specific field
public getFields()
public getFields(): array
Returns all field definitions found in the template
public getTags()
public getTags(): array
Returns all tag strings found in the template
public static parse()
public static parse(
string $template,
array $options = []
): FieldParser
Static helper for new instances of this class.
Protected Methods
protected processOptionsToArray()
protected processOptionsToArray(string $optionsString): array
Splits an option string to an array.
one|two -> [one, two] one:One|two:Two -> [one => 'One', two => 'Two'] ClassName::method -> [...]
protected processParams()
protected processParams(string $value, string $tagName): array
Processes group 2 from the Tag regex and returns an array of captured parameters.
protected processParamsRegex()
protected processParamsRegex(string $string): array
processParamsRegex converts parameter string to an array.
In: name="test" comment="This is a test" Out: ['name' => 'test', 'comment' => 'This is a test']
protected processRepeaterTags()
protected processRepeaterTags(string $template): void
Processes all repeating tags against a template, this will strip any repeaters from the template for further processing.
protected processTags()
protected processTags(string $template, bool $usingTags = null): void
Processes all registered tags against a template.
protected processTagsRegex()
protected processTagsRegex(string $string, string $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
protected processTemplate()
protected processTemplate($template): void
Processes repeating tags first, then registered tags and assigns the results to local object properties.