Class

Symfony\Component\Templating\PhpEngine

class PhpEngine implements EngineInterface, ArrayAccess

PhpEngine is an engine able to render PHP templates.

Methods

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

Constructor.

string render(mixed $name, array $parameters = array())

Renders a template.

Boolean exists(mixed $name)

Returns true if the template exists.

Boolean supports(mixed $name)

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

mixed offsetGet(string $name)

Gets a helper value.

Boolean 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)

setHelpers(array $helpers)

Sets the helpers.

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

Sets a helper.

Boolean has(string $name)

Returns true if the helper if defined.

HelperInterface 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, mixed $escaper)

Adds an escaper for the given context.

mixed getEscaper(string $context)

Gets an escaper for a given context.

addGlobal(string $name, mixed $value)

array getGlobals()

Returns the assigned globals.

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

Convert a string from one encoding to another.

LoaderInterface getLoader()

Gets the loader associated with this engine.

Details

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

Constructor.

Parameters

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

at line 78
public string render(mixed $name, array $parameters = array())

Renders a template.

Parameters

mixed $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

InvalidArgumentException if the template does not exist
RuntimeException if the template cannot be rendered

at line 115
public Boolean exists(mixed $name)

Returns true if the template exists.

Parameters

mixed $name A template name or a TemplateReferenceInterface instance

Return Value

Boolean true if the template exists, false otherwise

at line 135
public Boolean supports(mixed $name)

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

Parameters

mixed $name A template name or a TemplateReferenceInterface instance

Return Value

Boolean true if this class supports the given resource, false otherwise

at line 188
public mixed offsetGet(string $name)

Gets a helper value.

Parameters

string $name The helper name

Return Value

mixed The helper value

Exceptions

InvalidArgumentException if the helper is not defined

at line 202
public Boolean offsetExists(string $name)

Returns true if the helper is defined.

Parameters

string $name The helper name

Return Value

Boolean true if the helper is defined, false otherwise

at line 215
public offsetSet(HelperInterface $name, string $value)

Sets a helper.

Parameters

HelperInterface $name The helper instance
string $value An alias

at line 227
public offsetUnset(string $name)

Removes a helper.

Parameters

string $name The helper name

at line 237
public addHelpers(array $helpers)

Parameters

array $helpers An array of helper

at line 251
public setHelpers(array $helpers)

Sets the helpers.

Parameters

array $helpers An array of helper

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

Sets a helper.

Parameters

HelperInterface $helper The helper instance
string $alias An alias

at line 284
public Boolean has(string $name)

Returns true if the helper if defined.

Parameters

string $name The helper name

Return Value

Boolean true if the helper is defined, false otherwise

at line 300
public 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 316
public extend(string $template)

Decorates the current template with another one.

Parameters

string $template The decorator logical name

at line 331
public 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 343
public setCharset(string $charset)

Sets the charset to use.

Parameters

string $charset The charset

at line 355
public string getCharset()

Gets the current charset.

Return Value

string The current charset

at line 368
public setEscaper(string $context, mixed $escaper)

Adds an escaper for the given context.

Parameters

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

at line 382
public mixed getEscaper(string $context)

Gets an escaper for a given context.

Parameters

string $context The context name

Return Value

mixed $escaper A PHP callable

at line 397
public addGlobal(string $name, mixed $value)

Parameters

string $name
mixed $value

at line 409
public array getGlobals()

Returns the assigned globals.

Return Value

array

at line 501
public string convertEncoding(string $string, string $to, string $from)

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

Exceptions

RuntimeException if no suitable encoding function is found (iconv or mbstring)

at line 517
public LoaderInterface getLoader()

Gets the loader associated with this engine.

Return Value

LoaderInterface A LoaderInterface instance