CakePHP
  • 文档
    • 手册
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 商品
  • 旅程
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 通讯
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助和支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Middleware
      • Session
      • TestSuite
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

CookieCollection 类

Cookie 集合

提供一个 Cookie 对象的不可变集合。向集合添加或删除元素将返回一个新的集合,您必须保留它。

命名空间: Cake\Http\Cookie

属性摘要

  • $cookies protected
    array<string,Cake\Http\Cookie\CookieInterface>

    Cookie 对象

方法摘要

  • __construct() public

    构造函数

  • __get() public

    获取第一个名为 的 Cookie,如果存在。

  • __isset() public

    检查是否存在名为 的 Cookie。

  • add() public

    添加一个 Cookie 并获取更新后的集合。

  • addFromResponse() public

    创建一个新的集合,其中包含来自响应的 Cookie。

  • addToRequest() public

    将与路径/域/过期时间匹配的 Cookie 添加到请求中。

  • checkCookies() protected

    检查数组中是否只有有效的 Cookie 对象。

  • count() public

    获取集合中 Cookie 的数量。

  • createFromHeader() public static

    从一组 Set-Cookie 头部创建 Cookie 集合。

  • createFromServerRequest() public static

    从 ServerRequest 中的 Cookie 创建一个新集合。

  • findMatchingCookies() protected

    查找与方案、主机和路径匹配的 Cookie。

  • get() public

    获取第一个名为 的 Cookie。

  • getIterator() public

    获取迭代器。

  • has() public

    检查是否存在名为 的 Cookie。

  • remove() public

    创建一个新的集合,其中所有与匹配的 Cookie 都被删除。

  • removeExpiredCookies() protected

    从集合中删除过期的 Cookie。

方法详情

__construct() ¶ public

__construct(arrayCake\Http\Cookie\CookieInterface> $cookies = [])

构造函数

参数
arrayCake\Http\Cookie\CookieInterface> $cookies optional

Cookie 对象数组

__get() ¶ public

__get(string $name): Cake\Http\Cookie\CookieInterface|null

获取第一个名为 的 Cookie,如果存在。

参数
string $name

Cookie 的名称。

返回值
Cake\Http\Cookie\CookieInterface|null

__isset() ¶ public

__isset(string $name): bool

检查是否存在名为 的 Cookie。

参数
string $name

要检查的 Cookie 名称。

返回值
bool

add() ¶ public

add(Cake\Http\Cookie\CookieInterface $cookie): static

添加一个 Cookie 并获取更新后的集合。

Cookie 是按 ID 存储的。这意味着如果一个 Cookie 集合用于多个域的 Cookie,则可能存在重复的 Cookie。这会影响 get()、has() 和 remove() 的行为。

参数
Cake\Http\Cookie\CookieInterface $cookie

要添加的 Cookie 实例。

返回值
static

addFromResponse() ¶ public

addFromResponse(Psr\Http\Message\ResponseInterface $response, Psr\Http\Message\RequestInterface $request): static

创建一个新的集合,其中包含来自响应的 Cookie。

参数
Psr\Http\Message\ResponseInterface $response

要从中提取 Cookie 的响应。

Psr\Http\Message\RequestInterface $request

要从中获取 Cookie 上下文的请求。

返回值
static

addToRequest() ¶ public

addToRequest(Psr\Http\Message\RequestInterface $request, array $extraCookies = []): Psr\Http\Message\RequestInterface

将与路径/域/过期时间匹配的 Cookie 添加到请求中。

这允许 CookieCollections 在 HTTP 客户端场景中用作“Cookie Jar”。当调用此方法时,与请求的域 + 路径匹配且未过期的 Cookie 将被应用于请求。

参数
Psr\Http\Message\RequestInterface $request

要更新的请求。

array $extraCookies optional

要添加到请求中的附加 Cookie 的关联数组。当您有来自集合外部的 Cookie 数据想要发送时,这很有用。

返回值
Psr\Http\Message\RequestInterface

checkCookies() ¶ protected

checkCookies(arrayCake\Http\Cookie\CookieInterface> $cookies): void

检查数组中是否只有有效的 Cookie 对象。

参数
arrayCake\Http\Cookie\CookieInterface> $cookies

Cookie 对象数组

返回值
void
抛出
InvalidArgumentException

count() ¶ public

count(): int

获取集合中 Cookie 的数量。

返回值
int

createFromHeader() ¶ public static

createFromHeader(list<string> $header, array<string, mixed> $defaults = []): static

从一组 Set-Cookie 头部创建 Cookie 集合。

参数
list<string> $header

一组 Set-Cookie 头部值数组。

array<string, mixed> $defaults optional

默认属性。

返回值
static

createFromServerRequest() ¶ public static

createFromServerRequest(Psr\Http\Message\ServerRequestInterface $request): static

从 ServerRequest 中的 Cookie 创建一个新集合。

参数
Psr\Http\Message\ServerRequestInterface $request

要从中提取 Cookie 数据的请求。

返回值
static

findMatchingCookies() ¶ protected

findMatchingCookies(string $scheme, string $host, string $path): array<string, mixed>

查找与方案、主机和路径匹配的 Cookie。

参数
string $scheme

要匹配的 HTTP 方案。

string $host

要匹配的主机。

string $path

要匹配的路径。

返回值
array<string, mixed>

get() ¶ public

get(string $name): Cake\Http\Cookie\CookieInterface

获取第一个名为 的 Cookie。

参数
string $name

Cookie 的名称。

返回值
Cake\Http\Cookie\CookieInterface
抛出
InvalidArgumentException
如果 Cookie 未找到。

getIterator() ¶ public

getIterator(): Traversable<string,Cake\Http\Cookie\CookieInterface>

获取迭代器。

返回值
Traversable<string,Cake\Http\Cookie\CookieInterface>

has() ¶ public

has(string $name): bool

检查是否存在名为 的 Cookie。

参数
string $name

要检查的 Cookie 名称。

返回值
bool

remove() ¶ public

remove(string $name): static

创建一个新的集合,其中所有与匹配的 Cookie 都被删除。

如果 Cookie 不在集合中,此方法将不执行任何操作。

参数
string $name

要删除的 Cookie 的名称。

返回值
static

removeExpiredCookies() ¶ protected

removeExpiredCookies(string $host, string $path): void

从集合中删除过期的 Cookie。

参数
string $host

要检查过期 Cookie 的主机。

string $path

要检查过期 Cookie 的路径。

返回值
void

属性详细信息

$cookies ¶ 受保护

Cookie 对象

类型
array<string,Cake\Http\Cookie\CookieInterface>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 手册
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 通讯
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成