PHPackages                             small/swoole-resource-client-bundle - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. small/swoole-resource-client-bundle

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

small/swoole-resource-client-bundle
===================================

Symfony bundle client for small-resource-server, using Swoole HttpClient.

1.0.0(8mo ago)014MITPHPPHP &gt;=8.3

Since Sep 3Pushed 8mo agoCompare

[ Source](https://github.com/sebk69/small-swoole-resource-client-bundle)[ Packagist](https://packagist.org/packages/small/swoole-resource-client-bundle)[ RSS](/packages/small-swoole-resource-client-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (10)Versions (2)Used By (0)

Small Swoole Resource Client Bundle
===================================

[](#small-swoole-resource-client-bundle)

[![](img/tests-badge.png)](img/tests-badge.png) [![](img/coverage-badge.png)](img/coverage-badge.png)

A lightweight Symfony bundle that provides a typed client to interact with the [small-resource-server](https://github.com/sebk69/small-resource-server), using a Swoole-based HTTP client.

- **Namespace:** `Small\SwooleResourceClientBundle`
- **Requires:** PHP ≥ 8.3, Symfony ≥7.2, `small/swoole-symfony-http-client`
- **Config keys:** `server_uri`, `api_key`

Why
---

[](#why)

- Acquire and release **resource locks** via a simple API
- Read / write **JSON data** for a named resource + selector
- Fully compatible with Symfony HttpClient contracts; the factory accepts any `HttpClientInterface`

Installation
------------

[](#installation)

```
composer require small/swoole-resource-client-bundle
# (this bundle) and its HTTP dependency:
composer require small/swoole-symfony-http-client
```

If Flex does not register it automatically, enable the bundle in `config/bundles.php`:

```
return [
    Small\SwooleResourceClientBundle\SmallSwooleResourceClientBundle::class => ['all' => true],
];
```

Configuration
-------------

[](#configuration)

Create `config/packages/small_swoole_resource_client.yaml`:

```
small_swoole_resource_client:
  server_uri: 'http://localhost:9501'  # resource server base URL
  api_key: '%env(RESOURCE_API_KEY)%'   # key that the server expects in "x-api-key"
```

> **Tip:** provide `RESOURCE_API_KEY` through your secrets or environment.

Services
--------

[](#services)

The bundle exposes a single public service:

- `small_swoole_resource_client.factory` → `Small\SwooleResourceClientBundle\Resource\Factory`

### Factory

[](#factory)

```
final class Factory
{
    public function __construct(string $serverUri, string $apiKey, ?HttpClientInterface $httpClient = null);
    public function createResource(string $name, int $timeout): Resource; // POST /resource
    public function getResource(string $name): Resource;                  // client-side proxy only
}
```

- If no client is injected, the factory builds a `Small\SwooleSymfonyHttpClient\SwooleHttpClient`and configures it with:
    - `base_uri = rtrim(serverUri, '/')`
    - default headers: `accept: application/json` and `x-api-key: `
    - `timeout: 10`

### Resource

[](#resource)

```
final class Resource
{
    public function __construct(string $name, HttpClientInterface $client);
    public function getData(string $selector, bool $lock): array|null; // GET /resource/{name}/{selector}?lock=0|1
    public function lockData(string $selector): bool;                  // convenience wrapper over getData(..., true)
    public function writeData(string $selector, string $json): bool;   // PUT /resource/{name}/{selector}
    public function unlockData(string $selector): bool;                // POST /resource/{name}/{selector}/unlock
    public function getTicket(): ?string;                              // last x-ticket, if provided by server
}
```

- When the server returns **202 Accepted**, the client stores the `x-ticket` header and returns `null`.
- On **200 OK**, `getData()` returns the decoded JSON array.
- `writeData()` requires the `x-ticket` header (set automatically if previously received).
- `unlockData()` returns `true` on **200 OK**.

Usage Example
-------------

[](#usage-example)

```
use Small\SwooleResourceClientBundle\Resource\Factory;

final class ExampleService
{
    public function __construct(private readonly Factory $factory) {}

    public function run(): void
    {
        $res = $this->factory->createResource('printer', 300);

        // Try to acquire lock & get data
        $data = $res->getData('queue', true);
        if ($data === null) {
            // 202 Accepted: lock pending; you may retry later (ticket is kept inside the Resource).
            return;
        }

        // Process and write a new state
        $res->writeData('queue', json_encode(['status' => 'done'], JSON_THROW_ON_ERROR));
        $res->unlockData('queue');
    }
}
```

Testing
-------

[](#testing)

This repository uses **Pest** for tests. The code is written against `HttpClientInterface` which makes it easy to inject a fake client in `test` env.

### Run the suite

[](#run-the-suite)

```
composer install
composer test
# or directly: vendor/bin/pest
```

### Feature tests (Kernel)

[](#feature-tests-kernel)

In `config/packages/test/small_swoole_resource_client.yaml`:

```
small_swoole_resource_client:
  server_uri: 'http://server.example:9501'
  api_key: 'SECRET_KEY'
```

Inject a fake client via `config/services_test.yaml` (or `services_test.php`):

```
services:
  Tests\FakeClass\DummySwooleHttpClient: { public: true }

  small_swoole_resource_client.factory:
    class: Small\SwooleResourceClientBundle\Resource\Factory
    public: true
    arguments:
      $serverUri: '%small_swoole_resource_client.server_uri%'
      $apiKey: '%small_swoole_resource_client.api_key%'
      $httpClient: '@Tests\FakeClass\DummySwooleHttpClient'
```

Static Analysis
---------------

[](#static-analysis)

We recommend **PHPStan** (at the highest level your codebase supports).

```
composer phpstan
# or vendor/bin/phpstan analyse
```

Error Handling
--------------

[](#error-handling)

All network/transport failures are wrapped in `RuntimeException` with a clear message. For non-success HTTP statuses, the response body (if any) is included in the exception message to aid diagnostics.

Security
--------

[](#security)

This bundle forwards `x-api-key` to the resource server. Treat that key as a secret. Consider scoping the key with minimal privileges when your server supports it.

License
-------

[](#license)

Distributed under the **MIT** license. See [LICENSE](LICENSE) for details.

---

**Author:** Sébastien Kus
**Contact:**

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance60

Regular maintenance activity

Popularity6

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

252d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9bbe2f3534bc0dfbcb38a783f2945901d018d3da8b6b12b5c0225fbadffb7167?d=identicon)[small](/maintainers/small)

---

Tags

clientmicroservicesphpresourcesswoolesymfony

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/small-swoole-resource-client-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/small-swoole-resource-client-bundle/health.svg)](https://phpackages.com/packages/small-swoole-resource-client-bundle)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[kadirov/api-starter-kit

443.9k](/packages/kadirov-api-starter-kit)[ibexa/oss

A meta package for installing Ibexa Open Source

19772.4k11](/packages/ibexa-oss)

PHPackages © 2026

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