Documentation

HtmlTemplate
in package
Uses ActionMessages

Template class

Tags
author

Dodonov A.A.

Table of Contents

$blocks  : array<string, string>
Page blocks
$pageVars  : array<string, string|array|object|mixed>
Page variables
$paths  : array<string|int, string>
Path to the template folder
$resources  : TemplateResources|null
Loaded resources
$template  : string
Loaded template content
__construct()  : mixed
Template сonstructor
addBlock()  : void
Method adds block to page
addPaths()  : void
Method adds paths to the setup ones
blockExists()  : bool
Does block exist
compile()  : string
Compile template
compilePageVars()  : void
Compiling the page with it's variables
fileExists()  : bool
Checking if the file exists
getBlock()  : string
Method returns block's content
getErrorMessageCode()  : string
Method returns error message code
getFile()  : string
Method returns file data
getPageVar()  : mixed
Getting page var
getPaths()  : array<string|int, mixed>
Method returns all setup puths of the template
getSuccessMessageCode()  : string
Method returns success message code
pageVarExists()  : bool
Checking that var exists
resetLayout()  : void
Method resets layout
setErrorMessage()  : void
Method sets error message variable
setPageVar()  : void
Setting page variables
setPageVarFromBlock()  : void
Setting page variables from block
setPageVarFromFile()  : void
Setting page variables from file's content
setPageVars()  : void
Method sets multiple variables
setPaths()  : void
Resetting paths
setResources()  : void
Method sets template resources
setSuccessMessage()  : void
Method sets success message variable
fileGetContents()  : string
Getting content of the file
getErrorMessageContent()  : string
Method sets error action message
getJoinedJsonFilesData()  : array<string, string>
Method reads all files $fileName found in $this->paths and joins them
getSuccessMessageContent()  : string
Method sets success action message
readBlock()  : string
Method returns block's content
getActionMessage()  : string
Method returns localized error message by it's key

Properties

$blocks

Page blocks

private array<string, string> $blocks = []

$pageVars

Page variables

private array<string, string|array|object|mixed> $pageVars = []

$paths

Path to the template folder

private array<string|int, string> $paths = []

$template

Loaded template content

private string $template = ''

Methods

__construct()

Template сonstructor

public __construct(string|array<string|int, string>|mixed $path[, string $template = 'index' ][, array<string|int, mixed> $blocks = [] ]) : mixed
Parameters
$path : string|array<string|int, string>|mixed

path to template

$template : string = 'index'

page layout

$blocks : array<string|int, mixed> = []

page blocks

Return values
mixed

addBlock()

Method adds block to page

public addBlock(string $blockName) : void
Parameters
$blockName : string

name of the additing block

Return values
void

addPaths()

Method adds paths to the setup ones

public addPaths(array<string|int, string> $paths) : void
Parameters
$paths : array<string|int, string>

paths to directories with the template's static content

Return values
void

blockExists()

Does block exist

public blockExists(string $blockName) : bool
Parameters
$blockName : string

block name

Return values
bool

does block exist?

compile()

Compile template

public compile() : string
Return values
string

compiled template

compilePageVars()

Compiling the page with it's variables

public compilePageVars(string &$content) : void
Parameters
$content : string

compiling content

Return values
void

fileExists()

Checking if the file exists

public fileExists(string $fileSubPath) : bool
Parameters
$fileSubPath : string

file sub path

Return values
bool

true if the file exists, false otherwise

getBlock()

Method returns block's content

public getBlock(string $blockName) : string
Parameters
$blockName : string
Return values
string

block's content

getErrorMessageCode()

Method returns error message code

public static getErrorMessageCode() : string
Return values
string

error message code

getFile()

Method returns file data

public getFile(string $filePath) : string
Parameters
$filePath : string

path to file

Return values
string

file content

getPageVar()

Getting page var

public getPageVar(string $var) : mixed
Parameters
$var : string

variable name

Return values
mixed

variable value, or exception if the variable was not found

getPaths()

Method returns all setup puths of the template

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

getSuccessMessageCode()

Method returns success message code

public static getSuccessMessageCode() : string
Return values
string

success message code

pageVarExists()

Checking that var exists

public pageVarExists(string $var) : bool
Parameters
$var : string

page var name

Return values
bool

true if the page var exists, false otherwise

resetLayout()

Method resets layout

public resetLayout(string $template) : void
Parameters
$template : string

template name

Return values
void

setErrorMessage()

Method sets error message variable

public setErrorMessage(string $errorMessageLocator) : void
Parameters
$errorMessageLocator : string

message locator

Tags
note

This method should be overriden

Return values
void

setPageVar()

Setting page variables

public setPageVar(string $var, mixed $value) : void
Parameters
$var : string

variable name

$value : mixed

variable value

Return values
void

setPageVarFromBlock()

Setting page variables from block

public setPageVarFromBlock(string $var, string $blockName) : void
Parameters
$var : string

variable name

$blockName : string

block name

Return values
void

setPageVarFromFile()

Setting page variables from file's content

public setPageVarFromFile(string $var, string $path) : void
Parameters
$var : string

variable name

$path : string

path to file

Return values
void

setPageVars()

Method sets multiple variables

public setPageVars(array<string, mixed> $vars) : void
Parameters
$vars : array<string, mixed>

variables

Tags
psalm-suppress

MixedArgumentTypeCoercion, MixedAssignment

Return values
void

setPaths()

Resetting paths

public setPaths(array<string|int, string> $paths) : void
Parameters
$paths : array<string|int, string>
Return values
void

setSuccessMessage()

Method sets success message variable

public setSuccessMessage(string $successMessageLocator) : void
Parameters
$successMessageLocator : string

message locator

Tags
note

This method should be overriden

Return values
void

fileGetContents()

Getting content of the file

protected fileGetContents(string $fileSubPath) : string
Parameters
$fileSubPath : string

file sub path

Return values
string

file content

getErrorMessageContent()

Method sets error action message

protected getErrorMessageContent(string $errorMessage) : string
Parameters
$errorMessage : string

error message

Return values
string

compiled error message

getJoinedJsonFilesData()

Method reads all files $fileName found in $this->paths and joins them

protected getJoinedJsonFilesData(string $fileName) : array<string, string>
Parameters
$fileName : string

file name to be fetched

Return values
array<string, string>

compound JSON object as assoc array

getSuccessMessageContent()

Method sets success action message

protected getSuccessMessageContent(string $successMessage) : string
Parameters
$successMessage : string

success message

Return values
string

compiled success message

readBlock()

Method returns block's content

protected readBlock(string $blockName) : string
Parameters
$blockName : string
Return values
string

block's content

getActionMessage()

Method returns localized error message by it's key

private getActionMessage(string $actionMessageCode) : string
Parameters
$actionMessageCode : string

key of the message

Return values
string

localized error message by it's key

Search results