Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added withCookie. #499

Closed
wants to merge 4 commits into from
Closed

Added withCookie. #499

wants to merge 4 commits into from

Conversation

limingxinleo
Copy link
Member

No description provided.

@limingxinleo
Copy link
Member Author

#498

@limingxinleo
Copy link
Member Author

@cexll 你看一下这个pr,应该满足你的要求

@cexll
Copy link
Contributor

cexll commented Sep 1, 2019

我学习一下,

@cexll
Copy link
Contributor

cexll commented Sep 1, 2019

namespace App\Controller;

private function cookie(Cookie $cookie)
    {
        $response = $this->response()->withCookie($cookie);
        Context::set(Psr7ResponseInterface::class, $response);
        return $this;
    }
    /**
     * @return \Hyperf\HttpMessage\Server\Response
     */
    private function response()
    {
        return Context::get(Psr7ResponseInterface::class);
    }

    public function setCookie(string $name, string $value='', int $expire=0, string $path='/', string $domain='', bool $secure=false, bool $httpOnly=true)
    {
        $cookie = new Cookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
        $this->cookie($cookie);
    }

我用你说的,设置cookie可以不用return

$this->setCookie();

@limingxinleo
Copy link
Member Author

你不return就不能withCookie()->withCookie()。这么操作了

@cexll
Copy link
Contributor

cexll commented Sep 1, 2019

你不return就不能withCookie()->withCookie()。这么操作了

我之前pr的不return就返回不出去,按照你说的 写到 App\Controller\Controller, 其他地方直接能用,不知道这样会不会有啥问题

@limingxinleo
Copy link
Member Author

我重新开个pr来修改这里

@limingxinleo limingxinleo deleted the pr/498 branch September 1, 2019 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants