Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

php - Downgrading Twig: Uncaught Error: Call to undefined method TwigEnvironment

I'm using Symfony 4.4 on a project and I need to use stfalcontinymce. Since I'm on SF4 I need the version 2.4. So I did this:

composer require stfalcon/tinymce-bundle=2.4

But then I get this error:

!!  11:03:44 CRITICAL  [php] Uncaught Error: Class 'Twig_Extension' not found ["exception" => Error { …}]
!!
!!  In StfalconTinymceExtension.php line 13:
!!                                                                        
!!    Attempted to load class "Twig_Extension" from the global namespace. 
!!    Did you forget a "use" statement? 

Someone told me that it's because this version doesn't get along with Twig 3 so I need to downgrade my Twig version. I then did this to downgrade Twig:

composer require twig/twig=2

But then I get this error:

     13:14:07 CRITICAL  [php] Uncaught Error: Call to undefined method TwigEnvironment::registerUndefinedTokenPa
rserCallback() ["exception" => Error { …}]
!!
!!  In srcApp_KernelDevDebugContainer.php line 2040:
!!  
!!    Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "TwigEnvironm ent".
!!    Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?

I tried adding in composer.json

"twig/extensions": "*"

Then composer install, then running the command:

composer require stfalcon/tinymce-bundle=2.4 -W

And I get this error:

!!  13:49:04 CRITICAL  [php] Uncaught Error: Call to undefined method 

TwigEnvironment::registerUndefinedTokenParserCallback() ["exception" => Error { …}]
!!
!!  In srcApp_KernelDevDebugContainer.php line 2045:
!!  
!!    Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "TwigEnvironment".
!!    Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?

I'm really lost here. Can someone help? thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your executed commands don't seem to be possible on my system at all since there will be version constraint conflicts.

Instead of restricting to one version for your dependencies, you should use a constraint.

Your require in composer.json may contain something like the following

        "twig/twig": "^2",
        "stfalcon/tinymce-bundle": "2.4.*",
        "twig/extra-bundle": "^2"

The constraints are explained here. But the ^2 basically means >= 2.x.x and < 3.0.0

For the tinymce bundle I used the above because of the this GitHub issue

Furthermore twig/extensions seems to be deprecated, and this GitHub issue mentions twig/extra-bundle which is needed and may be its replacement.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...