smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.26k stars 712 forks source link

Allow built-in modifiers override #1049

Open 2vcreation opened 3 months ago

2vcreation commented 3 months ago

A proposition to fix #1048 (and may be a part of #1011 too)

This is to prevent modifiers added by registerPlugin function from beeing silently ignored by DefaultExtension. More details in #1048

wisskid commented 3 months ago

Sorry, but I don't like this approach. The registerplugin methods are the "old" way to register plugins. I'm in favor of creating new Extensions.

Wouldn't it be easier to switch the default loading order of the Extensions? It is now: core, default, BC. We could change it to core, BC, default.

2vcreation commented 3 months ago

Thanks for your quick reply.

You're right, it would have been be easier to switch the default loading order of the Extensions : Core, BC, then Default. But it does not handle the case where we want to register a "Smarty::PLUGIN_MODIFIER" (not a compiler one), wich has an equivalent in DefaultExtension->getModifierCompiler(). For example :

//This modifier will be silently ignored, even if DefaultExtension is set at the end.
$smarty->registerPlugin(Smarty::PLUGIN_MODIFIER,"json_encode",[$this,"myJsonEncodeModifier"])

In that case DefaultExtension->getModifierCompiler() is going to take the lead anyway.

Side question : I understand you consider "registerPlugin" method as old way to register Plugins. Does this mean that it could be deprecated in a near future ?

wisskid commented 5 days ago

I understand you consider "registerPlugin" method as old way to register Plugins. Does this mean that it could be deprecated in a near future ?

Yes, it might.