ArrayLoader

Implements\Twig\Loader\LoaderInterface, \Twig\Loader\ExistsLoaderInterface, \Twig\Loader\SourceContextLoaderInterface

Loads a template from an array.

When using this loader with a cache mechanism, you should know that a new cache key is generated each time a template content "changes" (the cache key being the source code of the template). If you don't want to see your cache grows out of control, you need to take care of clearing the old cache file by yourself.

This loader should only be used for unit testing.

final
author

Fabien Potencier fabien@symfony.com

package

Default

Methods

__construct

__construct(array $templates = array())

Arguments

$templates

array

An array of templates (keys are the names, and values are the source code)

Check if we have the source code of a template, given its name.

exists(string $name): boolean

Arguments

$name

string

The name of the template to check if we can load

Response

boolean

If the template source code is handled by this loader or not

Gets the cache key to use for the cache for a given template name.

getCacheKey(string $name): string

Arguments

$name

string

The name of the template to load

Response

string

The cache key

Gets the source code of a template, given its name.

getSource(string $name): string

Arguments

$name

string

The name of the template to load

Response

string

The template source code

Returns the source context for a given template logical name.

getSourceContext(string $name): \Twig\Source

Arguments

$name

string

The template logical name

Response

\Twig\Source

Returns true if the template is still fresh.

isFresh(string $name,integer $time): boolean

Arguments

$name

string

The template name

$time

integer

Timestamp of the last modification time of the cached template

Response

boolean

true if the template is fresh, false otherwise

Adds or overrides a template.

setTemplate(string $name,string $template)

Arguments

$name

string

The template name

$template

string

The template source

Properties

templates

templates :

Type(s)