ArrayLoader
in package
implements
LoaderInterface, ExistsLoaderInterface, 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.
Tags
Interfaces, Classes and Traits
- LoaderInterface
- Interface all loaders must implement.
- ExistsLoaderInterface
- Empty interface for Twig 1.x compatibility.
- SourceContextLoaderInterface
- Empty interface for Twig 1.x compatibility.
Table of Contents
- $templates : mixed
- __construct() : mixed
- exists() : bool
- Check if we have the source code of a template, given its name.
- getCacheKey() : string
- Gets the cache key to use for the cache for a given template name.
- getSourceContext() : Source
- Returns the source context for a given template logical name.
- isFresh() : bool
- Returns true if the template is still fresh.
- setTemplate() : mixed
- Adds or overrides a template.
Properties
$templates
private
mixed
$templates
= []
Methods
__construct()
public
__construct([array<string|int, mixed> $templates = [] ]) : mixed
Parameters
- $templates : array<string|int, mixed> = []
-
An array of templates (keys are the names, and values are the source code)
Return values
mixed —exists()
Check if we have the source code of a template, given its name.
public
exists(mixed $name) : bool
Parameters
- $name : mixed
-
The name of the template to check if we can load
Return values
bool —If the template source code is handled by this loader or not
getCacheKey()
Gets the cache key to use for the cache for a given template name.
public
getCacheKey(mixed $name) : string
Parameters
- $name : mixed
-
The name of the template to load
Return values
string —The cache key
getSourceContext()
Returns the source context for a given template logical name.
public
getSourceContext(mixed $name) : Source
Parameters
- $name : mixed
-
The template logical name
Return values
Source —isFresh()
Returns true if the template is still fresh.
public
isFresh(mixed $name, mixed $time) : bool
Parameters
- $name : mixed
-
The template name
- $time : mixed
-
Timestamp of the last modification time of the cached template
Return values
bool —true if the template is fresh, false otherwise
setTemplate()
Adds or overrides a template.
public
setTemplate(string $name, string $template) : mixed
Parameters
- $name : string
-
The template name
- $template : string
-
The template source