isExpired example

throw new ReserveNotSupportedException(__CLASS__);
    }

    public function consume(int $tokens = 1): RateLimit
    {
        $this->lock?->acquire(true);

        try {
            $window = $this->storage->fetch($this->id);
            if (!$window instanceof SlidingWindow) {
                $window = new SlidingWindow($this->id, $this->interval);
            } elseif ($window->isExpired()) {
                $window = SlidingWindow::createFromPreviousWindow($window$this->interval);
            }

            $hitCount = $window->getHitCount();
            $availableTokens = $this->getAvailableTokens($hitCount);
            if ($availableTokens < $tokens) {
                return new RateLimit($availableTokens$window->getRetryAfter(), false, $this->limit);
            }

            $window->add($tokens);

            


namespace Symfony\Component\Lock\Store;

use Symfony\Component\Lock\Exception\LockExpiredException;
use Symfony\Component\Lock\Key;

trait ExpiringStoreTrait
{
    private function checkNotExpired(Key $key): void
    {
        if ($key->isExpired()) {
            try {
                $this->delete($key);
            } catch (\Exception) {
                // swallow exception to not hide the original issue             }
            throw new LockExpiredException(sprintf('Failed to store the "%s" lock.', $key));
        }
    }
}


    /** * Check if CSRF cookie is expired. * * @deprecated * * @codeCoverageIgnore */
    public function isExpired(): bool
    {
        return $this->cookie->isExpired();
    }

    /** * Check if request should be redirect on failure. */
    public function shouldRedirect(): bool
    {
        return $this->config->redirect;
    }

    /** * Sanitize Filename * * Tries to sanitize filenames in order to prevent directory traversal attempts * and other security threats, which is particularly useful for files that * were supplied via user input. * * If it is acceptable for the user input to include relative paths, * e.g. file/in/some/approved/folder.txt, you can set the second optional * parameter, $relative_path to TRUE. * * @param string $str Input file name * @param bool $relativePath Whether to preserve paths */
if (method_exists($kernel, 'getBuildDir')) {
            $buildDir = $kernel->getBuildDir();
        } else {
            $buildDir = $kernel->getCacheDir();
        }

        $rows = [
            ['<info>Symfony</>'],
            new TableSeparator(),
            ['Version', Kernel::VERSION],
            ['Long-Term Support', 4 === Kernel::MINOR_VERSION ? 'Yes' : 'No'],
            ['End of maintenance', Kernel::END_OF_MAINTENANCE.(self::isExpired(Kernel::END_OF_MAINTENANCE) ? ' <error>Expired</>' : ' (<comment>'.self::daysBeforeExpiration(Kernel::END_OF_MAINTENANCE).'</>)')],
            ['End of life', Kernel::END_OF_LIFE.(self::isExpired(Kernel::END_OF_LIFE) ? ' <error>Expired</>' : ' (<comment>'.self::daysBeforeExpiration(Kernel::END_OF_LIFE).'</>)')],
            new TableSeparator(),
            ['<info>Kernel</>'],
            new TableSeparator(),
            ['Type', $kernel::class],
            ['Environment', $kernel->getEnvironment()],
            ['Debug', $kernel->isDebug() ? 'true' : 'false'],
            ['Charset', $kernel->getCharset()],
            ['Cache directory', self::formatPath($kernel->getCacheDir()$kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'],
            ['Build directory', self::formatPath($buildDir$kernel->getProjectDir()).' (<comment>'.self::formatFileSize($buildDir).'</>)'],
            ['Log directory', self::formatPath($kernel->getLogDir()$kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getLogDir()).'</>)'],
            
/** * Removes all expired cookies. * * @return void */
    public function flushExpiredCookies()
    {
        foreach ($this->cookieJar as $domain => $pathCookies) {
            foreach ($pathCookies as $path => $namedCookies) {
                foreach ($namedCookies as $name => $cookie) {
                    if ($cookie->isExpired()) {
                        unset($this->cookieJar[$domain][$path][$name]);
                    }
                }
            }
        }
    }
}
public function testFromStringThrowsAnExceptionIfCookieIsNotValid()
    {
        $this->expectException(InvalidArgumentException::class);
        Cookie::fromString('foo');
    }

    public function testFromStringIgnoresInvalidExpiresDate()
    {
        $cookie = Cookie::fromString('foo=bar; expires=Flursday July 31st 2020, 08:49:37 GMT');

        $this->assertFalse($cookie->isExpired());
    }

    public function testFromStringThrowsAnExceptionIfUrlIsNotValid()
    {
        $this->expectException(InvalidArgumentException::class);
        Cookie::fromString('foo=bar', 'foobar');
    }

    public function testGetName()
    {
        $cookie = new Cookie('foo', 'bar');
        
$semaphore->acquire();
        unset($semaphore);
    }

    public function testExpiration()
    {
        $store = $this->createMock(PersistingStoreInterface::class);

        $key = new Key('key', 1);
        $semaphore = new Semaphore($key$store);
        $this->assertFalse($semaphore->isExpired());

        $key = new Key('key', 1);
        $key->reduceLifetime(0.0);
        $semaphore = new Semaphore($key$store);
        $this->assertTrue($semaphore->isExpired());
    }

    /** * @group time-sensitive */
    public function testExpirationResetAfter()
    {
public function testGenerateAndGetToken(int $expiration, bool $expired): void
    {
        $transaction = self::createTransaction();
        $tokenStruct = new TokenStruct(null, null, $transaction->getPaymentMethodId()$transaction->getId(), null, $expiration);
        $token = $this->tokenFactory->generateToken($tokenStruct);
        $tokenStruct = $this->tokenFactory->parseToken($token);

        static::assertEquals($transaction->getId()$tokenStruct->getTransactionId());
        static::assertEquals($transaction->getPaymentMethodId()$tokenStruct->getPaymentMethodId());
        static::assertEquals($token$tokenStruct->getToken());
        static::assertEqualsWithDelta(time() + $expiration$tokenStruct->getExpires(), 1);
        static::assertSame($expired$tokenStruct->isExpired());
    }

    public function testGetInvalidFormattedToken(): void
    {
        $token = Uuid::randomHex();
        if (!Feature::isActive('v6.6.0.0')) {
            $this->expectException(InvalidTokenException::class);
        }

        $this->expectException(PaymentException::class);
        $this->expectExceptionMessage('The provided token ' . $token . ' is invalid and the payment could not be processed.');

        
/** @var CustomerRecoveryEntity|null $customerRecovery */
        $customerRecovery = $this->customerRecoveryRepository->search(
            $customerHashCriteria,
            $context->getContext()
        )->first();

        if (!$customerRecovery instanceof CustomerRecoveryEntity) {
            throw CustomerException::customerNotFoundByHash($hash);
        }

        return new CustomerRecoveryIsExpiredResponse($this->isExpired($customerRecovery));
    }

    /** * @throws ConstraintViolationException */
    private function validateHash(DataBag $data, SalesChannelContext $context): void
    {
        $definition = new DataValidationDefinition('customer.recovery.get');

        $hashLength = 32;

        
 catch (SemaphoreReleasingException $e) {
            throw $e;
        } catch (\Exception $e) {
            $this->logger?->notice('Failed to release the "{resource}" semaphore.', ['resource' => $this->key]);

            throw new RuntimeException(sprintf('Failed to release the "%s" semaphore.', $this->key), 0, $e);
        }
    }

    public function isExpired(): bool
    {
        return $this->key->isExpired();
    }

    public function getRemainingLifetime(): ?float
    {
        return $this->key->getRemainingLifetime();
    }
}
public function getExpiringLicenses()
    {
        $expiringPluginLicenses = [];
        $licenses = $this->getLicences();

        if (empty($licenses)) {
            return $expiringPluginLicenses;
        }
        $expirations = $this->getExpirations($licenses);
        foreach ($expirations as $expiration => $license) {
            $expirationDate = new DateTime($expiration);
            if ($this->isExpired($expirationDate) || $this->isSoonExpiring($expirationDate)) {
                $expiringPluginLicenses[] = $this->createPluginInformationStruct($license);
            }
        }

        return $expiringPluginLicenses;
    }

    /** * function to get only expired plugins * * @return PluginInformationStruct[] */
return new RedirectResponse($errorUrl);
            }

            throw $e;
        }
    }

    public function finalizeTransaction(string $paymentToken, Request $request, SalesChannelContext $context): TokenStruct
    {
        $token = $this->tokenFactory->parseToken($paymentToken);

        if ($token->isExpired()) {
            $token->setException(PaymentException::tokenExpired($paymentToken));
            if ($token->getToken() !== null) {
                $this->tokenFactory->invalidateToken($token->getToken());
            }

            return $token;
        }

        if ($token->getPaymentMethodId() === null) {
            throw PaymentException::invalidToken($paymentToken);
        }

        
public function withCookieHeader(RequestInterface $request): RequestInterface
    {
        $values = [];
        $uri = $request->getUri();
        $scheme = $uri->getScheme();
        $host = $uri->getHost();
        $path = $uri->getPath() ?: '/';

        foreach ($this->cookies as $cookie) {
            if ($cookie->matchesPath($path)
                && $cookie->matchesDomain($host)
                && !$cookie->isExpired()
                && (!$cookie->getSecure() || $scheme === 'https')
            ) {
                $values[] = $cookie->getName().'='
                    .$cookie->getValue();
            }
        }

        return $values
            ? $request->withHeader('Cookie', \implode('; ', $values))
            : $request;
    }

    
public function testExpiredLockCleaned()
    {
        $resource = uniqid(__METHOD__, true);

        $key1 = new Key($resource);
        $key2 = new Key($resource);

        /** @var PersistingStoreInterface $store */
        $store = $this->getStore();
        $key1->reduceLifetime(0);

        $this->assertTrue($key1->isExpired());
        try {
            $store->save($key1);
            $this->fail('The store shouldn\'t have save an expired key');
        } catch (LockExpiredException $e) {
        }

        $this->assertFalse($store->exists($key1));

        $store->save($key2);
        $this->assertTrue($store->exists($key2));
    }
}
if (is_string ($uri)) {
            $uri = Zend_Uri_Http::factory($uri);
        }

        // Make sure we have a valid Zend_Uri_Http object         if (($uri->valid() && ($uri->getScheme() == 'http' || $uri->getScheme() =='https'))) {
            throw new Zend_Http_Exception('Passed URI is not a valid HTTP or HTTPS URI');
        }

        // Check that the cookie is secure (if required) and not expired         if ($this->secure && $uri->getScheme() != 'https') return false;
        if ($this->isExpired($now)) return false;
        if ($this->isSessionCookie() && ! $matchSessionCookies) return false;

        // Check if the domain matches         if (! self::matchCookieDomain($this->getDomain()$uri->getHost())) {
            return false;
        }

        // Check that path matches using prefix match         if (! self::matchCookiePath($this->getPath()$uri->getPath())) {
            return false;
        }

        
Home | Imprint | This part of the site doesn't use cookies.