class PhpEngine implements EngineInterface, ArrayAccess
PhpEngine is an engine able to render PHP templates.
protected | $loader | ||
protected | $current | ||
protected HelperInterface[] | $helpers | ||
protected | $parents | ||
protected | $stack | ||
protected | $charset | ||
protected | $cache | ||
protected | $escapers | ||
static protected | $escaperCache | ||
protected | $globals | ||
protected | $parser |
__construct(TemplateNameParserInterface $parser, LoaderInterface $loader, array $helpers = array()) | ||
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. | |
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, 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) | ||
array | getGlobals() Returns the assigned globals. | |
initializeEscapers() Initializes the built-in escapers. | ||
LoaderInterface | getLoader() Gets the loader associated with this engine. | |
Storage | load(string|TemplateReferenceInterface $name) Loads the given template. |
TemplateNameParserInterface | $parser | A TemplateNameParserInterface instance |
LoaderInterface | $loader | A loader instance |
array | $helpers | An array of helper instances |
Renders a template.
string|TemplateReferenceInterface | $name | A template name or a TemplateReferenceInterface instance |
array | $parameters | An array of parameters to pass to the template |
string | The evaluated template as a string |
RuntimeException | if the template cannot be rendered |
Returns true if the template exists.
string|TemplateReferenceInterface | $name | A template name or a TemplateReferenceInterface instance |
bool | true if the template exists, false otherwise |
RuntimeException | if the engine cannot handle the template name |
Returns true if this class is able to render the given template.
string|TemplateReferenceInterface | $name | A template name or a TemplateReferenceInterface instance |
bool | true if this class supports the given template, false otherwise |
Evaluates a template.
Storage | $template | The template to render |
array | $parameters | An array of parameters to pass to the template |
string|false | The evaluated template, or false if the engine is unable to render the template |
InvalidArgumentException |
Gets a helper value.
string | $name | The helper name |
HelperInterface | The helper value |
InvalidArgumentException | if the helper is not defined |
Returns true if the helper is defined.
string | $name | The helper name |
bool | true if the helper is defined, false otherwise |
Sets a helper.
HelperInterface | $name | The helper instance |
string | $value | An alias |
Removes a helper.
string | $name | The helper name |
LogicException |
Adds some helpers.
array | $helpers | An array of helper |
Sets the helpers.
array | $helpers | An array of helper |
Sets a helper.
HelperInterface | $helper | The helper instance |
string | $alias | An alias |
Returns true if the helper if defined.
string | $name | The helper name |
bool | true if the helper is defined, false otherwise |
Gets a helper value.
string | $name | The helper name |
HelperInterface | The helper instance |
InvalidArgumentException | if the helper is not defined |
Decorates the current template with another one.
string | $template | The decorator logical name |
Escapes a string by using the current charset.
mixed | $value | A variable to escape |
string | $context | The context name |
string | The escaped value |
Sets the charset to use.
string | $charset | The charset |
Gets the current charset.
string | The current charset |
Adds an escaper for the given context.
string | $context | The escaper context (html, js, ...) |
callable | $escaper | A PHP callable |
Gets an escaper for a given context.
string | $context | The context name |
callable | $escaper A PHP callable |
InvalidArgumentException |
string | $name | |
mixed | $value |
Returns the assigned globals.
array |
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.
Gets the loader associated with this engine.
LoaderInterface | A LoaderInterface instance |
Loads the given template.
string|TemplateReferenceInterface | $name | A template name or a TemplateReferenceInterface instance |
Storage | A Storage instance |
InvalidArgumentException | if the template cannot be found |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/Templating/PhpEngine.html