Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Error: Uncaught Logic Exception -- twig 3.10 deprecation @ timber/src/Twig.php #2994

Closed
pgnd opened this issue May 11, 2024 · 3 comments

Comments

@pgnd
Copy link

pgnd commented May 11, 2024

with

composer show timber/timber
	name     : timber/timber
	descrip. : Create WordPress themes with beautiful OOP code and the Twig Template Engine
	keywords : templating, themes, timber, twig, wordpress
	versions : * 2.x-dev
	released : 2024-05-07, this week
	type     : library

and update to just-released Twig 3.10

composer show twig/twig
	name     : twig/twig
	descrip. : Twig, the flexible, fast, and secure template language for PHP
	keywords : templating
	versions : * v3.10.0
	released : 2024-05-11, today
	type     : library
	...

access to my site front-page, fires a new fatal error; e.g.,

( ! ) Fatal error: Uncaught LogicException: You must call "setEnvironment()" before calling "Twig\Extension\EscaperExtension::setEscaper()". in /srv/www/wp.app/web/app/themes/test-flynt/vendor/twig/twig/src/Extension/EscaperExtension.php on line 127

( ! ) LogicException: You must call "setEnvironment()" before calling "Twig\Extension\EscaperExtension::setEscaper()". in /srv/www/wp.app/web/app/themes/test-flynt/vendor/twig/twig/src/Extension/EscaperExtension.php on line 127

the call stack identifies,

.../Twig.php:558

	Twig\Extension\EscaperExtension->setEscaper( $strategy = 'esc_url', $callable = class Closure { } )

checking Timber src,

cat  ./vendor/timber/timber/src/Twig.php

	        if (\class_exists('Twig\Extension\EscaperExtension')) {
	            $escaper_extension = $twig->getExtension('Twig\Extension\EscaperExtension');
558	            $escaper_extension->setEscaper('esc_url', $esc_url);
	            $escaper_extension->setEscaper('wp_kses_post', $wp_kses_post);
	            $escaper_extension->setEscaper('esc_html', $esc_html);
	            $escaper_extension->setEscaper('esc_js', $esc_js);
	        }
	        return $twig;
	    }

and @ twig src,

https://github.com/twigphp/Twig/blob/3.x/src/Extension/EscaperExtension.php#L127

the deprecation causing the error,

	...
114	    /**
	     * Defines a new escaper to be used via the escape filter.
	     *
	     * @param string                        $strategy The strategy name that should be used as a strategy in the escape call
	     * @param callable(Environment, string) $callable A valid PHP callable
	     *
	     * @deprecated since Twig 3.10
	     */
	    public function setEscaper($strategy, callable $callable)
	    {
	        trigger_deprecation('twig/twig', '3.10', 'The "%s()" method is deprecated, use the "Twig\Runtime\EscaperRuntime::setEscaper()" method instead (be warned that Environment is not passed anymore to the callable).', __METHOD__);

	        if (!isset($this->environment)) {
127	            throw new \LogicException(sprintf('You must call "setEnvironment()" before calling "%s()".', __METHOD__));
	        }
	        if (!isset($this->escaper)) {
	            throw new \LogicException(sprintf('You must call "setEscaperRuntime()" before calling "%s()".', __METHOD__));
	        }

	        $this->escapers[$strategy] = $callable;
	        $callable = function ($string, $charset) use ($callable) {
	            return $callable($this->environment, $string);
	        };

	        $this->escaper->setEscaper($strategy, $callable);
	    }
	...
@pgnd pgnd changed the title Fata Error: Uncaught Logic Exception -- twig 3.10 deprecation @ timber/src/Twig.php Fatal Error: Uncaught Logic Exception -- twig 3.10 deprecation @ timber/src/Twig.php May 11, 2024
@rmens
Copy link
Contributor

rmens commented May 11, 2024

Just opened the same issue a few minutes earlier with a temporary fix #2993

@pgnd
Copy link
Author

pgnd commented May 11, 2024

drop back to last release, @

https://github.com/twigphp/Twig/tags

composer require \
 timber/timber \
 twig/twig:"3.9.3"

composer show timber/timber | grep versions
	versions : * v2.1.0
composer show twig/twig | grep versions
	versions : * v3.9.3

cures, as expected

@Levdbas
Copy link
Member

Levdbas commented May 13, 2024

Duplicate of #2993. We'll track in that ticket if any upgrades are needed in our codebase.

@Levdbas Levdbas closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants