-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymfonyHttpDriver.php
More file actions
88 lines (73 loc) · 1.92 KB
/
SymfonyHttpDriver.php
File metadata and controls
88 lines (73 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
namespace DebugBar\Bridge\Symfony;
use DebugBar\HttpDriverInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
/**
* HTTP driver for Symfony Request/Session
*
*/
class SymfonyHttpDriver implements HttpDriverInterface
{
protected SessionInterface $session;
protected ?Response $response;
public function __construct(SessionInterface $session, ?Response $response = null)
{
$this->session = $session;
$this->response = $response;
}
public function setResponse(Response $response): void
{
$this->response = $response;
}
/**
* {@inheritDoc}
*/
public function setHeaders(array $headers): void
{
if (!is_null($this->response)) {
$this->response->headers->add($headers);
}
}
public function output(string $content): void
{
if (!is_null($this->response)) {
$existingContent = $this->response->getContent();
$content = $existingContent ? $existingContent . $content : $content;
$this->response->setContent($content);
}
}
public function isSessionStarted(): bool
{
if (!$this->session->isStarted()) {
$this->session->start();
}
return $this->session->isStarted();
}
public function setSessionValue(string $name, mixed $value): void
{
$this->session->set($name, $value);
}
/**
* {@inheritDoc}
*/
public function hasSessionValue(string $name): bool
{
return $this->session->has($name);
}
/**
* {@inheritDoc}
*/
public function getSessionValue(string $name): mixed
{
return $this->session->get($name);
}
/**
* {@inheritDoc}
*/
public function deleteSessionValue(string $name): void
{
$this->session->remove($name);
}
}