class FrontMatter (View source)

Component for parsing front matter from a source.

This component allows for an easy and convenient way to parse

Constants

SEPARATOR

The separator used to indicate front matter data.

REGEXP

The regular expression used to extract the YAML front matter content.

Properties

protected array $parsed

The parsed source.

protected string $serializer

A serializer.

protected string $source

The source.

Methods

__construct(string $source, string $serializer = '\\Drupal\\Component\\Serialization\\Yaml')

FrontMatter constructor.

static FrontMatter
create(string $source, string $serializer = '\\Drupal\\Component\\Serialization\\Yaml')

Creates a new FrontMatter instance.

array
parse()

Parses the source.

string
getContent()

Retrieves the extracted source content.

array
getData()

Retrieves the extracted front matter data.

int
getLine()

Retrieves the line where the source content starts, after any data.

Details

__construct(string $source, string $serializer = '\\Drupal\\Component\\Serialization\\Yaml')

FrontMatter constructor.

Parameters

string $source

A string source.

string $serializer

The name of a class that implements \Drupal\Component\Serialization\SerializationInterface.

static FrontMatter create(string $source, string $serializer = '\\Drupal\\Component\\Serialization\\Yaml')

Creates a new FrontMatter instance.

Parameters

string $source

A string source.

string $serializer

The name of a class that implements \Drupal\Component\Serialization\SerializationInterface.

Return Value

FrontMatter

protected array parse()

Parses the source.

Return Value

array

An associative array containing:

  • content: The real content.
  • data: The front matter data extracted and decoded.
  • line: The line number where the real content starts.

Exceptions

FrontMatterParseException

string getContent()

Retrieves the extracted source content.

Return Value

string

The extracted source content.

Exceptions

FrontMatterParseException

array getData()

Retrieves the extracted front matter data.

Return Value

array

The extracted front matter data.

Exceptions

FrontMatterParseException

int getLine()

Retrieves the line where the source content starts, after any data.

Return Value

int

The source content line.

Exceptions

FrontMatterParseException