Drupal investigation

SessionTestTrait.php 811B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Drupal\Tests;
  3. use Symfony\Component\HttpFoundation\Request;
  4. /**
  5. * Provides methods to generate and get session name in tests.
  6. */
  7. trait SessionTestTrait {
  8. /**
  9. * The name of the session cookie.
  10. *
  11. * @var string
  12. */
  13. protected $sessionName;
  14. /**
  15. * Generates a session cookie name.
  16. *
  17. * @param string $data
  18. * The data to generate session name.
  19. */
  20. protected function generateSessionName($data) {
  21. $prefix = (Request::createFromGlobals()->isSecure() ? 'SSESS' : 'SESS');
  22. $this->sessionName = $prefix . substr(hash('sha256', $data), 0, 32);
  23. }
  24. /**
  25. * Returns the session name in use on the child site.
  26. *
  27. * @return string
  28. * The name of the session cookie.
  29. */
  30. protected function getSessionName() {
  31. return $this->sessionName;
  32. }
  33. }