W3cubDocs

/Symfony 4.1

TimedPhpEngine

class TimedPhpEngine extends PhpEngine

Times the time spent to render a template.

Properties

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

Methods

__construct(TemplateNameParserInterface $parser, ContainerInterface $container, LoaderInterface $loader, Stopwatch $stopwatch, GlobalVariables $globals = null)
string render(string|TemplateReferenceInterface $name, array $parameters = array())

Renders a template.

bool exists(string|TemplateReferenceInterface $name)

Returns true if the template exists.

from PhpEngine
bool supports(string|TemplateReferenceInterface $name)

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

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

Evaluates a template.

from PhpEngine
HelperInterface offsetGet(string $name)

Gets a helper value.

from PhpEngine
bool offsetExists(string $name)

Returns true if the helper is defined.

from PhpEngine
offsetSet(HelperInterface $name, string $value)

Sets a helper.

from PhpEngine
offsetUnset(string $name)

Removes a helper.

from PhpEngine
addHelpers(array $helpers)

Adds some helpers.

from PhpEngine
setHelpers(array $helpers)

Sets the helpers.

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

Sets a helper.

from PhpEngine
bool has(string $name)

Returns true if the helper if defined.

from PhpEngine
HelperInterface get(string $name)

Gets a helper value.

from PhpEngine
extend(string $template)

Decorates the current template with another one.

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

Escapes a string by using the current charset.

from PhpEngine
setCharset(string $charset)

Sets the charset to use.

from PhpEngine
string getCharset()

Gets the current charset.

from PhpEngine
setEscaper(string $context, callable $escaper)

Adds an escaper for the given context.

from PhpEngine
callable getEscaper(string $context)

Gets an escaper for a given context.

from PhpEngine
addGlobal(string $name, mixed $value) from PhpEngine
array getGlobals()

Returns the assigned globals.

from PhpEngine
initializeEscapers()

Initializes the built-in escapers.

from PhpEngine
LoaderInterface getLoader()

Gets the loader associated with this engine.

from PhpEngine
Storage load(string|TemplateReferenceInterface $name)

Loads the given template.

from PhpEngine
Response renderResponse(string $view, array $parameters = array(), Response $response = null)

Renders a view and returns a Response.

from PhpEngine

Details

__construct(TemplateNameParserInterface $parser, ContainerInterface $container, LoaderInterface $loader, Stopwatch $stopwatch, GlobalVariables $globals = null)

Parameters

TemplateNameParserInterface $parser A TemplateNameParserInterface instance
ContainerInterface $container
LoaderInterface $loader A loader instance
Stopwatch $stopwatch
GlobalVariables $globals

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

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

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

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

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

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

offsetSet(HelperInterface $name, string $value)

Sets a helper.

Parameters

HelperInterface $name The helper instance
string $value An alias

offsetUnset(string $name)

Removes a helper.

Parameters

string $name The helper name

Exceptions

LogicException

addHelpers(array $helpers)

Adds some helpers.

Parameters

array $helpers An array of helper

setHelpers(array $helpers)

Sets the helpers.

Parameters

array $helpers An array of helper

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

Sets a helper.

Parameters

HelperInterface $helper The helper instance
string $alias An alias

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

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

extend(string $template)

Decorates the current template with another one.

Parameters

string $template The decorator logical name

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

setCharset(string $charset)

Sets the charset to use.

Parameters

string $charset The charset

string getCharset()

Gets the current charset.

Return Value

string The current charset

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

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

addGlobal(string $name, mixed $value)

Parameters

string $name
mixed $value

array getGlobals()

Returns the assigned globals.

Return Value

array

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.

LoaderInterface getLoader()

Gets the loader associated with this engine.

Return Value

LoaderInterface A LoaderInterface instance

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

Response renderResponse(string $view, array $parameters = array(), Response $response = null)

Renders a view and returns a Response.

Parameters

string $view The view name
array $parameters An array of parameters to pass to the view
Response $response A Response instance

Return Value

Response A Response instance

Exceptions

RuntimeException if the template cannot be rendered

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Bundle/FrameworkBundle/Templating/TimedPhpEngine.html