|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace HttpSoft\Cookie; |
| 6 | + |
| 7 | +use Countable; |
| 8 | +use IteratorAggregate; |
| 9 | +use Psr\Http\Message\ResponseInterface; |
| 10 | + |
| 11 | +interface CookieManagerInterface extends Countable, IteratorAggregate |
| 12 | +{ |
| 13 | + /** |
| 14 | + * Sets a cookie. |
| 15 | + * |
| 16 | + * @param CookieInterface $cookie the cookie to set. |
| 17 | + */ |
| 18 | + public function set(CookieInterface $cookie): void; |
| 19 | + |
| 20 | + /** |
| 21 | + * Sets multiple cookies. |
| 22 | + * |
| 23 | + * @param CookieInterface[] $cookies multiple cookies to set. |
| 24 | + */ |
| 25 | + public function setMultiple(array $cookies): void; |
| 26 | + |
| 27 | + /** |
| 28 | + * Gets the cookie with the specified name. |
| 29 | + * |
| 30 | + * @param string $name the cookie name. |
| 31 | + * @return CookieInterface|null the cookie or `null` if the cookie does not exist. |
| 32 | + */ |
| 33 | + public function get(string $name): ?CookieInterface; |
| 34 | + |
| 35 | + /** |
| 36 | + * Gets all cookies. |
| 37 | + * |
| 38 | + * @return CookieInterface[] all cookies, or an empty array if no cookies exist. |
| 39 | + */ |
| 40 | + public function getAll(): array; |
| 41 | + |
| 42 | + /** |
| 43 | + * Gets the value of the named cookie. |
| 44 | + * |
| 45 | + * @param string $name the cookie name. |
| 46 | + * @return string|null the value of the named cookie or `null` if the cookie does not exist. |
| 47 | + */ |
| 48 | + public function getValue(string $name): ?string; |
| 49 | + |
| 50 | + /** |
| 51 | + * Whether a cookie with the specified name exists. |
| 52 | + * |
| 53 | + * @param string $name the cookie name. |
| 54 | + * @return bool whether the named cookie exists. |
| 55 | + */ |
| 56 | + public function has(string $name): bool; |
| 57 | + |
| 58 | + /** |
| 59 | + * Removes a cookie. |
| 60 | + * |
| 61 | + * @param string $name the name of the cookie to be removed. |
| 62 | + * @return CookieInterface|null cookie that is removed. |
| 63 | + */ |
| 64 | + public function remove(string $name): ?CookieInterface; |
| 65 | + |
| 66 | + /** |
| 67 | + * Removes all cookies. |
| 68 | + */ |
| 69 | + public function clear(): void; |
| 70 | + |
| 71 | + /** |
| 72 | + * Sets all cookie to the response and returns a clone instance of the response with the cookies set. |
| 73 | + * |
| 74 | + * This method must be called before emitting the response. |
| 75 | + * |
| 76 | + * @link https://github.com/php-fig/http-message/blob/master/src/ResponseInterface.php |
| 77 | + * |
| 78 | + * @param ResponseInterface $response |
| 79 | + * @param bool $removeResponseCookies whether to remove previously set cookies from the response. |
| 80 | + * @return ResponseInterface response with cookies set. |
| 81 | + */ |
| 82 | + public function send(ResponseInterface $response, bool $removeResponseCookies = true): ResponseInterface; |
| 83 | +} |
0 commit comments