Class Twig_Loader_Array

ImplementsTwig_ExistsLoaderInterface, Twig_LoaderInterface

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.

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$templates Twig_Loader_Array

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Constructor. Twig_Loader_Array
exists() {@inheritdoc} Twig_Loader_Array
getCacheKey() {@inheritdoc} Twig_Loader_Array
getSource() {@inheritdoc} Twig_Loader_Array
isFresh() {@inheritdoc} Twig_Loader_Array
setTemplate() Adds or overrides a template. Twig_Loader_Array

Property Details

$templates protected property
protected $templates = []

Method Details

__construct() public method


public void __construct ( array $templates )
$templates array

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

exists() public method


public void exists ( $name )
getCacheKey() public method


public void getCacheKey ( $name )
getSource() public method


public void getSource ( $name )
isFresh() public method


public void isFresh ( $name, $time )
setTemplate() public method

Adds or overrides a template.

public void setTemplate ( $name, $template )
$name string

The template name

$template string

The template source