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

Add a PSR-4 loading script to allow Smarty to be used without Composer #1017

Closed scottchiefbaker closed 6 months ago

scottchiefbaker commented 6 months ago

This is to help address #999. I created a fake "class" script that acts as a PSR-4 loading script. For Smarty 3.x and 4.x I would instantiate Smarty with:

require("include/smarty/libs/Smarty.class.php");
$smarty = new Smarty();

With this new script I can instantiate Smarty 5.x with:

require("include/smarty/src/Smarty.class.php");
$smarty = new Smarty\Smarty();

This should help backwards compatible usability for old users like me. It'd be great if this script could live in /libs/ to be 99% backwards compatible, but that directory doesn't exist anymore.

scottchiefbaker commented 6 months ago

Would you consider letting me recreate the /libs/ directory and putting this file in there? That would make this almost a drop in replacement for Smart 3.x and 4.x for us non-composer users. Then the only difference would be:

$smarty = new Smarty(); // Smarty 3.x and 4.x

// Versus

$smarty = new Smarty\Smarty(); // Smarty 5.x
wisskid commented 6 months ago

Yes, that seems fine!

scottchiefbaker commented 6 months ago

Excellent. I recreated the libs/ folder and put the PSR-4 file in there. I've tested the changes and everything seems to be working now.

scottchiefbaker commented 6 months ago

PR updated with your requested fixes.

scottchiefbaker commented 6 months ago

@wisskid do you need anything else from me on this?

wisskid commented 6 months ago

@scottchiefbaker this has been merged (with a changelog) as https://github.com/smarty-php/smarty/pull/1019. Thanks!