vendor/gesdinet/jwt-refresh-token-bundle/Command/ClearInvalidRefreshTokensCommand.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the GesdinetJWTRefreshTokenBundle package.
  4.  *
  5.  * (c) Gesdinet <http://www.gesdinet.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Gesdinet\JWTRefreshTokenBundle\Command;
  11. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  12. use Symfony\Component\Console\Input\InputArgument;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. /**
  16.  * Class ClearInvalidRefreshTokensCommand.
  17.  */
  18. class ClearInvalidRefreshTokensCommand extends ContainerAwareCommand
  19. {
  20.     /**
  21.      * @see Command
  22.      */
  23.     protected function configure()
  24.     {
  25.         $this
  26.             ->setName('gesdinet:jwt:clear')
  27.             ->setDescription('Clear invalid refresh tokens.')
  28.             ->setDefinition(array(
  29.                 new InputArgument('datetime'InputArgument::OPTIONAL),
  30.             ));
  31.     }
  32.     /**
  33.      * @see Command
  34.      */
  35.     protected function execute(InputInterface $inputOutputInterface $output)
  36.     {
  37.         $datetime $input->getArgument('datetime');
  38.         if (null === $datetime) {
  39.             $datetime = new \DateTime();
  40.         } else {
  41.             $datetime = new \DateTime($datetime);
  42.         }
  43.         $manager $this->getContainer()->get('gesdinet.jwtrefreshtoken.refresh_token_manager');
  44.         $revokedTokens $manager->revokeAllInvalid($datetime);
  45.         foreach ($revokedTokens as $revokedToken) {
  46.             $output->writeln(sprintf('Revoke <comment>%s</comment>'$revokedToken->getRefreshToken()));
  47.         }
  48.     }
  49. }