Created
October 19, 2020 11:12
-
-
Save romainnorberg/a68e5bfa229d974f9b79027be3cbd058 to your computer and use it in GitHub Desktop.
Symfony Twig Closure Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace AppBundle\Extension; | |
use Twig\Extension\AbstractExtension; | |
use Twig\TwigFunction; | |
class ClosureExtension extends AbstractExtension | |
{ | |
public function getFunctions() | |
{ | |
return [ | |
new TwigFunction('closure', [$this, 'executeClosure']) | |
]; | |
} | |
public function executeClosure(\Closure $closure, $arguments) | |
{ | |
return $closure(...$arguments); | |
} | |
public function getName(): string | |
{ | |
return 'closure_twig_extension'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AppBundle\Extension\ClosureExtension: | |
public: false | |
tags: | |
- { name: twig.extension } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
closure(<closure>, [<parameters>]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment