> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/cookie/contracts.md).

# Contracts

## Public methods

```php
all(): array
has(string $key): bool
get(string $key)
set(string $key, $value = '', int $time = 0, string $path = '/', string $domain = '', bool $secure = false, bool $httponly = false): void
delete(string $key, string $path = '/'): void
flush(): void
```

## Read contract

### `all()`

Returns all currently stored cookies after decrypting each value.

Use it when you need the full cookie bag in application form instead of encrypted transport form.

### `has()`

Returns `true` only when the key exists and the stored value is not empty.

That means these values behave as absent:

* `''`
* `'0'`
* `0`
* `false`
* `null`

### `get()`

Returns the decrypted value for a present cookie.

Returns `null` when `has()` is false.

## Write contract

### `set()`

Writes the cookie in two places:

* updates the in-memory storage used by the current request
* schedules the outgoing browser cookie with `setcookie(...)`

The lifetime argument is relative, not absolute. Passing `3600` means "expire in one hour".

Values are serialized and encrypted before storage.

### `delete()`

Removes the key from in-memory storage and sends an expired cookie header when the cookie is considered present.

Deletion only exposes a `path` argument. Domain, secure, and HttpOnly flags are not repeated here.

### `flush()`

Deletes every cookie key currently available in the wrapper by calling `delete()` for each one.

## Failure behavior

`all()`, `get()`, and `set()` depend on encryption helpers. If encryption or decryption fails, the package surfaces that exception.

There is no plaintext fallback mode.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/cookie/contracts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
