SectionParser
in package
This class parses CMS object files (pages, partials and layouts).
Returns the structured file information.
Tags
Table of Contents
- ERROR_INI = '_PARSER_ERROR_INI'
- SECTION_SEPARATOR = '=='
- parse() : array<string|int, mixed>
- Parses a CMS object file content.
- parseOffset() : array<string|int, mixed>
- Same as parse method, except the line number where the respective section begins is returned.
- render() : string
- Renders a CMS object as file content.
- adjustLinePosition() : int
- Pushes the starting line number forward since it is not always directly after the separator (==). There can be an opening tag or white space in between where the section really begins.
- calculateLinePosition() : int
- Returns the line number of a found instance of CMS object section separator (==).
Constants
ERROR_INI
public
mixed
ERROR_INI
= '_PARSER_ERROR_INI'
SECTION_SEPARATOR
public
mixed
SECTION_SEPARATOR
= '=='
Methods
parse()
Parses a CMS object file content.
public
static parse(string $content[, mixed $options = [] ]) : array<string|int, mixed>
The expected file format is following:
INI settings section == PHP code section == Twig markup section
If the content has only 2 sections they are considered as settings and Twig. If there is only a single section, it is considered as Twig.
Parameters
- $content : string
-
Specifies the file content.
- $options : mixed = []
Return values
array<string|int, mixed> —Returns an array with the following indexes: 'settings', 'markup', 'code'. The 'markup' and 'code' elements contain strings. The 'settings' element contains the parsed INI file as array. If the content string doesn't contain a section, the corresponding result element has null value.
parseOffset()
Same as parse method, except the line number where the respective section begins is returned.
public
static parseOffset(string $content) : array<string|int, mixed>
Parameters
- $content : string
-
Specifies the file content.
Return values
array<string|int, mixed> —Returns an array with the following indexes: 'settings', 'markup', 'code'.
render()
Renders a CMS object as file content.
public
static render(mixed $data[, mixed $options = [] ]) : string
Parameters
- $data : mixed
- $options : mixed = []
Return values
string —adjustLinePosition()
Pushes the starting line number forward since it is not always directly after the separator (==). There can be an opening tag or white space in between where the section really begins.
private
static adjustLinePosition(string $content[, int $startLine = -1 ]) : int
Parameters
- $content : string
-
Object content
- $startLine : int = -1
-
The calculated starting line from calculateLinePosition()
Return values
int —The adjusted line number.
calculateLinePosition()
Returns the line number of a found instance of CMS object section separator (==).
private
static calculateLinePosition(string $content[, int $instance = 1 ]) : int
Parameters
- $content : string
-
Object content
- $instance : int = 1
-
Which instance to look for
Return values
int —The line number the instance was found.