Skip to content

Commit

Permalink
FRW-9287 Added new twig var dumper plugin. (#11241)
Browse files Browse the repository at this point in the history
FRW-9287 Added new twig var dumper plugin.
  • Loading branch information
kraal-spryker authored Dec 12, 2024
1 parent ce248b3 commit 3ad0338
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"spryker/event-dispatcher": "*",
"spryker/propel": "*",
"spryker/silex": "*",
"spryker/testify": "*"
"spryker/testify": "*",
"symfony/var-dumper": "*"
},
"suggest": {
"spryker/event-dispatcher": "If you want to use EventDispatcher plugin.",
Expand Down
3 changes: 3 additions & 0 deletions src/Spryker/Shared/Twig/Plugin/DebugTwigPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Twig\Environment;
use Twig\Extension\DebugExtension;

/**
* @deprecated Use {@link \Spryker\Shared\Twig\Plugin\VarDumperTwigPlugin} instead.
*/
class DebugTwigPlugin implements TwigPluginInterface
{
/**
Expand Down
44 changes: 44 additions & 0 deletions src/Spryker/Shared/Twig/Plugin/VarDumperTwigPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Shared\Twig\Plugin;

use Spryker\Service\Container\ContainerInterface;
use Spryker\Shared\TwigExtension\Dependency\Plugin\TwigPluginInterface;
use Symfony\Bridge\Twig\Extension\DumpExtension;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Twig\Environment;

class VarDumperTwigPlugin implements TwigPluginInterface
{
/**
* @var string
*/
protected const SERVICE_DEBUG = 'debug';

/**
* {@inheritDoc}
* - Added pretty print for debug extension.
*
* @api
*
* @param \Twig\Environment $twig
* @param \Spryker\Service\Container\ContainerInterface $container
*
* @return \Twig\Environment
*/
public function extend(Environment $twig, ContainerInterface $container): Environment
{
if ($container->has(static::SERVICE_DEBUG) === false || $container->get(static::SERVICE_DEBUG) === false) {
return $twig;
}

$twig->addExtension(new DumpExtension(new VarCloner()));

return $twig;
}
}

0 comments on commit 3ad0338

Please sign in to comment.