summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Loader
diff options
context:
space:
mode:
authorAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:22:40 +1000
committerAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:22:40 +1000
commit92561d7f36508b7e0271926e417adf0e2e53916b (patch)
treea8588b4f70af276c5acf58836e33b1f6ff5c61e8 /inc/lib/Twig/Loader
parent6f1083e4b51fc9c4c594f6c72cf3d84ef4d0298b (diff)
Initial attempt a switch to composer and PHP-8.1 compatibility
Diffstat (limited to 'inc/lib/Twig/Loader')
-rw-r--r--inc/lib/Twig/Loader/Array.php97
-rw-r--r--inc/lib/Twig/Loader/Chain.php151
-rw-r--r--inc/lib/Twig/Loader/Filesystem.php290
-rw-r--r--inc/lib/Twig/Loader/String.php58
4 files changed, 0 insertions, 596 deletions
diff --git a/inc/lib/Twig/Loader/Array.php b/inc/lib/Twig/Loader/Array.php
deleted file mode 100644
index 0aac7690..00000000
--- a/inc/lib/Twig/Loader/Array.php
+++ /dev/null
@@ -1,97 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * 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.
- *
- * @final
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
-{
- protected $templates = array();
-
- /**
- * @param array $templates An array of templates (keys are the names, and values are the source code)
- */
- public function __construct(array $templates = array())
- {
- $this->templates = $templates;
- }
-
- /**
- * Adds or overrides a template.
- *
- * @param string $name The template name
- * @param string $template The template source
- */
- public function setTemplate($name, $template)
- {
- $this->templates[(string) $name] = $template;
- }
-
- public function getSource($name)
- {
- @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
-
- $name = (string) $name;
- if (!isset($this->templates[$name])) {
- throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
- }
-
- return $this->templates[$name];
- }
-
- public function getSourceContext($name)
- {
- $name = (string) $name;
- if (!isset($this->templates[$name])) {
- throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
- }
-
- return new Twig_Source($this->templates[$name], $name);
- }
-
- public function exists($name)
- {
- return isset($this->templates[(string) $name]);
- }
-
- public function getCacheKey($name)
- {
- $name = (string) $name;
- if (!isset($this->templates[$name])) {
- throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
- }
-
- return $name.':'.$this->templates[$name];
- }
-
- public function isFresh($name, $time)
- {
- $name = (string) $name;
- if (!isset($this->templates[$name])) {
- throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
- }
-
- return true;
- }
-}
-
-class_alias('Twig_Loader_Array', 'Twig\Loader\ArrayLoader', false);
diff --git a/inc/lib/Twig/Loader/Chain.php b/inc/lib/Twig/Loader/Chain.php
deleted file mode 100644
index 59a33796..00000000
--- a/inc/lib/Twig/Loader/Chain.php
+++ /dev/null
@@ -1,151 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Loads templates from other loaders.
- *
- * @final
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
-{
- private $hasSourceCache = array();
- protected $loaders = array();
-
- /**
- * @param Twig_LoaderInterface[] $loaders
- */
- public function __construct(array $loaders = array())
- {
- foreach ($loaders as $loader) {
- $this->addLoader($loader);
- }
- }
-
- public function addLoader(Twig_LoaderInterface $loader)
- {
- $this->loaders[] = $loader;
- $this->hasSourceCache = array();
- }
-
- public function getSource($name)
- {
- @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
-
- $exceptions = array();
- foreach ($this->loaders as $loader) {
- if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
- continue;
- }
-
- try {
- return $loader->getSource($name);
- } catch (Twig_Error_Loader $e) {
- $exceptions[] = $e->getMessage();
- }
- }
-
- throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
- }
-
- public function getSourceContext($name)
- {
- $exceptions = array();
- foreach ($this->loaders as $loader) {
- if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
- continue;
- }
-
- try {
- if ($loader instanceof Twig_SourceContextLoaderInterface) {
- return $loader->getSourceContext($name);
- }
-
- return new Twig_Source($loader->getSource($name), $name);
- } catch (Twig_Error_Loader $e) {
- $exceptions[] = $e->getMessage();
- }
- }
-
- throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
- }
-
- public function exists($name)
- {
- $name = (string) $name;
-
- if (isset($this->hasSourceCache[$name])) {
- return $this->hasSourceCache[$name];
- }
-
- foreach ($this->loaders as $loader) {
- if ($loader instanceof Twig_ExistsLoaderInterface) {
- if ($loader->exists($name)) {
- return $this->hasSourceCache[$name] = true;
- }
-
- continue;
- }
-
- try {
- if ($loader instanceof Twig_SourceContextLoaderInterface) {
- $loader->getSourceContext($name);
- } else {
- $loader->getSource($name);
- }
-
- return $this->hasSourceCache[$name] = true;
- } catch (Twig_Error_Loader $e) {
- }
- }
-
- return $this->hasSourceCache[$name] = false;
- }
-
- public function getCacheKey($name)
- {
- $exceptions = array();
- foreach ($this->loaders as $loader) {
- if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
- continue;
- }
-
- try {
- return $loader->getCacheKey($name);
- } catch (Twig_Error_Loader $e) {
- $exceptions[] = get_class($loader).': '.$e->getMessage();
- }
- }
-
- throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
- }
-
- public function isFresh($name, $time)
- {
- $exceptions = array();
- foreach ($this->loaders as $loader) {
- if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
- continue;
- }
-
- try {
- return $loader->isFresh($name, $time);
- } catch (Twig_Error_Loader $e) {
- $exceptions[] = get_class($loader).': '.$e->getMessage();
- }
- }
-
- throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
- }
-}
-
-class_alias('Twig_Loader_Chain', 'Twig\Loader\ChainLoader', false);
diff --git a/inc/lib/Twig/Loader/Filesystem.php b/inc/lib/Twig/Loader/Filesystem.php
deleted file mode 100644
index 4e8be0d5..00000000
--- a/inc/lib/Twig/Loader/Filesystem.php
+++ /dev/null
@@ -1,290 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Loads template from the filesystem.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
-{
- /** Identifier of the main namespace. */
- const MAIN_NAMESPACE = '__main__';
-
- protected $paths = array();
- protected $cache = array();
- protected $errorCache = array();
-
- private $rootPath;
-
- /**
- * @param string|array $paths A path or an array of paths where to look for templates
- * @param string|null $rootPath The root path common to all relative paths (null for getcwd())
- */
- public function __construct($paths = array(), $rootPath = null)
- {
- $this->rootPath = (null === $rootPath ? getcwd() : $rootPath).DIRECTORY_SEPARATOR;
- if (false !== $realPath = realpath($rootPath)) {
- $this->rootPath = $realPath.DIRECTORY_SEPARATOR;
- }
-
- if ($paths) {
- $this->setPaths($paths);
- }
- }
-
- /**
- * Returns the paths to the templates.
- *
- * @param string $namespace A path namespace
- *
- * @return array The array of paths where to look for templates
- */
- public function getPaths($namespace = self::MAIN_NAMESPACE)
- {
- return isset($this->paths[$namespace]) ? $this->paths[$namespace] : array();
- }
-
- /**
- * Returns the path namespaces.
- *
- * The main namespace is always defined.
- *
- * @return array The array of defined namespaces
- */
- public function getNamespaces()
- {
- return array_keys($this->paths);
- }
-
- /**
- * Sets the paths where templates are stored.
- *
- * @param string|array $paths A path or an array of paths where to look for templates
- * @param string $namespace A path namespace
- */
- public function setPaths($paths, $namespace = self::MAIN_NAMESPACE)
- {
- if (!is_array($paths)) {
- $paths = array($paths);
- }
-
- $this->paths[$namespace] = array();
- foreach ($paths as $path) {
- $this->addPath($path, $namespace);
- }
- }
-
- /**
- * Adds a path where templates are stored.
- *
- * @param string $path A path where to look for templates
- * @param string $namespace A path namespace
- *
- * @throws Twig_Error_Loader
- */
- public function addPath($path, $namespace = self::MAIN_NAMESPACE)
- {
- // invalidate the cache
- $this->cache = $this->errorCache = array();
-
- $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;
- if (!is_dir($checkPath)) {
- throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
- }
-
- $this->paths[$namespace][] = rtrim($path, '/\\');
- }
-
- /**
- * Prepends a path where templates are stored.
- *
- * @param string $path A path where to look for templates
- * @param string $namespace A path namespace
- *
- * @throws Twig_Error_Loader
- */
- public function prependPath($path, $namespace = self::MAIN_NAMESPACE)
- {
- // invalidate the cache
- $this->cache = $this->errorCache = array();
-
- $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;
- if (!is_dir($checkPath)) {
- throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
- }
-
- $path = rtrim($path, '/\\');
-
- if (!isset($this->paths[$namespace])) {
- $this->paths[$namespace][] = $path;
- } else {
- array_unshift($this->paths[$namespace], $path);
- }
- }
-
- public function getSource($name)
- {
- @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
-
- return file_get_contents($this->findTemplate($name));
- }
-
- public function getSourceContext($name)
- {
- $path = $this->findTemplate($name);
-
- return new Twig_Source(file_get_contents($path), $name, $path);
- }
-
- public function getCacheKey($name)
- {
- $path = $this->findTemplate($name);
- $len = strlen($this->rootPath);
- if (0 === strncmp($this->rootPath, $path, $len)) {
- return substr($path, $len);
- }
-
- return $path;
- }
-
- public function exists($name)
- {
- $name = $this->normalizeName($name);
-
- if (isset($this->cache[$name])) {
- return true;
- }
-
- try {
- return false !== $this->findTemplate($name, false);
- } catch (Twig_Error_Loader $exception) {
- @trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', get_class($this)), E_USER_DEPRECATED);
-
- return false;
- }
- }
-
- public function isFresh($name, $time)
- {
- return filemtime($this->findTemplate($name)) < $time;
- }
-
- protected function findTemplate($name)
- {
- $throw = func_num_args() > 1 ? func_get_arg(1) : true;
- $name = $this->normalizeName($name);
-
- if (isset($this->cache[$name])) {
- return $this->cache[$name];
- }
-
- if (isset($this->errorCache[$name])) {
- if (!$throw) {
- return false;
- }
-
- throw new Twig_Error_Loader($this->errorCache[$name]);
- }
-
- $this->validateName($name);
-
- list($namespace, $shortname) = $this->parseName($name);
-
- if (!isset($this->paths[$namespace])) {
- $this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace);
-
- if (!$throw) {
- return false;
- }
-
- throw new Twig_Error_Loader($this->errorCache[$name]);
- }
-
- foreach ($this->paths[$namespace] as $path) {
- if (!$this->isAbsolutePath($path)) {
- $path = $this->rootPath.'/'.$path;
- }
-
- if (is_file($path.'/'.$shortname)) {
- if (false !== $realpath = realpath($path.'/'.$shortname)) {
- return $this->cache[$name] = $realpath;
- }
-
- return $this->cache[$name] = $path.'/'.$shortname;
- }
- }
-
- $this->errorCache[$name] = sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace]));
-
- if (!$throw) {
- return false;
- }
-
- throw new Twig_Error_Loader($this->errorCache[$name]);
- }
-
- protected function parseName($name, $default = self::MAIN_NAMESPACE)
- {
- if (isset($name[0]) && '@' == $name[0]) {
- if (false === $pos = strpos($name, '/')) {
- throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name));
- }
-
- $namespace = substr($name, 1, $pos - 1);
- $shortname = substr($name, $pos + 1);
-
- return array($namespace, $shortname);
- }
-
- return array($default, $name);
- }
-
- protected function normalizeName($name)
- {
- return preg_replace('#/{2,}#', '/', str_replace('\\', '/', (string) $name));
- }
-
- protected function validateName($name)
- {
- if (false !== strpos($name, "\0")) {
- throw new Twig_Error_Loader('A template name cannot contain NUL bytes.');
- }
-
- $name = ltrim($name, '/');
- $parts = explode('/', $name);
- $level = 0;
- foreach ($parts as $part) {
- if ('..' === $part) {
- --$level;
- } elseif ('.' !== $part) {
- ++$level;
- }
-
- if ($level < 0) {
- throw new Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name));
- }
- }
- }
-
- private function isAbsolutePath($file)
- {
- return strspn($file, '/\\', 0, 1)
- || (strlen($file) > 3 && ctype_alpha($file[0])
- && ':' === substr($file, 1, 1)
- && strspn($file, '/\\', 2, 1)
- )
- || null !== parse_url($file, PHP_URL_SCHEME)
- ;
- }
-}
-
-class_alias('Twig_Loader_Filesystem', 'Twig\Loader\FilesystemLoader', false);
diff --git a/inc/lib/Twig/Loader/String.php b/inc/lib/Twig/Loader/String.php
deleted file mode 100644
index 950bd35b..00000000
--- a/inc/lib/Twig/Loader/String.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-@trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use Twig_Loader_Array instead or Twig_Environment::createTemplate().', E_USER_DEPRECATED);
-
-/**
- * Loads a template from a string.
- *
- * This loader should NEVER be used. It only exists for Twig internal purposes.
- *
- * 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.
- *
- * @deprecated since 1.18.1 (to be removed in 2.0)
- *
- * @internal
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
-{
- public function getSource($name)
- {
- @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
-
- return $name;
- }
-
- public function getSourceContext($name)
- {
- return new Twig_Source($name, $name);
- }
-
- public function exists($name)
- {
- return true;
- }
-
- public function getCacheKey($name)
- {
- return $name;
- }
-
- public function isFresh($name, $time)
- {
- return true;
- }
-}