14 private array $cookie = [];
23 public function setCookie(
string $name,
string $value, array $attr ): void {
27 $index = strtoupper( $name );
29 if ( isset( $this->cookie[$index] ) ) {
30 $this->cookie[$index]->set( $value, $attr );
32 $this->cookie[$index] =
new Cookie( $name, $value, $attr );
42 foreach ( $this->cookie as $c ) {
43 $serialized = $c->serializeToHttpRequest(
$path, $domain );
45 $cookies[] = $serialized;
49 return implode(
'; ', $cookies );
59 $bit = array_map(
'trim', explode(
';', $cookie ) );
61 $parts = explode(
'=', array_shift( $bit ), 2 );
63 $value = $parts[1] ??
'';
66 foreach ( $bit as $piece ) {
67 $parts = explode(
'=', $piece, 2 );
68 $attr[ strtolower( $parts[0] ) ] = $parts[1] ??
true;
71 if ( !isset( $attr[
'domain'] ) ) {
72 $attr[
'domain'] = $domain;
77 $this->setCookie( $name, $value, $attr );
Cookie jar to use with MWHttpRequest.
setCookie(string $name, string $value, array $attr)
Set a cookie in the cookie jar.
serializeToHttpRequest(string $path, string $domain)
parseCookieResponseHeader(string $cookie, string $domain)
Parse the content of an Set-Cookie HTTP Response header.
Cookie for HTTP requests.
static validateCookieDomain(string $domain, ?string $originDomain=null)
Return the true if the cookie is valid is valid.