class loader extends FilesystemLoader

Twig Template loader

Properties

protected $safe_directories
protected filesystem_interface $filesystem

Methods

__construct(filesystem_interface $filesystem, string|array $paths = array())

Constructor

FilesystemLoader
setSafeDirectories(array $directories = array())

Set safe directories

FilesystemLoader
addSafeDirectory(string $directory)

Add safe directory

array
getSafeDirectories()

Get current safe directories

validateName($name)

Override for parent::validateName()

addPath($path, $namespace = self::MAIN_NAMESPACE)

Adds a realpath call to fix a BC break in Twig 1.26 (https://github.com/twigphp/Twig/issues/2145)

findTemplate($name, $throw = true)

Find the template

Details

at line 34
__construct(filesystem_interface $filesystem, string|array $paths = array())

Constructor

Parameters

filesystem_interface $filesystem
string|array $paths

at line 47
FilesystemLoader setSafeDirectories(array $directories = array())

Set safe directories

Parameters

array $directories

Array of directories that are safe (empty to clear)

Return Value

FilesystemLoader

at line 68
FilesystemLoader addSafeDirectory(string $directory)

Add safe directory

Parameters

string $directory

Directory that should be added

Return Value

FilesystemLoader

at line 85
array getSafeDirectories()

Get current safe directories

Return Value

array

at line 98
protected validateName($name)

Override for parent::validateName()

This is done because we added support for safe directories, and when Twig findTemplate() is called, validateName() is called first, which would always throw an exception if the file is outside of the configured template directories.

Parameters

$name

at line 108
addPath($path, $namespace = self::MAIN_NAMESPACE)

Adds a realpath call to fix a BC break in Twig 1.26 (https://github.com/twigphp/Twig/issues/2145)

{@inheritdoc}

Parameters

$path
$namespace

at line 119
protected findTemplate($name, $throw = true)

Find the template

Override for \Twig\Loader\FilesystemLoader::findTemplate to add support for loading from safe directories.

Parameters

$name
$throw