Skip to content

Commit

Permalink
Converted addClosure to a public method
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseydiloreto committed May 18, 2024
1 parent a91d4c9 commit bdc0695
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Craft;
use craft\console\Application as CraftConsoleApp;
use craft\web\Application as CraftWebApp;
use craft\web\twig\Environment;
use craft\web\View;
use nystudio107\closure\helpers\Reflection as ReflectionHelper;
use nystudio107\closure\twig\ClosureExpressionParser;
Expand Down Expand Up @@ -106,14 +107,16 @@ protected function registerEventHandlers(): void
* Add our ClosureExpressionParser to default $allowArrow = true to let
* arrow function closures work outside of Twig filter contexts
*
* @param Environment|null $twig
* @return void
*/
protected function addClosure(): void
public function addClosure(?Environment $twig = null): void
{
if ($this->closureAdded) {
return;
}
$twig = Craft::$app->getView()->getTwig();
// Custom environment if specified, otherwise Craft default
$twig = $twig ?? Craft::$app->getView()->getTwig();
// Get the parser object used by Twig
try {
$parserReflection = ReflectionHelper::getReflectionProperty($twig, 'parser');
Expand Down

0 comments on commit bdc0695

Please sign in to comment.