PHPackages                             weijiajia/saloonphp-cookie-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. weijiajia/saloonphp-cookie-plugin

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

weijiajia/saloonphp-cookie-plugin
=================================

A cookie management plugin for Saloon PHP, allowing for easy cookie handling in your API integrations.

0851↓33.3%PHP

Since May 15Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/jackchang1025/saloonphp-cookie-plugin)[ Packagist](https://packagist.org/packages/weijiajia/saloonphp-cookie-plugin)[ RSS](/packages/weijiajia-saloonphp-cookie-plugin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Saloon PHP Cookie Plugin
========================

[](#saloon-php-cookie-plugin)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c0fb84767aac324fc17fa8b66c20ccbd4400974342eed8bdd1f73179538693d7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765696a69616a69612f73616c6f6f6e7068702d636f6f6b69652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weijiajia/saloonphp-cookie-plugin)[![Total Downloads](https://camo.githubusercontent.com/d23be70763b663eb19dca25bb1be65b00d43d63caf93d976666315b57901a0ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765696a69616a69612f73616c6f6f6e7068702d636f6f6b69652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weijiajia/saloonphp-cookie-plugin)

A cookie management plugin for [Saloon PHP](https://github.com/saloonphp/saloon), allowing for easy cookie handling in your API integrations.

English Documentation
---------------------

[](#english-documentation)

### Installation

[](#installation)

You can install the package via composer:

```
composer require weijiajia/saloonphp-cookie-plugin
```

### Requirements

[](#requirements)

- PHP 8.0 or higher
- Saloon PHP v3.0 or higher

### Usage

[](#usage)

#### 1. Implement the CookieJarInterface

[](#1-implement-the-cookiejarinterface)

First, implement the `CookieJarInterface` in your connector or request class:

```
use Weijiajia\SaloonphpCookiePlugin\Contracts\CookieJarInterface;
use GuzzleHttp\Cookie\CookieJarInterface as GuzzleCookieJarInterface;

class YourConnector extends Connector implements CookieJarInterface
{
    // Implementation required by CookieJarInterface
    public function getCookieJar(): ?GuzzleCookieJarInterface
    {
        // Return your cookie jar or null
    }
}
```

#### 2. Use the HasCookie trait

[](#2-use-the-hascookie-trait)

Add the `HasCookie` trait to your connector or request class:

```
use Weijiajia\SaloonphpCookiePlugin\HasCookie;

class YourConnector extends Connector implements CookieJarInterface
{
    use HasCookie;

    // Rest of your class implementation
}
```

#### 3. Working with cookies

[](#3-working-with-cookies)

You can set cookies in various ways:

```
// Set cookies using an array
$connector->withCookies([
    'name' => 'value',
    'another_cookie' => 'another_value',
]);

// Or use a GuzzleHttp CookieJar
$cookieJar = new \GuzzleHttp\Cookie\CookieJar();
// Configure your cookie jar...
$connector->withCookies($cookieJar);

// You can also use strict mode
$connector->withCookies($cookies, true); // Second parameter enables strict mode
```

#### 4. Access the cookie jar

[](#4-access-the-cookie-jar)

You can access the cookie jar at any time:

```
$cookieJar = $connector->getCookieJar();
```

### Example

[](#example)

```
use Saloon\Http\Connector;
use Weijiajia\SaloonphpCookiePlugin\HasCookie;
use Weijiajia\SaloonphpCookiePlugin\Contracts\CookieJarInterface;
use GuzzleHttp\Cookie\CookieJarInterface as GuzzleCookieJarInterface;

class ApiConnector extends Connector implements CookieJarInterface
{
    use HasCookie;

    public function resolveBaseUrl(): string
    {
        return 'https://api.example.com';
    }
}

// Using the connector with cookies
$connector = new ApiConnector();
$connector->withCookies([
    'session_id' => '123456789',
    'user_token' => 'abcdef123456',
]);

// Make requests, and cookies will be handled automatically
$response = $connector->send(new YourRequest());
```

---

中文文档
----

[](#中文文档)

### 安装

[](#安装)

您可以通过 Composer 安装此插件：

```
composer require weijiajia/saloonphp-cookie-plugin
```

### 要求

[](#要求)

- PHP 8.0 或更高版本
- Saloon PHP v3.0 或更高版本

### 使用方法

[](#使用方法)

#### 1. 实现 CookieJarInterface

[](#1-实现-cookiejarinterface)

首先，在您的连接器或请求类中实现 `CookieJarInterface`：

```
use Weijiajia\SaloonphpCookiePlugin\Contracts\CookieJarInterface;
use GuzzleHttp\Cookie\CookieJarInterface as GuzzleCookieJarInterface;

class YourConnector extends Connector implements CookieJarInterface
{
    // CookieJarInterface 要求实现的方法
    public function getCookieJar(): ?GuzzleCookieJarInterface
    {
        // 返回您的 cookie jar 或 null
    }
}
```

#### 2. 使用 HasCookie trait

[](#2-使用-hascookie-trait)

在您的连接器或请求类中添加 `HasCookie` trait：

```
use Weijiajia\SaloonphpCookiePlugin\HasCookie;

class YourConnector extends Connector implements CookieJarInterface
{
    use HasCookie;

    // 类的其余实现
}
```

#### 3. 处理 cookies

[](#3-处理-cookies)

您可以通过多种方式设置 cookies：

```
// 使用数组设置 cookies
$connector->withCookies([
    'name' => 'value',
    'another_cookie' => 'another_value',
]);

// 或者使用 GuzzleHttp CookieJar
$cookieJar = new \GuzzleHttp\Cookie\CookieJar();
// 配置您的 cookie jar...
$connector->withCookies($cookieJar);

// 您还可以使用严格模式
$connector->withCookies($cookies, true); // 第二个参数启用严格模式
```

#### 4. 访问 cookie jar

[](#4-访问-cookie-jar)

您可以随时访问 cookie jar：

```
$cookieJar = $connector->getCookieJar();
```

### 示例

[](#示例)

```
use Saloon\Http\Connector;
use Weijiajia\SaloonphpCookiePlugin\HasCookie;
use Weijiajia\SaloonphpCookiePlugin\Contracts\CookieJarInterface;
use GuzzleHttp\Cookie\CookieJarInterface as GuzzleCookieJarInterface;

class ApiConnector extends Connector implements CookieJarInterface
{
    use HasCookie;

    public function resolveBaseUrl(): string
    {
        return 'https://api.example.com';
    }
}

// 使用带有 cookies 的连接器
$connector = new ApiConnector();
$connector->withCookies([
    'session_id' => '123456789',
    'user_token' => 'abcdef123456',
]);

// 发送请求，cookies 将自动处理
$response = $connector->send(new YourRequest());
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/636557533fde1107bb301eca908de1c17c9ea7073d5c9c0fbad725ccd0800bde?d=identicon)[jackchang1025](/maintainers/jackchang1025)

---

Top Contributors

[![422066139](https://avatars.githubusercontent.com/u/1780162?v=4)](https://github.com/422066139 "422066139 (3 commits)")

### Embed Badge

![Health badge](/badges/weijiajia-saloonphp-cookie-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/weijiajia-saloonphp-cookie-plugin/health.svg)](https://phpackages.com/packages/weijiajia-saloonphp-cookie-plugin)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
