Skip to content

Commit 74b3180

Browse files
committed
refactor: add back session utils on the response interface
1 parent 9b26752 commit 74b3180

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

packages/http/src/IsResponse.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ public function removeCookie(string $key): self
8787
return $this;
8888
}
8989

90+
public function addSession(string $name, mixed $value): self
91+
{
92+
$this->session->set($name, $value);
93+
94+
return $this;
95+
}
96+
97+
public function removeSession(string $name): self
98+
{
99+
$this->session->remove($name);
100+
101+
return $this;
102+
}
103+
104+
public function flash(string|UnitEnum $key, mixed $value): self
105+
{
106+
$this->session->flash($key, $value);
107+
108+
return $this;
109+
}
110+
90111
public function setContentType(ContentType $contentType): self
91112
{
92113
$this->removeHeader(ContentType::HEADER)
@@ -108,11 +129,4 @@ public function setBody(View|string|array|Generator|null $body): self
108129

109130
return $this;
110131
}
111-
112-
public function flash(string|UnitEnum $key, mixed $value): self
113-
{
114-
$this->session->flash($key, $value);
115-
116-
return $this;
117-
}
118132
}

packages/http/src/Response.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ public function addHeader(string $key, string $value): self;
5050
*/
5151
public function removeHeader(string $key): self;
5252

53+
/**
54+
* Adds a value to the session.
55+
*/
56+
public function addSession(string $name, mixed $value): self;
57+
58+
/**
59+
* Removes a value from the session.
60+
*/
61+
public function removeSession(string $name): self;
62+
63+
/**
64+
* Flash a value to the session for the next request.
65+
*/
66+
public function flash(string|UnitEnum $key, mixed $value): self;
67+
5368
/**
5469
* Adds a cookie to the response.
5570
*/
@@ -69,9 +84,4 @@ public function setStatus(Status $status): self;
6984
* Sets the body of the response.
7085
*/
7186
public function setBody(View|string|array|Generator|null $body): self;
72-
73-
/**
74-
* Flash a value to the session for the next request.
75-
*/
76-
public function flash(string|UnitEnum $key, mixed $value): self;
7787
}

0 commit comments

Comments
 (0)