mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 17:54:55 +02:00
Update Twig to v2.15.4
This commit is contained in:
@@ -22,7 +22,7 @@ use Twig\Source;
|
||||
class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
|
||||
{
|
||||
/** Identifier of the main namespace. */
|
||||
const MAIN_NAMESPACE = '__main__';
|
||||
public const MAIN_NAMESPACE = '__main__';
|
||||
|
||||
protected $paths = [];
|
||||
protected $cache = [];
|
||||
@@ -34,10 +34,10 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
|
||||
* @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 = [], $rootPath = null)
|
||||
public function __construct($paths = [], string $rootPath = null)
|
||||
{
|
||||
$this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR;
|
||||
if (false !== $realPath = realpath($rootPath)) {
|
||||
if (null !== $rootPath && false !== ($realPath = realpath($rootPath))) {
|
||||
$this->rootPath = $realPath.\DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
@@ -136,17 +136,6 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (null === ($path = $this->findTemplate($name)) || false === $path) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return file_get_contents($path);
|
||||
}
|
||||
|
||||
public function getSourceContext($name)
|
||||
{
|
||||
if (null === ($path = $this->findTemplate($name)) || false === $path) {
|
||||
@@ -177,13 +166,7 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
return null !== ($path = $this->findTemplate($name, false)) && false !== $path;
|
||||
} catch (LoaderError $e) {
|
||||
@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;
|
||||
}
|
||||
return null !== ($path = $this->findTemplate($name, false)) && false !== $path;
|
||||
}
|
||||
|
||||
public function isFresh($name, $time)
|
||||
@@ -199,13 +182,15 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
|
||||
/**
|
||||
* Checks if the template can be found.
|
||||
*
|
||||
* @param string $name The template name
|
||||
* In Twig 3.0, findTemplate must return a string or null (returning false won't work anymore).
|
||||
*
|
||||
* @param string $name The template name
|
||||
* @param bool $throw Whether to throw an exception when an error occurs
|
||||
*
|
||||
* @return string|false|null The template name or false/null
|
||||
*/
|
||||
protected function findTemplate($name)
|
||||
protected function findTemplate($name, $throw = true)
|
||||
{
|
||||
$throw = \func_num_args() > 1 ? func_get_arg(1) : true;
|
||||
$name = $this->normalizeName($name);
|
||||
|
||||
if (isset($this->cache[$name])) {
|
||||
@@ -221,9 +206,9 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
|
||||
}
|
||||
|
||||
try {
|
||||
$this->validateName($name);
|
||||
|
||||
list($namespace, $shortname) = $this->parseName($name);
|
||||
|
||||
$this->validateName($shortname);
|
||||
} catch (LoaderError $e) {
|
||||
if (!$throw) {
|
||||
return false;
|
||||
@@ -265,7 +250,12 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
|
||||
throw new LoaderError($this->errorCache[$name]);
|
||||
}
|
||||
|
||||
protected function parseName($name, $default = self::MAIN_NAMESPACE)
|
||||
private function normalizeName($name)
|
||||
{
|
||||
return preg_replace('#/{2,}#', '/', str_replace('\\', '/', (string) $name));
|
||||
}
|
||||
|
||||
private function parseName($name, $default = self::MAIN_NAMESPACE)
|
||||
{
|
||||
if (isset($name[0]) && '@' == $name[0]) {
|
||||
if (false === $pos = strpos($name, '/')) {
|
||||
@@ -281,12 +271,7 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
|
||||
return [$default, $name];
|
||||
}
|
||||
|
||||
protected function normalizeName($name)
|
||||
{
|
||||
return preg_replace('#/{2,}#', '/', str_replace('\\', '/', (string) $name));
|
||||
}
|
||||
|
||||
protected function validateName($name)
|
||||
private function validateName($name)
|
||||
{
|
||||
if (false !== strpos($name, "\0")) {
|
||||
throw new LoaderError('A template name cannot contain NUL bytes.');
|
||||
@@ -312,10 +297,10 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
|
||||
{
|
||||
return strspn($file, '/\\', 0, 1)
|
||||
|| (\strlen($file) > 3 && ctype_alpha($file[0])
|
||||
&& ':' === substr($file, 1, 1)
|
||||
&& ':' === $file[1]
|
||||
&& strspn($file, '/\\', 2, 1)
|
||||
)
|
||||
|| null !== parse_url($file, PHP_URL_SCHEME)
|
||||
|| null !== parse_url($file, \PHP_URL_SCHEME)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user