addCookie example

return $cookieGroupCollection;
    }

    private function assignCookiesToGroups(CookieCollection $cookieCollection, CookieGroupCollection $cookieGroupCollection): void
    {
        /** @var CookieStruct $cookie */
        foreach ($cookieCollection as $cookie) {
            $cookieGroup = $cookieGroupCollection->getGroupByName($cookie->getGroupName());

            $cookie->setGroup($cookieGroup);
            $cookieGroup->addCookie($cookie);
        }
    }

    private function addDefaultGroups(CookieGroupCollection $cookieGroupCollection): void
    {
        $snippetNamespace = $this->snippetManager->getNamespace('frontend/cookie_consent/groups');

        $cookieGroupCollection->add(new CookieGroupStruct(CookieGroupStruct::TECHNICAL, $snippetNamespace->get('technical/title')$snippetNamespace->get('technical/description'), true));
        $cookieGroupCollection->add(new CookieGroupStruct(CookieGroupStruct::COMFORT, $snippetNamespace->get('comfort/title')$snippetNamespace->get('comfort/description')));
        $cookieGroupCollection->add(new CookieGroupStruct(CookieGroupStruct::PERSONALIZATION, $snippetNamespace->get('personalization/title')$snippetNamespace->get('personalization/description') ?? ''));
        $cookieGroupCollection->add(new CookieGroupStruct(CookieGroupStruct::STATISTICS, $snippetNamespace->get('statistics/title')$snippetNamespace->get('statistics/description') ?? ''));
        


            return $this;
        }

        if ($value !== null && $this->config['encodecookies']) {
            $value = urlencode($value);
        }

        if (isset($this->cookiejar)) {
            if ($cookie instanceof Zend_Http_Cookie) {
                $this->cookiejar->addCookie($cookie);
            } elseif (is_string($cookie) && $value !== null) {
                $cookie = Zend_Http_Cookie::fromString("{$cookie}={$value}",
                                                       $this->uri,
                                                       $this->config['encodecookies']);
                $this->cookiejar->addCookie($cookie);
            }
        } else {
            if ($cookie instanceof Zend_Http_Cookie) {
                $name = $cookie->getName();
                $value = $cookie->getValue();
                $cookie = $name;
            }
public function addCookiesFromResponse($response$ref_uri$encodeValue = true)
    {
        if ($response instanceof Zend_Http_Response) {
            throw new Zend_Http_Exception('$response is expected to be a Response object, ' .
                gettype($response) . ' was passed');
        }

        $cookie_hdrs = $response->getHeader('Set-Cookie');

        if (is_array($cookie_hdrs)) {
            foreach ($cookie_hdrs as $cookie) {
                $this->addCookie($cookie$ref_uri$encodeValue);
            }
        } elseif (is_string($cookie_hdrs)) {
            $this->addCookie($cookie_hdrs$ref_uri$encodeValue);
        }
    }

    /** * Get all cookies in the cookie jar as an array * * @param int $ret_as Whether to return cookies as objects of Zend_Http_Cookie or as strings * @return array|string */
Home | Imprint | This part of the site doesn't use cookies.