class ArrayLoader
Same name in this branch
- 11.1.x vendor/composer/composer/src/Composer/Package/Loader/ArrayLoader.php \Composer\Package\Loader\ArrayLoader
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.
@author Fabien Potencier <fabien@symfony.com>
Hierarchy
- class \Twig\Loader\ArrayLoader implements \Twig\Loader\LoaderInterface
Expanded class hierarchy of ArrayLoader
3 files declare their use of ArrayLoader
- Environment.php in vendor/
twig/ twig/ src/ Environment.php - IntegrationTestCase.php in vendor/
twig/ twig/ src/ Test/ IntegrationTestCase.php - NodeTestCase.php in vendor/
twig/ twig/ src/ Test/ NodeTestCase.php
File
-
vendor/
twig/ twig/ src/ Loader/ ArrayLoader.php, line 29
Namespace
Twig\LoaderView source
final class ArrayLoader implements LoaderInterface {
/**
* @param array $templates An array of templates (keys are the names, and values are the source code)
*/
public function __construct(array $templates = []) {
}
public function setTemplate(string $name, string $template) : void {
$this->templates[$name] = $template;
}
public function getSourceContext(string $name) : Source {
if (!isset($this->templates[$name])) {
throw new LoaderError(\sprintf('Template "%s" is not defined.', $name));
}
return new Source($this->templates[$name], $name);
}
public function exists(string $name) : bool {
return isset($this->templates[$name]);
}
public function getCacheKey(string $name) : string {
if (!isset($this->templates[$name])) {
throw new LoaderError(\sprintf('Template "%s" is not defined.', $name));
}
return $name . ':' . $this->templates[$name];
}
public function isFresh(string $name, int $time) : bool {
if (!isset($this->templates[$name])) {
throw new LoaderError(\sprintf('Template "%s" is not defined.', $name));
}
return true;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ArrayLoader::exists | public | function | Overrides LoaderInterface::exists | |
ArrayLoader::getCacheKey | public | function | Gets the cache key to use for the cache for a given template name. | Overrides LoaderInterface::getCacheKey |
ArrayLoader::getSourceContext | public | function | Returns the source context for a given template logical name. | Overrides LoaderInterface::getSourceContext |
ArrayLoader::isFresh | public | function | Overrides LoaderInterface::isFresh | |
ArrayLoader::setTemplate | public | function | ||
ArrayLoader::__construct | public | function |