vendor/symfonycasts/reset-password-bundle/src/Util/ResetPasswordCleaner.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the SymfonyCasts ResetPasswordBundle package.
  4.  * Copyright (c) SymfonyCasts <https://symfonycasts.com/>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace SymfonyCasts\Bundle\ResetPassword\Util;
  9. use SymfonyCasts\Bundle\ResetPassword\Persistence\ResetPasswordRequestRepositoryInterface;
  10. /**
  11.  * @author Jesse Rushlow <jr@rushlow.dev>
  12.  * @author Ryan Weaver   <ryan@symfonycasts.com>
  13.  *
  14.  * @internal
  15.  *
  16.  * @final
  17.  */
  18. class ResetPasswordCleaner
  19. {
  20.     /**
  21.      * @var bool Enable/disable garbage collection
  22.      */
  23.     private $enabled;
  24.     private $repository;
  25.     public function __construct(ResetPasswordRequestRepositoryInterface $repositorybool $enabled true)
  26.     {
  27.         $this->repository $repository;
  28.         $this->enabled $enabled;
  29.     }
  30.     /**
  31.      * Clears expired reset password requests from persistence.
  32.      *
  33.      * Enable/disable in configuration. Calling with $force = true
  34.      * will attempt to remove expired requests regardless of
  35.      * configuration setting.
  36.      */
  37.     public function handleGarbageCollection(bool $force false): int
  38.     {
  39.         if ($this->enabled || $force) {
  40.             return $this->repository->removeExpiredResetPasswordRequests();
  41.         }
  42.         return 0;
  43.     }
  44. }