rcrowe / TwigBridge

Give the power of Twig to Laravel
MIT License
895 stars 165 forks source link

TwigBridge 0.14.* not compatible with Twig 3.9.0 #440

Closed barryp closed 2 months ago

barryp commented 2 months ago

This commit in Twig 3.9.0 https://github.com/twigphp/Twig/commit/54d34b969b256ecd1c7aa3416205206d87686ef7 removes functions that TwigBridge is using like the call to twig_get_attribute() from src/Node/GetAttrNode.php

I think some code is going to need to be rewritten. For now probably the thing to do is update twigbridge's composer.json to maybe require something like:

     "twig/twig": "~3.0 <=3.8.0",
barryvdh commented 2 months ago

So we just have to replace that call with \Twig\Extension\CoreExtension::getAttribute right?

barryp commented 2 months ago

Seems like it.

I was just now looking for other twig_*() functions that TwigBridge was calling and didn't find any.

If you make that change then you'd have to require twig >= 3.9.0 because the CoreExtension::getAttribute() isn't present in older twigs.

uandco commented 2 months ago

Faced the same issue, the workaround is to add that extra twig dependency at the root level instead of relying on TwigBridge to require it with the too broad ~3.0, while TwigBridge's own requirement is fixed.

bernhardh commented 2 months ago

If you make that change then you'd have to require twig >= 3.9.0 because the CoreExtension::getAttribute() isn't present in older twigs.

Yes. But if you wanna keep backward compatibilty, just do:

if (! function_exists("twig_get_attribute")) {
    function twig_get_attribute(
        $env,
        $source,
        $object,
        $item,
        $arguments,
        $type,
        $isDefinedTest,
        $ignoreStrictCheck,
        $sandboxed,
        $lineno
    )
    {
        return \Twig\Extension\CoreExtension::getAttribute(
            $env,
            $source,
            $object,
            $item,
            $arguments,
            $type,
            $isDefinedTest,
            $ignoreStrictCheck,
            $sandboxed,
            $lineno);
    }
}

This works btw as a hotfix as well until this packages gets an update ;)

barryvdh commented 2 months ago

Fixed in https://github.com/rcrowe/TwigBridge/releases/tag/v0.14.3