TestBrowserToken.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Bundle\FrameworkBundle\Test;
  11. use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. /**
  14. * A very limited token that is used to login in tests using the KernelBrowser.
  15. *
  16. * @author Wouter de Jong <wouter@wouterj.nl>
  17. */
  18. class TestBrowserToken extends AbstractToken
  19. {
  20. private $firewallName;
  21. public function __construct(array $roles = [], UserInterface $user = null, string $firewallName = 'main')
  22. {
  23. parent::__construct($roles);
  24. if (null !== $user) {
  25. $this->setUser($user);
  26. }
  27. $this->firewallName = $firewallName;
  28. }
  29. public function getFirewallName(): string
  30. {
  31. return $this->firewallName;
  32. }
  33. public function getCredentials()
  34. {
  35. return null;
  36. }
  37. public function __serialize(): array
  38. {
  39. return [$this->firewallName, parent::__serialize()];
  40. }
  41. public function __unserialize(array $data): void
  42. {
  43. [$this->firewallName, $parentData] = $data;
  44. parent::__unserialize($parentData);
  45. }
  46. }