Twig API
Class

Twig_Loader_Array

class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface

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.

Methods

__construct(array $templates)

Constructor.

setTemplate(string $name, string $template)

Adds or overrides a template.

string getSource(string $name)

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

boolean exists(string $name)

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

string getCacheKey(string $name)

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

Boolean isFresh(string $name, timestamp $time)

Returns true if the template is still fresh.

Details

at line 33
public __construct(array $templates)

Constructor.

Parameters

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

See also

Twig_Loader

at line 47
public setTemplate(string $name, string $template)

Adds or overrides a template.

Parameters

string $name The template name
string $template The template source

at line 55
public string getSource(string $name)

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

Parameters

string $name The name of the template to load

Return Value

string The template source code

Exceptions

Twig_Error_Loader When $name is not found

at line 68
public boolean exists(string $name)

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

Parameters

string $name The name of the template to check if we can load

Return Value

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

at line 76
public string getCacheKey(string $name)

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

Parameters

string $name The name of the template to load

Return Value

string The cache key

Exceptions

Twig_Error_Loader When $name is not found

at line 89
public Boolean isFresh(string $name, timestamp $time)

Returns true if the template is still fresh.

Parameters

string $name The template name
timestamp $time The last modification time of the cached template

Return Value

Boolean true if the template is fresh, false otherwise

Exceptions

Twig_Error_Loader When $name is not found