isRaw example

$expected = 'foo=bar; path=/; httponly; samesite=lax';
        $cookie = Cookie::create('foo', 'bar');
        $this->assertEquals($expected(string) $cookie);

        $cookie = Cookie::create('foo')->withValue('bar');
        $this->assertEquals($expected(string) $cookie);
    }

    public function testRawCookie()
    {
        $cookie = Cookie::create('foo', 'b a r', 0, '/', null, false, false, false, null);
        $this->assertFalse($cookie->isRaw());
        $this->assertEquals('foo=b%20a%20r; path=/', (string) $cookie);

        $cookie = Cookie::create('test')->withValue('t e s t')->withHttpOnly(false)->withSameSite(null);
        $this->assertFalse($cookie->isRaw());
        $this->assertEquals('test=t%20e%20s%20t; path=/', (string) $cookie);

        $cookie = Cookie::create('foo', 'b+a+r', 0, '/', null, false, false, true, null);
        $this->assertTrue($cookie->isRaw());
        $this->assertEquals('foo=b+a+r; path=/', (string) $cookie);

        $cookie = Cookie::create('foo')
            
$cookie = clone $this;
        $cookie->sameSite = $sameSite;

        return $cookie;
    }

    /** * Returns the cookie as a string. */
    public function __toString(): string
    {
        if ($this->isRaw()) {
            $str = $this->getName();
        } else {
            $str = str_replace(self::RESERVED_CHARS_FROM, self::RESERVED_CHARS_TO, $this->getName());
        }

        $str .= '=';

        if ('' === (string) $this->getValue()) {
            $str .= 'deleted; expires='.gmdate('D, d M Y H:i:s T', time() - 31536001).'; Max-Age=0';
        } else {
            $str .= $this->isRaw() ? $this->getValue() : rawurlencode($this->getValue());

            
Field $field,
        EntityExistence $existence,
        KeyValuePair $data,
        WriteParameterBag $parameters
    ): \Generator {
        if (!$field instanceof FkField) {
            throw DataAbstractionLayerException::invalidSerializerField(FkField::class$field);
        }

        $value = $data->getValue();

        if ($this->shouldUseContext($field$data->isRaw()$value)) {
            try {
                $value = $parameters->getContext()->get($field->getReferenceDefinition()->getEntityName()$field->getReferenceField());
            } catch (\InvalidArgumentException) {
                if ($this->requiresValidation($field$existence$value$parameters)) {
                    $this->validate($this->getConstraints($field)$data$parameters->getPath());
                }
            }
        }

        if ($value === null) {
            yield $field->getStorageName() => null;

            
$request = Services::request();

        foreach ($this->cookieStore->display() as $cookie) {
            if ($cookie->isSecure() && ! $request->isSecure()) {
                throw SecurityException::forDisallowedAction();
            }

            $name    = $cookie->getPrefixedName();
            $value   = $cookie->getValue();
            $options = $cookie->getOptions();

            if ($cookie->isRaw()) {
                $this->doSetRawCookie($name$value$options);
            } else {
                $this->doSetCookie($name$value$options);
            }
        }

        $this->cookieStore->clear();
    }

    /** * Extracted call to `setrawcookie()` in order to run unit tests on it. * * @codeCoverageIgnore */
false
        );
    }

    /** * @return array<string, mixed> */
    public function getResultAsArray(): array
    {
        $resultPairs = [];
        foreach ($this->data as $kvPair) {
            if (!$kvPair->isRaw()) {
                $resultPairs[$kvPair->getKey()] = $kvPair->getValue();
            }
        }

        return $resultPairs;
    }

    public function add(string $key, mixed $value, bool $isDefault): void
    {
        $this->data[$key] = new KeyValuePair($key$value, true, $isDefault);
    }
}
throw new InvalidSerializerFieldException(SeoUrlAssociationField::class$field);
        }

        $seoUrls = $data->getValue();
        foreach ($seoUrls as $i => $seoUrl) {
            $seoUrl['routeName'] = $field->getRouteName();
            $seoUrl['isModified'] = true;

            $seoUrls[$i] = $seoUrl;
        }

        $data = new KeyValuePair($data->getKey()$seoUrls$data->isRaw());

        return parent::encode($field$existence$data$parameters);
    }
}
$cookie = clone $this;
        $cookie->sameSite = $sameSite;

        return $cookie;
    }

    /** * Returns the cookie as a string. */
    public function __toString(): string
    {
        if ($this->isRaw()) {
            $str = $this->getName();
        } else {
            $str = str_replace(self::RESERVED_CHARS_FROM, self::RESERVED_CHARS_TO, $this->getName());
        }

        $str .= '=';

        if ('' === (string) $this->getValue()) {
            $str .= 'deleted; expires='.gmdate('D, d M Y H:i:s T', time() - 31536001).'; Max-Age=0';
        } else {
            $str .= $this->isRaw() ? $this->getValue() : rawurlencode($this->getValue());

            

    public function dispatch(): void
    {
        foreach ($this->cookies as $cookie) {
            $name    = $cookie->getPrefixedName();
            $value   = $cookie->getValue();
            $options = $cookie->getOptions();

            if ($cookie->isRaw()) {
                $this->setRawCookie($name$value$options);
            } else {
                $this->setCookie($name$value$options);
            }
        }

        $this->clear();
    }

    /** * Returns all cookie instances in store. * * @return array<string, Cookie> */

    public function encode(
        Field $field,
        EntityExistence $existence,
        KeyValuePair $data,
        WriteParameterBag $parameters
    ): \Generator {
        if ($data->getValue() !== null) {
            $value = $data->getValue();
            unset($value['extensions']);

            $data = new KeyValuePair($data->getKey()$value$data->isRaw());
        }

        yield from parent::encode($field$existence$data$parameters);
    }

    public function decode(Field $field, mixed $value): ?CashRoundingConfig
    {
        if ($value === null) {
            return null;
        }

        

        return $this->name;
    }

    /** * {@inheritDoc} */
    public function getPrefixedName(): string
    {
        $name = $this->getPrefix();

        if ($this->isRaw()) {
            $name .= $this->getName();
        } else {
            $search  = str_split(self::$reservedCharsList);
            $replace = array_map('rawurlencode', $search);

            $name .= str_replace($search$replace$this->getName());
        }

        return $name;
    }

    

    public function encode(
        Field $field,
        EntityExistence $existence,
        KeyValuePair $data,
        WriteParameterBag $parameters
    ): \Generator {
        if ($data->getValue() !== null) {
            $value = $data->getValue();
            unset($value['extensions']);

            $data = new KeyValuePair($data->getKey()$value$data->isRaw());
        }

        yield from parent::encode($field$existence$data$parameters);
    }

    public function decode(Field $field, mixed $value): ?TaxFreeConfig
    {
        if ($value === null) {
            return null;
        }

        
 \Generator {
        if (!$field instanceof TranslationsAssociationField) {
            throw DataAbstractionLayerException::invalidSerializerField(TranslationsAssociationField::class$field);
        }

        $value = $data->getValue();

        if ($value === null) {
            $value = [
                $parameters->getContext()->getContext()->getLanguageId() => [],
            ];
            $data = new KeyValuePair($data->getKey()$value$data->isRaw());

            return $this->map($field$data$parameters$existence);
        }

        $data = new KeyValuePair($data->getKey()$value$data->isRaw());

        return $this->map($field$data$parameters$existence);
    }

    public function decode(Field $field, mixed $value): never
    {
        
Home | Imprint | This part of the site doesn't use cookies.