Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', DelegatingEngine::class);
/**
* DelegatingEngine selects an engine for a given template.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class DelegatingEngine implements EngineInterface, StreamingEngineInterface
{
/**
* @var EngineInterface[]
*/
protected $engines = [];
/**
* @param EngineInterface[] $engines An array of EngineInterface instances to add
*/
public function __construct(array $engines = [])
{
foreach ($engines as $engine) {
$this->addEngine($engine);
}
}
public function render(string|TemplateReferenceInterface $name, array $parameters = []): string
{
return $this->getEngine($name)->render($name, $parameters);
}
/**
* @return void
*/
public function stream(string|TemplateReferenceInterface $name, array $parameters = [])
{
$engine = $this->getEngine($name);
if (!$engine instanceof StreamingEngineInterface) {
throw new \LogicException(\sprintf('Template "%s" cannot be streamed as the engine supporting it does not implement StreamingEngineInterface.', $name));
}
$engine->stream($name, $parameters);
}
public function exists(string|TemplateReferenceInterface $name): bool
{
return $this->getEngine($name)->exists($name);
}
/**
* @return void
*/
public function addEngine(EngineInterface $engine)
{
$this->engines[] = $engine;
}
public function supports(string|TemplateReferenceInterface $name): bool
{
try {
$this->getEngine($name);
} catch (\RuntimeException) {
return false;
}
return true;
}
/**
* Get an engine able to render the given template.
*
* @throws \RuntimeException if no engine able to work with the template is found
*/
public function getEngine(string|TemplateReferenceInterface $name): EngineInterface
{
foreach ($this->engines as $engine) {
if ($engine->supports($name)) {
return $engine;
}
}
throw new \RuntimeException(\sprintf('No engine is able to work with the template "%s".', $name));
}
}

View File

@@ -0,0 +1,55 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', EngineInterface::class);
/**
* EngineInterface is the interface each engine must implement.
*
* All methods rely on a template name. A template name is a
* "logical" name for the template, and as such it does not refer to
* a path on the filesystem (in fact, the template can be stored
* anywhere, like in a database).
*
* The methods should accept any name. If the name is not an instance of
* TemplateReferenceInterface, a TemplateNameParserInterface should be used to
* convert the name to a TemplateReferenceInterface instance.
*
* Each template loader uses the logical template name to look for
* the template.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
interface EngineInterface
{
/**
* Renders a template.
*
* @throws \RuntimeException if the template cannot be rendered
*/
public function render(string|TemplateReferenceInterface $name, array $parameters = []): string;
/**
* Returns true if the template exists.
*
* @throws \RuntimeException if the engine cannot handle the template name
*/
public function exists(string|TemplateReferenceInterface $name): bool;
/**
* Returns true if this class is able to render the given template.
*/
public function supports(string|TemplateReferenceInterface $name): bool;
}

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Helper;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', Helper::class);
/**
* Helper is the base class for all helper classes.
*
* Most of the time, a Helper is an adapter around an existing
* class that exposes a read-only interface for templates.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
abstract class Helper implements HelperInterface
{
protected $charset = 'UTF-8';
/**
* Sets the default charset.
*
* @return void
*/
public function setCharset(string $charset)
{
$this->charset = $charset;
}
/**
* Gets the default charset.
*/
public function getCharset(): string
{
return $this->charset;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Helper;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', HelperInterface::class);
/**
* HelperInterface is the interface all helpers must implement.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
interface HelperInterface
{
/**
* Returns the canonical name of this helper.
*
* @return string
*/
public function getName();
/**
* Sets the default charset.
*
* @return void
*/
public function setCharset(string $charset);
/**
* Gets the default charset.
*/
public function getCharset(): string;
}

View File

@@ -0,0 +1,124 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Helper;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', SlotsHelper::class);
/**
* SlotsHelper manages template slots.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class SlotsHelper extends Helper
{
protected $slots = [];
protected $openSlots = [];
/**
* Starts a new slot.
*
* This method starts an output buffer that will be
* closed when the stop() method is called.
*
* @return void
*
* @throws \InvalidArgumentException if a slot with the same name is already started
*/
public function start(string $name)
{
if (\in_array($name, $this->openSlots)) {
throw new \InvalidArgumentException(\sprintf('A slot named "%s" is already started.', $name));
}
$this->openSlots[] = $name;
$this->slots[$name] = '';
ob_start();
ob_implicit_flush(0);
}
/**
* Stops a slot.
*
* @return void
*
* @throws \LogicException if no slot has been started
*/
public function stop()
{
if (!$this->openSlots) {
throw new \LogicException('No slot started.');
}
$name = array_pop($this->openSlots);
$this->slots[$name] = ob_get_clean();
}
/**
* Returns true if the slot exists.
*/
public function has(string $name): bool
{
return isset($this->slots[$name]);
}
/**
* Gets the slot value.
*/
public function get(string $name, bool|string $default = false): string
{
return $this->slots[$name] ?? $default;
}
/**
* Sets a slot value.
*
* @return void
*/
public function set(string $name, string $content)
{
$this->slots[$name] = $content;
}
/**
* Outputs a slot.
*
* @return bool true if the slot is defined or if a default content has been provided, false otherwise
*/
public function output(string $name, bool|string $default = false): bool
{
if (!isset($this->slots[$name])) {
if (false !== $default) {
echo $default;
return true;
}
return false;
}
echo $this->slots[$name];
return true;
}
/**
* Returns the canonical name of this helper.
*/
public function getName(): string
{
return 'slots';
}
}

19
vendor/symfony/templating/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2004-present Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,79 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Loader;
use Symfony\Component\Templating\Storage\FileStorage;
use Symfony\Component\Templating\Storage\Storage;
use Symfony\Component\Templating\TemplateReferenceInterface;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', CacheLoader::class);
/**
* CacheLoader is a loader that caches other loaders responses
* on the filesystem.
*
* This cache only caches on disk to allow PHP accelerators to cache the opcodes.
* All other mechanism would imply the use of `eval()`.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class CacheLoader extends Loader
{
protected $loader;
protected $dir;
/**
* @param string $dir The directory where to store the cache files
*/
public function __construct(LoaderInterface $loader, string $dir)
{
$this->loader = $loader;
$this->dir = $dir;
}
public function load(TemplateReferenceInterface $template): Storage|false
{
$key = hash('sha256', $template->getLogicalName());
$dir = $this->dir.\DIRECTORY_SEPARATOR.substr($key, 0, 2);
$file = substr($key, 2).'.tpl';
$path = $dir.\DIRECTORY_SEPARATOR.$file;
if (is_file($path)) {
$this->logger?->debug('Fetching template from cache.', ['name' => $template->get('name')]);
return new FileStorage($path);
}
if (false === $storage = $this->loader->load($template)) {
return false;
}
$content = $storage->getContent();
if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
throw new \RuntimeException(\sprintf('Cache Loader was not able to create directory "%s".', $dir));
}
file_put_contents($path, $content);
$this->logger?->debug('Storing template in cache.', ['name' => $template->get('name')]);
return new FileStorage($path);
}
public function isFresh(TemplateReferenceInterface $template, int $time): bool
{
return $this->loader->isFresh($template, $time);
}
}

View File

@@ -0,0 +1,67 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Loader;
use Symfony\Component\Templating\Storage\Storage;
use Symfony\Component\Templating\TemplateReferenceInterface;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', ChainLoader::class);
/**
* ChainLoader is a loader that calls other loaders to load templates.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class ChainLoader extends Loader
{
protected $loaders = [];
/**
* @param LoaderInterface[] $loaders
*/
public function __construct(array $loaders = [])
{
foreach ($loaders as $loader) {
$this->addLoader($loader);
}
}
/**
* @return void
*/
public function addLoader(LoaderInterface $loader)
{
$this->loaders[] = $loader;
}
public function load(TemplateReferenceInterface $template): Storage|false
{
foreach ($this->loaders as $loader) {
if (false !== $storage = $loader->load($template)) {
return $storage;
}
}
return false;
}
public function isFresh(TemplateReferenceInterface $template, int $time): bool
{
foreach ($this->loaders as $loader) {
return $loader->isFresh($template, $time);
}
return false;
}
}

View File

@@ -0,0 +1,99 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Loader;
use Symfony\Component\Templating\Storage\FileStorage;
use Symfony\Component\Templating\Storage\Storage;
use Symfony\Component\Templating\TemplateReferenceInterface;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', FilesystemLoader::class);
/**
* FilesystemLoader is a loader that read templates from the filesystem.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class FilesystemLoader extends Loader
{
protected $templatePathPatterns;
/**
* @param string|string[] $templatePathPatterns An array of path patterns to look for templates
*/
public function __construct(string|array $templatePathPatterns)
{
$this->templatePathPatterns = (array) $templatePathPatterns;
}
public function load(TemplateReferenceInterface $template): Storage|false
{
$file = $template->get('name');
if (self::isAbsolutePath($file) && is_file($file)) {
return new FileStorage($file);
}
$replacements = [];
foreach ($template->all() as $key => $value) {
$replacements['%'.$key.'%'] = $value;
}
$fileFailures = [];
foreach ($this->templatePathPatterns as $templatePathPattern) {
if (is_file($file = strtr($templatePathPattern, $replacements)) && is_readable($file)) {
$this->logger?->debug('Loaded template file.', ['file' => $file]);
return new FileStorage($file);
}
if (null !== $this->logger) {
$fileFailures[] = $file;
}
}
// only log failures if no template could be loaded at all
foreach ($fileFailures as $file) {
$this->logger?->debug('Failed loading template file.', ['file' => $file]);
}
return false;
}
public function isFresh(TemplateReferenceInterface $template, int $time): bool
{
if (false === $storage = $this->load($template)) {
return false;
}
return filemtime((string) $storage) < $time;
}
/**
* Returns true if the file is an existing absolute path.
*/
protected static function isAbsolutePath(string $file): bool
{
if ('/' == $file[0] || '\\' == $file[0]
|| (\strlen($file) > 3 && ctype_alpha($file[0])
&& ':' == $file[1]
&& ('\\' == $file[2] || '/' == $file[2])
)
|| parse_url($file, \PHP_URL_SCHEME)
) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Loader;
use Psr\Log\LoggerInterface;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', Loader::class);
/**
* Loader is the base class for all template loader classes.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
abstract class Loader implements LoaderInterface
{
/**
* @var LoggerInterface|null
*/
protected $logger;
/**
* Sets the debug logger to use for this loader.
*
* @return void
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
}

View File

@@ -0,0 +1,39 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Loader;
use Symfony\Component\Templating\Storage\Storage;
use Symfony\Component\Templating\TemplateReferenceInterface;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', LoaderInterface::class);
/**
* LoaderInterface is the interface all loaders must implement.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
interface LoaderInterface
{
/**
* Loads a template.
*/
public function load(TemplateReferenceInterface $template): Storage|false;
/**
* Returns true if the template is still fresh.
*
* @param int $time The last modification time of the cached template (timestamp)
*/
public function isFresh(TemplateReferenceInterface $template, int $time): bool;
}

466
vendor/symfony/templating/PhpEngine.php vendored Normal file
View File

@@ -0,0 +1,466 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating;
use Symfony\Component\Templating\Helper\HelperInterface;
use Symfony\Component\Templating\Loader\LoaderInterface;
use Symfony\Component\Templating\Storage\FileStorage;
use Symfony\Component\Templating\Storage\Storage;
use Symfony\Component\Templating\Storage\StringStorage;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', PhpEngine::class);
/**
* PhpEngine is an engine able to render PHP templates.
*
* @implements \ArrayAccess<string, HelperInterface>
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class PhpEngine implements EngineInterface, \ArrayAccess
{
protected $loader;
protected $current;
/**
* @var HelperInterface[]
*/
protected $helpers = [];
protected $parents = [];
protected $stack = [];
protected $charset = 'UTF-8';
protected $cache = [];
protected $escapers = [];
protected static $escaperCache = [];
protected $globals = [];
protected $parser;
private Storage $evalTemplate;
private array $evalParameters;
/**
* @param HelperInterface[] $helpers An array of helper instances
*/
public function __construct(TemplateNameParserInterface $parser, LoaderInterface $loader, array $helpers = [])
{
$this->parser = $parser;
$this->loader = $loader;
$this->addHelpers($helpers);
$this->initializeEscapers();
foreach ($this->escapers as $context => $escaper) {
$this->setEscaper($context, $escaper);
}
}
/**
* @throws \InvalidArgumentException if the template does not exist
*/
public function render(string|TemplateReferenceInterface $name, array $parameters = []): string
{
$storage = $this->load($name);
$key = hash('sha256', serialize($storage));
$this->current = $key;
$this->parents[$key] = null;
// attach the global variables
$parameters = array_replace($this->getGlobals(), $parameters);
// render
if (false === $content = $this->evaluate($storage, $parameters)) {
throw new \RuntimeException(\sprintf('The template "%s" cannot be rendered.', $this->parser->parse($name)));
}
// decorator
if ($this->parents[$key]) {
$slots = $this->get('slots');
$this->stack[] = $slots->get('_content');
$slots->set('_content', $content);
$content = $this->render($this->parents[$key], $parameters);
$slots->set('_content', array_pop($this->stack));
}
return $content;
}
public function exists(string|TemplateReferenceInterface $name): bool
{
try {
$this->load($name);
} catch (\InvalidArgumentException) {
return false;
}
return true;
}
public function supports(string|TemplateReferenceInterface $name): bool
{
$template = $this->parser->parse($name);
return 'php' === $template->get('engine');
}
/**
* Evaluates a template.
*
* @throws \InvalidArgumentException
*/
protected function evaluate(Storage $template, array $parameters = []): string|false
{
$this->evalTemplate = $template;
$this->evalParameters = $parameters;
unset($template, $parameters);
if (isset($this->evalParameters['this'])) {
throw new \InvalidArgumentException('Invalid parameter (this).');
}
if (isset($this->evalParameters['view'])) {
throw new \InvalidArgumentException('Invalid parameter (view).');
}
// the view variable is exposed to the require file below
$view = $this;
if ($this->evalTemplate instanceof FileStorage) {
extract($this->evalParameters, \EXTR_SKIP);
unset($this->evalParameters);
ob_start();
require $this->evalTemplate;
unset($this->evalTemplate);
return ob_get_clean();
} elseif ($this->evalTemplate instanceof StringStorage) {
extract($this->evalParameters, \EXTR_SKIP);
unset($this->evalParameters);
ob_start();
eval('; ?>'.$this->evalTemplate.'<?php ;');
unset($this->evalTemplate);
return ob_get_clean();
}
return false;
}
/**
* Gets a helper value.
*
* @throws \InvalidArgumentException if the helper is not defined
*/
public function offsetGet(mixed $name): HelperInterface
{
return $this->get($name);
}
/**
* Returns true if the helper is defined.
*/
public function offsetExists(mixed $name): bool
{
return isset($this->helpers[$name]);
}
/**
* Sets a helper.
*/
public function offsetSet(mixed $name, mixed $value): void
{
$this->set($name, $value);
}
/**
* Removes a helper.
*
* @throws \LogicException
*/
public function offsetUnset(mixed $name): void
{
throw new \LogicException(\sprintf('You can\'t unset a helper (%s).', $name));
}
/**
* Adds some helpers.
*
* @param HelperInterface[] $helpers An array of helper
*
* @return void
*/
public function addHelpers(array $helpers)
{
foreach ($helpers as $alias => $helper) {
$this->set($helper, \is_int($alias) ? null : $alias);
}
}
/**
* Sets the helpers.
*
* @param HelperInterface[] $helpers An array of helper
*
* @return void
*/
public function setHelpers(array $helpers)
{
$this->helpers = [];
$this->addHelpers($helpers);
}
/**
* @return void
*/
public function set(HelperInterface $helper, ?string $alias = null)
{
$this->helpers[$helper->getName()] = $helper;
if (null !== $alias) {
$this->helpers[$alias] = $helper;
}
$helper->setCharset($this->charset);
}
/**
* Returns true if the helper if defined.
*/
public function has(string $name): bool
{
return isset($this->helpers[$name]);
}
/**
* Gets a helper value.
*
* @throws \InvalidArgumentException if the helper is not defined
*/
public function get(string $name): HelperInterface
{
if (!isset($this->helpers[$name])) {
throw new \InvalidArgumentException(\sprintf('The helper "%s" is not defined.', $name));
}
return $this->helpers[$name];
}
/**
* Decorates the current template with another one.
*
* @return void
*/
public function extend(string $template)
{
$this->parents[$this->current] = $template;
}
/**
* Escapes a string by using the current charset.
*/
public function escape(mixed $value, string $context = 'html'): mixed
{
if (is_numeric($value)) {
return $value;
}
// If we deal with a scalar value, we can cache the result to increase
// the performance when the same value is escaped multiple times (e.g. loops)
if (\is_scalar($value)) {
if (!isset(self::$escaperCache[$context][$value])) {
self::$escaperCache[$context][$value] = $this->getEscaper($context)($value);
}
return self::$escaperCache[$context][$value];
}
return $this->getEscaper($context)($value);
}
/**
* Sets the charset to use.
*
* @return void
*/
public function setCharset(string $charset)
{
if ('UTF8' === $charset = strtoupper($charset)) {
$charset = 'UTF-8'; // iconv on Windows requires "UTF-8" instead of "UTF8"
}
$this->charset = $charset;
foreach ($this->helpers as $helper) {
$helper->setCharset($this->charset);
}
}
/**
* Gets the current charset.
*/
public function getCharset(): string
{
return $this->charset;
}
/**
* Adds an escaper for the given context.
*
* @return void
*/
public function setEscaper(string $context, callable $escaper)
{
$this->escapers[$context] = $escaper;
self::$escaperCache[$context] = [];
}
/**
* Gets an escaper for a given context.
*
* @throws \InvalidArgumentException
*/
public function getEscaper(string $context): callable
{
if (!isset($this->escapers[$context])) {
throw new \InvalidArgumentException(\sprintf('No registered escaper for context "%s".', $context));
}
return $this->escapers[$context];
}
/**
* @return void
*/
public function addGlobal(string $name, mixed $value)
{
$this->globals[$name] = $value;
}
/**
* Returns the assigned globals.
*/
public function getGlobals(): array
{
return $this->globals;
}
/**
* Initializes the built-in escapers.
*
* Each function specifies a way for applying a transformation to a string
* passed to it. The purpose is for the string to be "escaped" so it is
* suitable for the format it is being displayed in.
*
* For example, the string: "It's required that you enter a username & password.\n"
* If this were to be displayed as HTML it would be sensible to turn the
* ampersand into '&amp;' and the apostrophe into '&aps;'. However if it were
* going to be used as a string in JavaScript to be displayed in an alert box
* it would be right to leave the string as-is, but c-escape the apostrophe and
* the new line.
*
* For each function there is a define to avoid problems with strings being
* incorrectly specified.
*
* @return void
*/
protected function initializeEscapers()
{
$flags = \ENT_QUOTES | \ENT_SUBSTITUTE;
$this->escapers = [
'html' =>
/**
* Runs the PHP function htmlspecialchars on the value passed.
*
* @param string $value The value to escape
*
* @return string
*/
fn ($value) => // Numbers and Boolean values get turned into strings which can cause problems
// with type comparisons (e.g. === or is_int() etc).
\is_string($value) ? htmlspecialchars($value, $flags, $this->getCharset(), false) : $value,
'js' =>
/**
* A function that escape all non-alphanumeric characters
* into their \xHH or \uHHHH representations.
*
* @param string $value The value to escape
*
* @return string
*/
function ($value) {
if ('UTF-8' != $this->getCharset()) {
$value = iconv($this->getCharset(), 'UTF-8', $value);
}
$callback = function ($matches) {
$char = $matches[0];
// \xHH
if (!isset($char[1])) {
return '\\x'.substr('00'.bin2hex($char), -2);
}
// \uHHHH
$char = iconv('UTF-8', 'UTF-16BE', $char);
return '\\u'.substr('0000'.bin2hex($char), -4);
};
if (null === $value = preg_replace_callback('#[^\p{L}\p{N} ]#u', $callback, $value)) {
throw new \InvalidArgumentException('The string to escape is not a valid UTF-8 string.');
}
if ('UTF-8' != $this->getCharset()) {
$value = iconv('UTF-8', $this->getCharset(), $value);
}
return $value;
},
];
self::$escaperCache = [];
}
/**
* Gets the loader associated with this engine.
*/
public function getLoader(): LoaderInterface
{
return $this->loader;
}
/**
* Loads the given template.
*
* @throws \InvalidArgumentException if the template cannot be found
*/
protected function load(string|TemplateReferenceInterface $name): Storage
{
$template = $this->parser->parse($name);
$key = $template->getLogicalName();
if (isset($this->cache[$key])) {
return $this->cache[$key];
}
$storage = $this->loader->load($template);
if (false === $storage) {
throw new \InvalidArgumentException(\sprintf('The template "%s" does not exist.', $template));
}
return $this->cache[$key] = $storage;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Storage;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', FileStorage::class);
/**
* FileStorage represents a template stored on the filesystem.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class FileStorage extends Storage
{
/**
* Returns the content of the template.
*/
public function getContent(): string
{
return file_get_contents($this->template);
}
}

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Storage;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', Storage::class);
/**
* Storage is the base class for all storage classes.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
abstract class Storage
{
protected $template;
/**
* @param string $template The template name
*/
public function __construct(string $template)
{
$this->template = $template;
}
/**
* Returns the object string representation.
*/
public function __toString(): string
{
return $this->template;
}
/**
* Returns the content of the template.
*/
abstract public function getContent(): string;
}

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating\Storage;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', StringStorage::class);
/**
* StringStorage represents a template stored in a string.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class StringStorage extends Storage
{
/**
* Returns the content of the template.
*/
public function getContent(): string
{
return $this->template;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', StreamingEngineInterface::class);
/**
* StreamingEngineInterface provides a method that knows how to stream a template.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
interface StreamingEngineInterface
{
/**
* Streams a template.
*
* The implementation should output the content directly to the client.
*
* @return void
*
* @throws \RuntimeException if the template cannot be rendered
* @throws \LogicException if the template cannot be streamed
*/
public function stream(string|TemplateReferenceInterface $name, array $parameters = []);
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', TemplateNameParser::class);
/**
* TemplateNameParser is the default implementation of TemplateNameParserInterface.
*
* This implementation takes everything as the template name
* and the extension for the engine.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class TemplateNameParser implements TemplateNameParserInterface
{
public function parse(string|TemplateReferenceInterface $name): TemplateReferenceInterface
{
if ($name instanceof TemplateReferenceInterface) {
return $name;
}
$engine = null;
if (false !== $pos = strrpos($name, '.')) {
$engine = substr($name, $pos + 1);
}
return new TemplateReference($name, $engine);
}
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', TemplateNameParserInterface::class);
/**
* TemplateNameParserInterface converts template names to TemplateReferenceInterface
* instances.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
interface TemplateNameParserInterface
{
/**
* Convert a template name to a TemplateReferenceInterface instance.
*/
public function parse(string|TemplateReferenceInterface $name): TemplateReferenceInterface;
}

View File

@@ -0,0 +1,74 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', TemplateReference::class);
/**
* Internal representation of a template.
*
* @author Victor Berchet <victor@suumit.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
class TemplateReference implements TemplateReferenceInterface
{
protected $parameters;
public function __construct(?string $name = null, ?string $engine = null)
{
$this->parameters = [
'name' => $name,
'engine' => $engine,
];
}
public function __toString(): string
{
return $this->getLogicalName();
}
public function set(string $name, string $value): static
{
if (\array_key_exists($name, $this->parameters)) {
$this->parameters[$name] = $value;
} else {
throw new \InvalidArgumentException(\sprintf('The template does not support the "%s" parameter.', $name));
}
return $this;
}
public function get(string $name): string
{
if (\array_key_exists($name, $this->parameters)) {
return $this->parameters[$name];
}
throw new \InvalidArgumentException(\sprintf('The template does not support the "%s" parameter.', $name));
}
public function all(): array
{
return $this->parameters;
}
public function getPath(): string
{
return $this->parameters['name'];
}
public function getLogicalName(): string
{
return $this->parameters['name'];
}
}

View File

@@ -0,0 +1,66 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Templating;
trigger_deprecation('symfony/templating', '6.4', '"%s" is deprecated since version 6.4 and will be removed in 7.0. Use Twig instead.', TemplateReferenceInterface::class);
/**
* Interface to be implemented by all templates.
*
* @author Victor Berchet <victor@suumit.com>
*
* @deprecated since Symfony 6.4, use Twig instead
*/
interface TemplateReferenceInterface extends \Stringable
{
/**
* Gets the template parameters.
*/
public function all(): array;
/**
* Sets a template parameter.
*
* @return $this
*
* @throws \InvalidArgumentException if the parameter name is not supported
*/
public function set(string $name, string $value): static;
/**
* Gets a template parameter.
*
* @throws \InvalidArgumentException if the parameter name is not supported
*/
public function get(string $name): string;
/**
* Returns the path to the template.
*
* By default, it just returns the template name.
*/
public function getPath(): string;
/**
* Returns the "logical" template name.
*
* The template name acts as a unique identifier for the template.
*/
public function getLogicalName(): string;
/**
* Returns the string representation as shortcut for getLogicalName().
*
* Alias of getLogicalName().
*/
public function __toString(): string;
}