* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ namespace PrestaShopBundle\Twig; use DateTime; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; /** * Provides helper functions in Twig for formatting data using context locale */ class LocaleExtension extends AbstractExtension { /** * @var string */ private $contextDateFormatLite; /** * @param string $contextDateFormatLite */ public function __construct(string $contextDateFormatLite) { $this->contextDateFormatLite = $contextDateFormatLite; } /** * {@inheritdoc} */ public function getFunctions() { return [ new TwigFunction( 'format_date', function ($date) { return (new DateTime($date))->format($this->contextDateFormatLite); } ), ]; } }