SymfonyHttpDriver.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Barryvdh\Debugbar;
  3. use DebugBar\HttpDriverInterface;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Session\Session;
  6. /**
  7. * HTTP driver for Symfony Request/Session
  8. */
  9. class SymfonyHttpDriver implements HttpDriverInterface
  10. {
  11. /** @var \Illuminate\Contracts\Session\Session|\Illuminate\Session\SessionManager */
  12. protected $session;
  13. /** @var \Symfony\Component\HttpFoundation\Response */
  14. protected $response;
  15. public function __construct($session, $response = null)
  16. {
  17. $this->session = $session;
  18. $this->response = $response;
  19. }
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function setHeaders(array $headers)
  24. {
  25. if (!is_null($this->response)) {
  26. $this->response->headers->add($headers);
  27. }
  28. }
  29. /**
  30. * {@inheritDoc}
  31. */
  32. public function isSessionStarted()
  33. {
  34. if (!$this->session->isStarted()) {
  35. $this->session->start();
  36. }
  37. return $this->session->isStarted();
  38. }
  39. /**
  40. * {@inheritDoc}
  41. */
  42. public function setSessionValue($name, $value)
  43. {
  44. $this->session->put($name, $value);
  45. }
  46. /**
  47. * {@inheritDoc}
  48. */
  49. public function hasSessionValue($name)
  50. {
  51. return $this->session->has($name);
  52. }
  53. /**
  54. * {@inheritDoc}
  55. */
  56. public function getSessionValue($name)
  57. {
  58. return $this->session->get($name);
  59. }
  60. /**
  61. * {@inheritDoc}
  62. */
  63. public function deleteSessionValue($name)
  64. {
  65. $this->session->remove($name);
  66. }
  67. }