SectionParser

This class parses CMS object files (pages, partials and layouts).

 class Winter\Storm\Halcyon\Processors\SectionParser

Returns the structured file information.

Constants

Constant Description
ERROR_INI
string "_PARSER_ERROR_INI"
SECTION_SEPARATOR
string "=="

Methods

public static parse (string $content, array $options = []) : array

Parses Halcyon section content.

The expected file format is following:

INI settings section
==
PHP code section
==
Twig markup section

If the content has only 2 sections they are parsed as settings and markup. If there is only a single section, it is parsed as markup.

Returns an array with the following elements: (array|null) 'settings', (string|null) 'markup', (string|null) 'code'.

Parameters
Property Description
$content
string
$options
array
Returns
array

public static parseCode (string $code) : string

Processes the Code section into a usable form

Parameters
Property Description
$code
string
Returns
string

public static parseMarkup (string $markup) : string

Processes the Markup section into a usable form

Parameters
Property Description
$markup
string
Returns
string

public static parseOffset (string $content) : array

Same as parse method, except the line number where the respective section begins is returned.

Returns an array with the following elements: (integer|null) 'settings', (integer|null) 'markup', (integer|null) 'code'.

Parameters
Property Description
$content
string
Returns
array

public static parseSettings (string $settings) : array

Parses the Settings section into an array

Parameters
Property Description
$settings
string
Returns
array

public static render (array $data, array $options = []) : string

Renders a CMS object as file content.

Parameters
Property Description
$data
array
$options
array
Returns
string

public static renderCode (string $code, array $options = []) : string

Renders the provided string into a string that can be stored in the Code section

Parameters
Property Description
$code
string
$options
array
Returns
string

public static renderMarkup (string $markup) : string

Renders the provided string into a string that can be stored in the Markup section

Parameters
Property Description
$markup
string
Returns
string

public static renderSettings (array $data) : string

Renders the provided settings data into a string that can be stored in the Settings section

Parameters
Property Description
$data
array
Returns
string

protected static adjustLinePosition (string $content, integer $startLine = -1) : integer

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.

Parameters
Property Description
$content
string
$startLine
integer
Returns
integer

protected static calculateLinePosition (string $content, integer $instance = 1) : integer | null

Returns the line number of a found instance of CMS object section separator (==).

Parameters
Property Description
$content
string

Object content

$instance
integer

Which instance to look for

Returns
integer | null

The line number the instance was found.

protected static parseIntoSections (string $content, integer $limit = 3) : array

Parse the provided content into sections

Parameters
Property Description
$content
string
$limit
integer
Returns
array
Copyright © 2024 Winter CMS