class PhpEngine implements EngineInterface, ArrayAccess

PhpEngine is an engine able to render PHP templates.

Properties

protected $loader
protected $current
protected HelperInterface[] $helpers
protected $parents
protected $stack
protected $charset
protected $cache
protected $escapers
static protected $escaperCache
protected $globals
protected $parser

Methods

__construct(TemplateNameParserInterface $parser, LoaderInterface $loader, array $helpers = array())

No description

string
render(string|TemplateReferenceInterface $name, array $parameters = array())

Renders a template.

bool
exists(string|TemplateReferenceInterface $name)

Returns true if the template exists.

bool
supports(string|TemplateReferenceInterface $name)

Returns true if this class is able to render the given template.

string|false
evaluate(Storage $template, array $parameters = array())

Evaluates a template.

offsetGet(string $name)

Gets a helper value.

bool
offsetExists(string $name)

Returns true if the helper is defined.

offsetSet(HelperInterface $name, string $value)

Sets a helper.

offsetUnset(string $name)

Removes a helper.

addHelpers(array $helpers)

Adds some helpers.

setHelpers(array $helpers)

Sets the helpers.

set(HelperInterface $helper, string $alias = null)

Sets a helper.

bool
has(string $name)

Returns true if the helper if defined.

get(string $name)

Gets a helper value.

extend(string $template)

Decorates the current template with another one.

string
escape(mixed $value, string $context = 'html')

Escapes a string by using the current charset.

setCharset(string $charset)

Sets the charset to use.

string
getCharset()

Gets the current charset.

setEscaper(string $context, callable $escaper)

Adds an escaper for the given context.

callable
getEscaper(string $context)

Gets an escaper for a given context.

addGlobal(string $name, mixed $value)

No description

array
getGlobals()

Returns the assigned globals.

initializeEscapers()

Initializes the built-in escapers.

string
convertEncoding(string $string, string $to, string $from) deprecated

Convert a string from one encoding to another.

getLoader()

Gets the loader associated with this engine.

load(string|TemplateReferenceInterface $name)

Loads the given template.

Details

at line 50
__construct(TemplateNameParserInterface $parser, LoaderInterface $loader, array $helpers = array())

Parameters

TemplateNameParserInterface $parser A TemplateNameParserInterface instance
LoaderInterface $loader A loader instance
array $helpers An array of helper instances

at line 68
string render(string|TemplateReferenceInterface $name, array $parameters = array())

Renders a template.

Parameters

string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance
array $parameters An array of parameters to pass to the template

Return Value

string The evaluated template as a string

Exceptions

RuntimeException if the template cannot be rendered

at line 99
bool exists(string|TemplateReferenceInterface $name)

Returns true if the template exists.

Parameters

string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance

Return Value

bool true if the template exists, false otherwise

Exceptions

RuntimeException if the engine cannot handle the template name

at line 113
bool supports(string|TemplateReferenceInterface $name)

Returns true if this class is able to render the given template.

Parameters

string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance

Return Value

bool true if this class supports the given template, false otherwise

at line 130
protected string|false evaluate(Storage $template, array $parameters = array())

Evaluates a template.

Parameters

Storage $template The template to render
array $parameters An array of parameters to pass to the template

Return Value

string|false The evaluated template, or false if the engine is unable to render the template

Exceptions

InvalidArgumentException

at line 179
HelperInterface offsetGet(string $name)

Gets a helper value.

Parameters

string $name The helper name

Return Value

HelperInterface The helper value

Exceptions

InvalidArgumentException if the helper is not defined

at line 191
bool offsetExists(string $name)

Returns true if the helper is defined.

Parameters

string $name The helper name

Return Value

bool true if the helper is defined, false otherwise

at line 202
offsetSet(HelperInterface $name, string $value)

Sets a helper.

Parameters

HelperInterface $name The helper instance
string $value An alias

at line 214
offsetUnset(string $name)

Removes a helper.

Parameters

string $name The helper name

Exceptions

LogicException

at line 224
addHelpers(array $helpers)

Adds some helpers.

Parameters

array $helpers An array of helper

at line 236
setHelpers(array $helpers)

Sets the helpers.

Parameters

array $helpers An array of helper

at line 248
set(HelperInterface $helper, string $alias = null)

Sets a helper.

Parameters

HelperInterface $helper The helper instance
string $alias An alias

at line 265
bool has(string $name)

Returns true if the helper if defined.

Parameters

string $name The helper name

Return Value

bool true if the helper is defined, false otherwise

at line 279
HelperInterface get(string $name)

Gets a helper value.

Parameters

string $name The helper name

Return Value

HelperInterface The helper instance

Exceptions

InvalidArgumentException if the helper is not defined

at line 293
extend(string $template)

Decorates the current template with another one.

Parameters

string $template The decorator logical name

at line 306
string escape(mixed $value, string $context = 'html')

Escapes a string by using the current charset.

Parameters

mixed $value A variable to escape
string $context The context name

Return Value

string The escaped value

at line 330
setCharset(string $charset)

Sets the charset to use.

Parameters

string $charset The charset

at line 347
string getCharset()

Gets the current charset.

Return Value

string The current charset

at line 358
setEscaper(string $context, callable $escaper)

Adds an escaper for the given context.

Parameters

string $context The escaper context (html, js, ...)
callable $escaper A PHP callable

at line 373
callable getEscaper(string $context)

Gets an escaper for a given context.

Parameters

string $context The context name

Return Value

callable $escaper A PHP callable

Exceptions

InvalidArgumentException

at line 386
addGlobal(string $name, mixed $value)

Parameters

string $name
mixed $value

at line 396
array getGlobals()

Returns the assigned globals.

Return Value

array

at line 418
protected initializeEscapers()

Initializes the built-in escapers.

Each function specifies a way for applying a transformation to a string passed to it. The purpose is for the string to be "escaped" so it is suitable for the format it is being displayed in.

For example, the string: "It's required that you enter a username & password.\n" If this were to be displayed as HTML it would be sensible to turn the ampersand into '&' and the apostrophe into '&aps;'. However if it were going to be used as a string in JavaScript to be displayed in an alert box it would be right to leave the string as-is, but c-escape the apostrophe and the new line.

For each function there is a define to avoid problems with strings being incorrectly specified.

at line 496
string convertEncoding(string $string, string $to, string $from) deprecated

deprecated since 2.8, to be removed in 3.0. Use iconv() instead.

Convert a string from one encoding to another.

Parameters

string $string The string to convert
string $to The input encoding
string $from The output encoding

Return Value

string The string with the new encoding

at line 508
LoaderInterface getLoader()

Gets the loader associated with this engine.

Return Value

LoaderInterface A LoaderInterface instance

at line 522
protected Storage load(string|TemplateReferenceInterface $name)

Loads the given template.

Parameters

string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance

Return Value

Storage A Storage instance

Exceptions

InvalidArgumentException if the template cannot be found