Closed ibrahimch closed 1 year ago
PSR-7 is immutable so you cannot pass the request and response and assume the passed ones have not changed. Without seeing how the code is used, we cannot say the implementation is wrong. If you want to prove this is wrong, send a PR with tests .
Thank you.
I'm using it with slim3 $c['cookies'] = new Cookies\Cookies($app->getContainer()->request, $app->getContainer()->response); $app->get('test', function($req, $res){ echo $this->cookies->get('theme'); });
I agree with @harikt, looking at your code it is clear to me that it is never going to work as expected. Every time you call a method to set a cookie value you need to capture the response object and ensure that that response object is returned by the application otherwise you will never actually be setting that cookie. Because of that, get will always be empty (the set cookie header was never actually sent to the client so it will never send you a cookie value as a part of a request).
Said another way, it is not possible to create a wrapper object like this and expect it to work. The FigResponseCookies
and FigRequestCookies
classes were designed to make these objects easier to deal with. If you want the value of a request's cookie, you should just ask the copy of the request object you have at that time using:
FigRequestCookies::get($request, 'theme')
If you want to set a cookie value on a response, you should just set it on the copy of the response you have at that time, and make sure that the new value is returned.
Looking at this more closely, it looks like you are using FigRequestCookie
to set the value on the request. If your intention is to set a cookie to be sent back to the client, you should be using FigResponseCookie
and making sure that you use the return value (a modified $response
) from that point forward instead of the original response instance.
PS. I've tried it with request response too, But same error
I'm facing issue, my code is below
When I call get cookies, this returns
theme=
I'm going to die, if this will not solveI've try set with response too, but same