W3cubDocs

/Symfony 2.7

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(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.

HelperInterface 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.

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

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

public 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

public 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

public 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

public 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

public 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

public offsetSet(HelperInterface $name, string $value)

Sets a helper.

Parameters

HelperInterface $name The helper instance
string $value An alias

public offsetUnset(string $name)

Removes a helper.

Parameters

string $name The helper name

Exceptions

LogicException

public addHelpers(array $helpers)

Adds some helpers.

Parameters

array $helpers An array of helper

public setHelpers(array $helpers)

Sets the helpers.

Parameters

array $helpers An array of helper

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

Sets a helper.

Parameters

HelperInterface $helper The helper instance
string $alias An alias

public 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

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

public extend(string $template)

Decorates the current template with another one.

Parameters

string $template The decorator logical name

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

public setCharset(string $charset)

Sets the charset to use.

Parameters

string $charset The charset

public string getCharset()

Gets the current charset.

Return Value

string The current charset

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

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

Exceptions

InvalidArgumentException

public addGlobal(string $name, mixed $value)

Parameters

string $name
mixed $value

public array getGlobals()

Returns the assigned globals.

Return Value

array

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)

public LoaderInterface getLoader()

Gets the loader associated with this engine.

Return Value

LoaderInterface A LoaderInterface instance

© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.7/Symfony/Component/Templating/PhpEngine.html