Augmentation vers version 3.3.0

This commit is contained in:
Gauvain Boiché
2020-03-31 15:31:03 +02:00
parent d926806907
commit a1864c0414
2618 changed files with 406015 additions and 31377 deletions

View File

@@ -27,22 +27,24 @@ use Twig\TwigFunction;
class DumpExtension extends AbstractExtension
{
private $cloner;
private $dumper;
public function __construct(ClonerInterface $cloner)
public function __construct(ClonerInterface $cloner, HtmlDumper $dumper = null)
{
$this->cloner = $cloner;
$this->dumper = $dumper;
}
public function getFunctions()
{
return array(
new TwigFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)),
);
return [
new TwigFunction('dump', [$this, 'dump'], ['is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true]),
];
}
public function getTokenParsers()
{
return array(new DumpTokenParser());
return [new DumpTokenParser()];
}
public function getName()
@@ -53,31 +55,31 @@ class DumpExtension extends AbstractExtension
public function dump(Environment $env, $context)
{
if (!$env->isDebug()) {
return;
return null;
}
if (2 === \func_num_args()) {
$vars = array();
$vars = [];
foreach ($context as $key => $value) {
if (!$value instanceof Template) {
$vars[$key] = $value;
}
}
$vars = array($vars);
$vars = [$vars];
} else {
$vars = \func_get_args();
unset($vars[0], $vars[1]);
}
$dump = fopen('php://memory', 'r+b');
$dumper = new HtmlDumper($dump, $env->getCharset());
$this->dumper = $this->dumper ?: new HtmlDumper();
$this->dumper->setCharset($env->getCharset());
foreach ($vars as $value) {
$dumper->dump($this->cloner->cloneVar($value));
$this->dumper->dump($this->cloner->cloneVar($value), $dump);
}
rewind($dump);
return stream_get_contents($dump);
return stream_get_contents($dump, -1, 0);
}
}