FilesystemLoader
in package
implements
LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
Loads template from the filesystem.
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
- MAIN_NAMESPACE = '__main__'
- Identifier of the main namespace.
- $cache : mixed
- $errorCache : mixed
- $paths : mixed
- $rootPath : mixed
- __construct() : mixed
- addPath() : mixed
- Adds a path where templates are stored.
- 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.
- getNamespaces() : array<string|int, mixed>
- Returns the path namespaces.
- getPaths() : array<string|int, mixed>
- Returns the paths to the templates.
- getSourceContext() : Source
- Returns the source context for a given template logical name.
- isFresh() : bool
- Returns true if the template is still fresh.
- prependPath() : mixed
- Prepends a path where templates are stored.
- setPaths() : mixed
- Sets the paths where templates are stored.
- findTemplate() : string|false|null
- Checks if the template can be found.
- isAbsolutePath() : mixed
- normalizeName() : mixed
- parseName() : mixed
- validateName() : mixed
Constants
MAIN_NAMESPACE
Identifier of the main namespace.
public
mixed
MAIN_NAMESPACE
= '__main__'
Properties
$cache
protected
mixed
$cache
= []
$errorCache
protected
mixed
$errorCache
= []
$paths
protected
mixed
$paths
= []
$rootPath
private
mixed
$rootPath
Methods
__construct()
public
__construct([string|array<string|int, mixed> $paths = [] ][, string|null $rootPath = null ]) : mixed
Parameters
- $paths : string|array<string|int, mixed> = []
-
A path or an array of paths where to look for templates
- $rootPath : string|null = null
-
The root path common to all relative paths (null for getcwd())
Return values
mixed —addPath()
Adds a path where templates are stored.
public
addPath(string $path[, string $namespace = self::MAIN_NAMESPACE ]) : mixed
Parameters
- $path : string
-
A path where to look for templates
- $namespace : string = self::MAIN_NAMESPACE
-
A path namespace
Tags
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
getNamespaces()
Returns the path namespaces.
public
getNamespaces() : array<string|int, mixed>
The main namespace is always defined.
Return values
array<string|int, mixed> —The array of defined namespaces
getPaths()
Returns the paths to the templates.
public
getPaths([string $namespace = self::MAIN_NAMESPACE ]) : array<string|int, mixed>
Parameters
- $namespace : string = self::MAIN_NAMESPACE
-
A path namespace
Return values
array<string|int, mixed> —The array of paths where to look for templates
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
prependPath()
Prepends a path where templates are stored.
public
prependPath(string $path[, string $namespace = self::MAIN_NAMESPACE ]) : mixed
Parameters
- $path : string
-
A path where to look for templates
- $namespace : string = self::MAIN_NAMESPACE
-
A path namespace
Tags
Return values
mixed —setPaths()
Sets the paths where templates are stored.
public
setPaths(string|array<string|int, mixed> $paths[, string $namespace = self::MAIN_NAMESPACE ]) : mixed
Parameters
- $paths : string|array<string|int, mixed>
-
A path or an array of paths where to look for templates
- $namespace : string = self::MAIN_NAMESPACE
-
A path namespace
Return values
mixed —findTemplate()
Checks if the template can be found.
protected
findTemplate(string $name[, bool $throw = true ]) : string|false|null
In Twig 3.0, findTemplate must return a string or null (returning false won't work anymore).
Parameters
- $name : string
-
The template name
- $throw : bool = true
-
Whether to throw an exception when an error occurs
Return values
string|false|null —The template name or false/null
isAbsolutePath()
private
isAbsolutePath(mixed $file) : mixed
Parameters
- $file : mixed
Return values
mixed —normalizeName()
private
normalizeName(mixed $name) : mixed
Parameters
- $name : mixed
Return values
mixed —parseName()
private
parseName(mixed $name[, mixed $default = self::MAIN_NAMESPACE ]) : mixed
Parameters
- $name : mixed
- $default : mixed = self::MAIN_NAMESPACE
Return values
mixed —validateName()
private
validateName(mixed $name) : mixed
Parameters
- $name : mixed