PHP SDK
The official PHP package for interacting with the Container API.
The recommended way to interact with the Container API in PHP connectors is the official SDK. It wraps all HTTP endpoints into a typed ContainerApiInterface.
Installation
composer require productsupcom/container-api-clientThe package is hosted on GitHub. Add the repository to your composer.json if you haven't already:
"repositories": [
{ "type": "vcs", "url": "https://github.com/productsupcom/container-api-client" }
]Setup with Symfony
Wire the Container API client using factory classes and Symfony's DI container.
Factory classes — create these to instantiate the Container API client:
<?php
namespace App\ContainerApi;
use GuzzleHttp\Client;
class ContainerApiClientFactory
{
public static function create(): Client
{
return new Client(['base_uri' => 'http://cde-container-api']);
}
}<?php
namespace App\ContainerApi;
use GuzzleHttp\Client;
use Productsup\CDE\ContainerApi\ContainerApi;
class ContainerApiFactory
{
public static function create(Client $client): ContainerApi
{
return new ContainerApi($client);
}
}Service definitions — register the factories in a config file:
services:
container.api.client:
class: GuzzleHttp\Client
factory: ['App\ContainerApi\ContainerApiClientFactory', 'create']
container.api:
class: Productsup\CDE\ContainerApi\ContainerApi
factory: ['App\ContainerApi\ContainerApiFactory', 'create']
arguments:
- '@container.api.client'DI binding — bind the interface so it can be injected anywhere:
services:
_defaults:
autowire: true
autoconfigure: true
bind:
Productsup\CDE\ContainerApi\ContainerApiInterface $containerApi: '@container.api'Now you can inject ContainerApiInterface into any service:
public function __construct(
private ContainerApiInterface $containerApi,
) {}Key methods
Writing output (data source connectors)
| Method | Description |
|---|---|
appendToOutputFile(array $item) | Write a single product |
appendManyToOutputFile(array $items) | Write a batch of products (auto-chunks large batches) |
streamToOutput(\Generator $generator) | Stream products from a generator — memory-efficient for large datasets |
Reading input (export connectors)
| Method | Description |
|---|---|
yieldFromInputFile() | Iterate all products one by one |
yieldBatchFromInputFile(int $size) | Iterate products in batches |
countItemsFromInputFile() | Get total item count |
Reading delta input (export-delta connectors)
| Method | Description |
|---|---|
yieldFromNewFile() | Products added since last run |
yieldFromModifiedFile() | Products changed since last run |
yieldFromUnchangedFile() | Products with no changes |
yieldFromDeletedFile() | Products removed since last run |
Batch and count variants are also available: yieldBatchFromNewFile(int $size), countItemsFromNewFile(), etc.
Writing feedback (export connectors)
| Method | Description |
|---|---|
appendToFeedbackFile(array $item) | Write a single feedback entry |
appendManyToFeedbackFile(array $items) | Write a batch of feedback entries |
Logging
| Method | Description |
|---|---|
info(string $message) | Log an info message |
warning(string $message) | Log a warning |
error(string $message) | Log an error |
debug(string $message) | Log a debug message |
Metadata
| Method | Description |
|---|---|
showHeaders(string $type) | Get column names of an input file |
countItemsFromInputFile() | Get item count |
Keeping up to date
Keep the SDK updated to get the latest methods and bug fixes:
composer update productsupcom/container-api-clientHow is this guide?