![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/vendor/magento/module-security/Model/UserExpiration/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Security\Model\UserExpiration; use Magento\Framework\App\ObjectManager; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Framework\Stdlib\DateTime\Timezone\LocalizedDateToUtcConverterInterface; use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Framework\Validator\AbstractValidator; use Magento\Framework\Validator\NotEmpty; use Magento\Framework\Validator\ValidatorChain; /** * Validates that the expires_at field is later than the current date/time. */ class Validator extends AbstractValidator { /** * @var TimezoneInterface */ private $timezone; /** * @var DateTime */ private $dateTime; /** * @var LocalizedDateToUtcConverterInterface */ private $localizedDateToUtcConverter; /** * @param TimezoneInterface $timezone * @param DateTime $dateTime * @param LocalizedDateToUtcConverterInterface|null $localizedDateToUtcConverter */ public function __construct( TimezoneInterface $timezone, DateTime $dateTime, ?LocalizedDateToUtcConverterInterface $localizedDateToUtcConverter = null ) { $this->timezone = $timezone; $this->dateTime = $dateTime; $this->localizedDateToUtcConverter = $localizedDateToUtcConverter ?: ObjectManager::getInstance() ->get(LocalizedDateToUtcConverterInterface::class); } /** * Ensure that the given date is later than the current date. * * @param string $value * @return bool * @throws \Exception */ public function isValid($value) { $this->_clearMessages(); $messages = []; $label = 'Expiration date'; if (ValidatorChain::is($value, NotEmpty::class)) { $utcExpiresAt = $this->localizedDateToUtcConverter->convertLocalizedDateToUtc($value); $currentTime = $this->dateTime->gmtTimestamp(); $expiresAt = $this->timezone->date($utcExpiresAt)->getTimestamp(); if ($expiresAt < $currentTime) { $messages['expires_at'] = __('"%1" must be later than the current date.', $label); } } $this->_addMessages($messages); return empty($messages); } }