Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Converted addClosure to a public method #1

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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