CookieStore example

public function __construct($config)
    {
        // Default to a non-caching page.         // Also ensures that a Cache-control header exists.         $this->noCache();

        // We need CSP object even if not enabled to avoid calls to non existing methods         $this->CSP = Services::csp();

        $this->CSPEnabled = $config->CSPEnabled;

        $this->cookieStore = new CookieStore([]);

        $cookie = config(CookieConfig::class);

        Cookie::setDefaults($cookie);

        // Default to an HTML Content-Type. Devs can override if needed.         $this->setContentType('text/html');
    }

    /** * Turns "pretend" mode on or off to aid in testing. * * Note that this is not a part of the interface so * should not be relied on outside of internal testing. * * @return $this * * @testTag only available to test code */

    function cookies(array $cookies = [], bool $getGlobal = true): CookieStore
    {
        if ($getGlobal) {
            return Services::response()->getCookieStore();
        }

        return new CookieStore($cookies);
    }
}

if (function_exists('csrf_token')) {
    /** * Returns the CSRF token name. * Can be used in Views when building hidden inputs manually, * or used in javascript vars when using APIs. */
    function csrf_token(): string
    {
        
/** * Copies any cookies from the global Response instance * into this RedirectResponse. Useful when you've just * set a cookie but need ensure that's actually sent * with the response instead of lost. * * @return $this|RedirectResponse */
    public function withCookies()
    {
        $this->cookieStore = new CookieStore(Services::response()->getCookies());

        return $this;
    }

    /** * Copies any headers from the global Response instance * into this RedirectResponse. Useful when you've just * set a header be need to ensure its actually sent * with the redirect response. * * @return $this|RedirectResponse */
Home | Imprint | This part of the site doesn't use cookies.