CsrfTokenManagerAdapter.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. use Symfony\Component\Security\Csrf\CsrfToken;
  12. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  13. /**
  14. * Adapter for using the new token generator with the old interface.
  15. *
  16. * @author Bernhard Schussek <bschussek@gmail.com>
  17. *
  18. * @deprecated since version 2.4, to be removed in 3.0.
  19. */
  20. class CsrfTokenManagerAdapter implements CsrfProviderInterface
  21. {
  22. private $tokenManager;
  23. public function __construct(CsrfTokenManagerInterface $tokenManager)
  24. {
  25. $this->tokenManager = $tokenManager;
  26. }
  27. public function getTokenManager($triggerDeprecationError = true)
  28. {
  29. if ($triggerDeprecationError) {
  30. @trigger_error('The '.__METHOD__.' method 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);
  31. }
  32. return $this->tokenManager;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function generateCsrfToken($intention)
  38. {
  39. @trigger_error('The '.__METHOD__.' method 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);
  40. return $this->tokenManager->getToken($intention)->getValue();
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function isCsrfTokenValid($intention, $token)
  46. {
  47. @trigger_error('The '.__METHOD__.' method 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);
  48. return $this->tokenManager->isTokenValid(new CsrfToken($intention, $token));
  49. }
  50. }