CsrfProviderAdapter.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\Form\Extension\Csrf\CsrfProvider;
  11. @trigger_error('The '.__NAMESPACE__.'\CsrfProviderAdapter class is deprecated since Symfony 2.4 and will be removed in version 3.0. Use the Symfony\Component\Security\Csrf\CsrfTokenManager class instead.', E_USER_DEPRECATED);
  12. use Symfony\Component\Form\Exception\BadMethodCallException;
  13. use Symfony\Component\Security\Csrf\CsrfToken;
  14. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  15. /**
  16. * Adapter for using old CSRF providers where the new {@link CsrfTokenManagerInterface}
  17. * is expected.
  18. *
  19. * @author Bernhard Schussek <bschussek@gmail.com>
  20. *
  21. * @deprecated since version 2.4, to be removed in 3.0.
  22. */
  23. class CsrfProviderAdapter implements CsrfTokenManagerInterface
  24. {
  25. private $csrfProvider;
  26. public function __construct(CsrfProviderInterface $csrfProvider)
  27. {
  28. $this->csrfProvider = $csrfProvider;
  29. }
  30. public function getCsrfProvider()
  31. {
  32. return $this->csrfProvider;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function getToken($tokenId)
  38. {
  39. return new CsrfToken($tokenId, $this->csrfProvider->generateCsrfToken($tokenId));
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function refreshToken($tokenId)
  45. {
  46. throw new BadMethodCallException('Not supported');
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function removeToken($tokenId)
  52. {
  53. throw new BadMethodCallException('Not supported');
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function isTokenValid(CsrfToken $token)
  59. {
  60. return $this->csrfProvider->isCsrfTokenValid($token->getId(), $token->getValue());
  61. }
  62. }