smarty-php / smarty

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

PHP9 support (strftime) #810

Open wisskid opened 2 years ago

wisskid commented 2 years ago

strftime

Provide a wrapper for strftime (to be removed in PHP9), possibly using alphp/strftime. This will require a new major, since alphp/strftime requires ext-intl.

lkppo commented 1 year ago

Why try to emulate strftime() and for how long? You might as well align with PHP by offering two formatters [one for date() and another for Intl] or none.

eczio commented 1 year ago

I think that there is definitely no need to depend on the !mandatory use of certain extensions such as 'ext-intl' and especially third-party libraries, there should be a way to implement this functionality without this for the new Smarty 5, this would be the best option. As a last resort, if the functionality for some reason cannot be implemented in full as before, which is unlikely, then it is necessary to check for the presence of this extensions and if it is not present, use a different implementation. Also the vast majority of template engines and even large frameworks do not require the use of any extensions to work correctly, which is correct and does not scare away some part of users.

wisskid commented 1 year ago

Please see https://github.com/smarty-php/smarty/issues/672#issuecomment-1159360142 and below. It's not as straightforward as you might think. But if you see a solution that does not require an extension, this would of course be preferred.

eczio commented 1 year ago

Well, I hope that we can still find some solution without using an additional 'ext-intl' extension. In any case, I think it would be absolutely correct not to require it forcibly and if it is not present, for example, use an implementation similar with symfony/polyfill-intl-icu with only supports the 'en' locale or something else, it will be enough for the vast majority of users.

wxiaoguang commented 9 months ago

Agree with lkppo, I think maybe it's time to get rid of strftime if it is not a must. Developers who still need strftime could polyfill it by themselves? (By reading some old issues & comments, I didn't figure out why strftime should be a must for new Smarty releases)

happit-jannes commented 1 day ago

We've temporarily bridged the gap with https://packagist.org/packages/php81_bc/strftime .

We also changed servers from Debian based to Alpine Linux, and locales aren't really supported in Alpine, so we wanted an intl solution anyway. Installing ext-intl was a no-brainer for us. We're still on Smarty 3, and use register_modifier to override the default date_format to keep our thousands of templates backwards compatible.

function dateFormat($date, string $format, ?string $locale = null): string 
{
    return \PHP81_BC\strftime($format, $date, $locale);
}

$smarty->register_modifier('date_format', 'dateFormat');