SessionCsrfProvider.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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__.'\SessionCsrfProvider is deprecated since Symfony 2.4 and will be removed in version 3.0. Use the Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage class instead.', E_USER_DEPRECATED);
  12. use Symfony\Component\HttpFoundation\Session\Session;
  13. /**
  14. * This provider uses a Symfony Session object to retrieve the user's
  15. * session ID.
  16. *
  17. * @see DefaultCsrfProvider
  18. *
  19. * @author Bernhard Schussek <bschussek@gmail.com>
  20. *
  21. * @deprecated since version 2.4, to be removed in 3.0.
  22. * Use {@link \Symfony\Component\Security\Csrf\CsrfTokenManager} in
  23. * combination with {@link \Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage}
  24. * instead.
  25. */
  26. class SessionCsrfProvider extends DefaultCsrfProvider
  27. {
  28. protected $session;
  29. /**
  30. * Initializes the provider with a Session object and a secret value.
  31. *
  32. * A recommended value for the secret is a generated value with at least
  33. * 32 characters and mixed letters, digits and special characters.
  34. *
  35. * @param Session $session The user session from which the session ID is returned
  36. * @param string $secret A secret value included in the CSRF token
  37. */
  38. public function __construct(Session $session, $secret)
  39. {
  40. parent::__construct($secret);
  41. $this->session = $session;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. protected function getSessionId()
  47. {
  48. $this->session->start();
  49. return $this->session->getId();
  50. }
  51. }