API Documentation

BladeMatterParser
in package

Tags
experimental

Parse the front matter in a Blade file.

Accepts a string to make it easier to mock when testing.

phpstan-consistent-constructor

=== DOCUMENTATION (draft) ===

Front Matter in Markdown

HydePHP uses a special syntax called BladeMatter that allows you to define variables in a Blade file, and have Hyde statically parse them into the front matter of the page model. This allows metadata in your Blade pages to be used when Hyde generates dynamic data like page titles and SEO tags.

Syntax

Any line following the syntax below will be added to the parsed page object's front matter.

example

@php($title = 'BladeMatter Test') This would then be parsed into the following array in the page model: ['title' => 'BladeMatter Test']

Limitations

Each directive must be on its own line, and start with @php($.. Arrays are currently not supported.

Table of Contents

Constants

SEARCH  = '@php($'

Properties

$contents  : string
$matter  : array<string|int, mixed>

Methods

__construct()  : mixed
get()  : array<string|int, mixed>
parse()  : static
parseFile()  : array<string|int, mixed>
parseString()  : array<string|int, mixed>
extractKey()  : string
extractValue()  : string
getValueWithType()  : scalar|array<string, scalar>
isValueArrayString()  : bool
lineMatchesFrontMatter()  : bool
parseArrayString()  : array<string, scalar>

Constants

protected string SEARCH = '@php($'

The directive signature used to determine if a line should be parsed.

Properties

Methods

__construct()

public __construct(string $contents) : mixed
Parameters
$contents : string

get()

public get() : array<string|int, mixed>
Return values
array<string|int, mixed>

parseFile()

public static parseFile(string $path) : array<string|int, mixed>
Parameters
$path : string
Return values
array<string|int, mixed>

parseString()

public static parseString(string $contents) : array<string|int, mixed>
Parameters
$contents : string
Return values
array<string|int, mixed>

extractKey()

protected static extractKey(string $line) : string
Parameters
$line : string
Return values
string

extractValue()

protected static extractValue(string $line) : string
Parameters
$line : string
Return values
string

getValueWithType()

protected static getValueWithType(string $value) : scalar|array<string, scalar>
Parameters
$value : string
Return values
scalar|array<string, scalar>

isValueArrayString()

protected static isValueArrayString(string $string) : bool
Parameters
$string : string
Return values
bool

lineMatchesFrontMatter()

protected static lineMatchesFrontMatter(string $line) : bool
Parameters
$line : string
Return values
bool

parseArrayString()

protected static parseArrayString(string $string) : array<string, scalar>
Parameters
$string : string
Return values
array<string, scalar>

        
On this page

Search results