SelfValidatingPassport.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Component\Security\Http\Authenticator\Passport;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Security\Http\Authenticator\Passport\Badge\BadgeInterface;
  13. use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
  14. /**
  15. * An implementation used when there are no credentials to be checked (e.g.
  16. * API token authentication).
  17. *
  18. * @author Wouter de Jong <wouter@wouterj.nl>
  19. *
  20. * @experimental in 5.2
  21. */
  22. class SelfValidatingPassport extends Passport
  23. {
  24. /**
  25. * @param UserBadge $userBadge
  26. * @param BadgeInterface[] $badges
  27. */
  28. public function __construct($userBadge, array $badges = [])
  29. {
  30. if ($userBadge instanceof UserInterface) {
  31. trigger_deprecation('symfony/security-http', '5.2', 'The 1st argument of "%s" must be an instance of "%s", support for "%s" will be removed in symfony/security-http 5.3.', __CLASS__, UserBadge::class, UserInterface::class);
  32. $this->user = $userBadge;
  33. } elseif ($userBadge instanceof UserBadge) {
  34. $this->addBadge($userBadge);
  35. } else {
  36. throw new \TypeError(sprintf('Argument 1 of "%s" must be an instance of "%s", "%s" given.', __METHOD__, UserBadge::class, get_debug_type($userBadge)));
  37. }
  38. foreach ($badges as $badge) {
  39. $this->addBadge($badge);
  40. }
  41. }
  42. }