PHP SDK Reference
Authoritative API reference for phramecms/php-sdk: ClientConfig, client interfaces, ContentQuery, readonly DTOs, RFC 9457 exceptions, PhrameCmsBundle, and FakePhrameClient.
PHP SDK Reference
Complete technical reference for phramecms/php-sdk (PhrameCms\Sdk\*), verified directly against the package source.
For conceptual walkthroughs and framework setup examples, see the PHP SDK Guide.
ClientConfig
Namespace: PhrameCms\Sdk\ClientConfig (final readonly class)
- Constant:
ClientConfig::DEFAULT_USER_AGENT = 'phramecms-php-sdk/0.1'
| Constructor Parameter / Public Property | Type | Default | Notes |
|---|---|---|---|
$baseUri |
string |
(required) | Must be a valid http or https URI with host; trailing / is stripped. Throws InvalidArgumentException otherwise. |
$token |
?string |
null |
Bearer token sent in Authorization: Bearer <token>. Empty string '' normalizes to null; whitespace-only or newline-containing values throw InvalidArgumentException. |
$userAgent |
string |
ClientConfig::DEFAULT_USER_AGENT |
Must be a non-empty single-line header value. |
$correlationIdProvider |
?Closure (?callable in constructor) |
null |
Zero-argument callback fn(): string invoked by resolveCorrelationId() to populate X-Correlation-Id when not explicitly passed per request. |
Methods:
resolveCorrelationId(): ?string— invokes$correlationIdProvider(if set), trims the result, and returnsnullif empty or containing CR/LF.
Entry Point & Client Interfaces
PhrameClientInterface & PhrameClient
- Interface:
PhrameCms\Sdk\Contract\PhrameClientInterface - Implementation:
PhrameCms\Sdk\PhrameClient(final readonly class)
| Method | Signature | Description |
|---|---|---|
PhrameClient::create(...) |
static create(ClientConfig $config, ClientInterface $httpClient, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory): self |
Convenience factory wiring HttpTransport and default sub-clients. |
content() |
content(): ContentClientInterface |
Content CRUD, querying, revisions, and workflow transitions (/api/v1/content/*). |
configs() |
configs(): ConfigClientInterface |
Configuration listing, reading, diffing, writing, and deleting (/api/v1/config/*). |
schemas() |
schemas(): SchemaClientInterface |
Compiled bundle JSON Schemas and OpenAPI 3.1 specification (/api/v1/schema/*, /api/v1/openapi.json). |
config() |
config(): ClientConfig |
Returns the immutable ClientConfig. |
transport() |
transport(): HttpTransportInterface |
Returns the underlying HTTP transport. |
ContentClientInterface
Namespace: PhrameCms\Sdk\Contract\ContentClientInterface (implemented by PhrameCms\Sdk\Client\ContentClient)
| Method | HTTP Mapping | Return Type | Notes |
|---|---|---|---|
list(string $entityType, string $bundle, ?ContentQuery $query = null) |
GET /api/v1/content/{entityType}/{bundle} |
ResourceCollection |
Applies filters, sort, pagination, sparse fieldsets, and includes from $query. |
iterateAll(string $entityType, string $bundle, ?ContentQuery $query = null) |
Repeated GET /api/v1/content/{entityType}/{bundle} |
Generator<int, ResourceObject> |
Lazily advances page[offset] from $query->getOffset() ?? 0 until all meta->total items are yielded. |
get(string $entityType, string $bundle, string $id, ?ContentQuery $query = null) |
GET /api/v1/content/{entityType}/{bundle}/{id} |
ResourceObject |
Throws NotFoundException on 404. |
findOneBy(string $entityType, string $bundle, array $filters, ?ContentQuery $query = null) |
GET /api/v1/content/{entityType}/{bundle} |
?ResourceObject |
Merges $filters, sets limit(1), and returns $collection->items[0] ?? null. |
create(string $entityType, string $bundle, array $fields, ?string $state = null, ?string $id = null, ?string $logMessage = null, bool $dryRun = false, ?string $idempotencyKey = null) |
POST /api/v1/content/{entityType}/{bundle} |
MutationResult |
Sends JSON:API { data: { type, id?, attributes }, meta?: { log_message } }; adds ?dry_run=true and Idempotency-Key when provided. |
update(string $entityType, string $bundle, string $id, array $fields, ?string $logMessage = null, bool $dryRun = false, ?string $idempotencyKey = null) |
PATCH /api/v1/content/{entityType}/{bundle}/{id} |
MutationResult |
Partial field update; sends meta.log_message when $logMessage !== null. |
delete(string $entityType, string $bundle, string $id, bool $dryRun = false, ?string $idempotencyKey = null) |
DELETE /api/v1/content/{entityType}/{bundle}/{id} |
MutationResult |
Deletes entity (or previews deletion when $dryRun is true). |
revisions(string $entityType, string $bundle, string $id) |
GET /api/v1/content/{entityType}/{bundle}/{id}/revisions |
list<RevisionRecord> |
Returns immutable revision history. |
transition(string $entityType, string $bundle, string $id, string $targetState, ?string $logMessage = null, bool $dryRun = false, ?string $idempotencyKey = null) |
POST /api/v1/content/{entityType}/{bundle}/{id}/transitions |
MutationResult |
Sends { data: { type, id, attributes: { state, log_message? } } }. |
ConfigClientInterface
Namespace: PhrameCms\Sdk\Contract\ConfigClientInterface (implemented by PhrameCms\Sdk\Client\ConfigClient)
| Method | HTTP Mapping | Return Type | Notes |
|---|---|---|---|
list(?string $prefix = null) |
GET /api/v1/config (?prefix=...) |
list<ConfigSummary> |
Lists configuration summaries, optionally filtered by prefix. |
get(string $name) |
GET /api/v1/config/{name} |
ConfigDocument |
Fetches a single configuration object and its content hash. |
set(string $name, array $data, ?string $reason = null, bool $dryRun = false, ?string $idempotencyKey = null) |
PUT /api/v1/config/{name} |
ConfigMutationResult |
Sends { data: { type: 'config', id: $name, attributes: $data }, meta?: { reason } } and ?dry_run=true when $dryRun is true. |
delete(string $name, ?string $reason = null, bool $dryRun = false, ?string $idempotencyKey = null) |
DELETE /api/v1/config/{name} |
ConfigMutationResult |
Passes ?dry_run=true and ?reason=... as query parameters when provided. |
diff(?string $prefix = null, ?string $snapshotId = null, ?string $directory = null) |
GET /api/v1/config/diff |
ConfigDiff |
Passes prefix, snapshot_id, and directory query parameters when non-null. |
SchemaClientInterface
Namespace: PhrameCms\Sdk\Contract\SchemaClientInterface (implemented by PhrameCms\Sdk\Client\SchemaClient)
| Method | HTTP Mapping | Return Type | Notes |
|---|---|---|---|
index() |
GET /api/v1/schema |
list<BundleSchema> |
Lists compiled JSON Schemas for all entity types and bundles. |
entityType(string $entityType) |
GET /api/v1/schema/entities/{entityType} |
list<BundleSchema> |
Lists compiled bundle schemas for one entity type. |
bundle(string $entityType, string $bundle) |
GET /api/v1/schema/entities/{entityType}/{bundle} |
BundleSchema |
Fetches compiled JSON Schema for a single bundle. |
openApi() |
GET /api/v1/openapi.json |
array<string, mixed> |
Requests Accept: application/json; public endpoint on PhrameCMS. |
HttpTransportInterface & ResponseData
Namespace: PhrameCms\Sdk\Contract\HttpTransportInterface (implemented by PhrameCms\Sdk\Http\HttpTransport)
- Constants:
HttpTransportInterface::JSON_API_MEDIA_TYPE = 'application/vnd.api+json'HttpTransportInterface::JSON_MEDIA_TYPE = 'application/json'HttpTransportInterface::CORRELATION_ID_HEADER = 'X-Correlation-Id'HttpTransportInterface::IDEMPOTENCY_KEY_HEADER = 'Idempotency-Key'
- Method:
request(string $method, string $path, array $query = [], ?array $body = null, array $headers = [], ?string $accept = self::JSON_API_MEDIA_TYPE, ?string $contentType = self::JSON_API_MEDIA_TYPE, ?string $idempotencyKey = null): ResponseData PhrameCms\Sdk\Http\ResponseData(final readonly class): public$statusCode(int),$headers(array<string, list<string>>),$body(array<string, mixed>),$correlationId(?string), plus case-insensitiveheader(string $name): ?string.
ContentQuery
Namespace: PhrameCms\Sdk\Query\ContentQuery (final readonly class — every mutator returns a new immutable instance)
| Method | Signature | Serialized Query Parameter | Validation |
|---|---|---|---|
create() |
static create(): self |
— | Creates an empty query. |
filter() |
filter(string $field, string|int|float|bool|array $value): self |
filter[<field>]=<value> (bool encoded as 'true'/'false') |
Non-empty field name. |
filters() |
filters(array $filters): self |
Applies filter() for each entry |
Same as filter(). |
sort() |
sort(string $field, bool $descending = false): self |
sort=field1,-field2 |
Supports leading - (sets descending) or +; non-empty field name. |
limit() |
limit(int $limit): self |
page[limit]=<limit> |
Must be >= 1. |
offset() |
offset(int $offset): self |
page[offset]=<offset> |
Must be >= 0. |
sparseFields() |
sparseFields(string $resourceType, array $fields): self |
fields[<resourceType>]=a,b |
Non-empty type, non-empty list, deduplicated. |
include() |
include(string ...$relationships): self |
include=rel1,rel2 |
Non-empty names, deduplicated. |
toQueryParams() |
toQueryParams(): array<string, mixed> |
Returns nested array passed to http_build_query(..., PHP_QUERY_RFC3986) |
— |
Getters: getFilters(), getSort(), getLimit(), getOffset(), getSparseFields(), getInclude().
Readonly Model DTOs (PhrameCms\Sdk\Model\*)
Content Models
| Class | Public Readonly Properties | Helper Methods |
|---|---|---|
ResourceObject |
string $type, string $id, array $attributes = [], array $relationships = [], array $meta = [] |
fromArray(array $data): self, hasAttribute(string $key): bool, string(string $key): string, nullableString(string $key): ?string, int(string $key): int, bool(string $key): bool, array(string $key): array, state(): ?string, createdAt(): ?string, updatedAt(): ?string (typed getters throw UnexpectedValueException on missing key or type mismatch) |
ResourceCollection |
list<ResourceObject> $items, list<ResourceObject> $included, PageMeta $meta, PageLinks $links |
fromDocument(array $document): self, findIncluded(string $type, string $id): ?ResourceObject |
PageMeta |
int $total, int $limit, int $offset, array<string, mixed> $extra = [] |
fromArray(array $data): self |
PageLinks |
?string $self, ?string $first, ?string $prev, ?string $next, ?string $last |
fromArray(array $data): self |
RevisionRecord |
string $revisionId, string $entityId, string $entityType, string $bundle, string $state, array<string, mixed> $fields, string $logMessage, string $actorId, string $actorType, string $createdAt |
Constant RESOURCE_TYPE = 'entity-revision'; fromArray(array $data): self, fromResource(ResourceObject $resource): self |
MutationResult |
?ResourceObject $resource, bool $dryRun, ?array<string, mixed> $diff = null, array<string, mixed> $meta = [] |
fromDocument(array $document): self |
Config & Schema Models
| Class | Public Readonly Properties | Static Factories |
|---|---|---|
ConfigSummary |
string $name, string $type = 'config', array<string, mixed> $attributes = [], array<string, mixed> $meta = [] |
fromResource(array $resource): self |
ConfigDocument |
string $name, array<string, mixed> $data, ?string $hash = null, array<string, mixed> $meta = [], array<string, mixed> $links = [], ?string $correlationId = null |
fromResponse(ResponseData $response): self |
ConfigChange |
string $name, ?array<string, mixed> $before = null, ?array<string, mixed> $after = null |
fromArray(array $payload): self |
ConfigDiff |
bool $empty, list<ConfigChange> $created = [], list<ConfigChange> $updated = [], list<ConfigChange> $deleted = [], array<string, mixed> $meta = [], array<string, mixed> $links = [], ?string $correlationId = null |
fromResponse(ResponseData $response): self, fromDiffArray(array $diff, ?bool $empty = null, array $meta = [], array $links = [], ?string $correlationId = null): self |
ConfigMutationResult |
string $name, bool $changed, bool $deleted, bool $dryRun, ?string $snapshotId = null, ?ConfigDiff $diff = null, ?array<string, mixed> $data = null, array<string, mixed> $meta = [], array<string, mixed> $links = [], ?string $correlationId = null |
fromResponse(ResponseData $response, string $fallbackName): self |
BundleSchema |
string $id, string $entityType, string $bundle, array<string, mixed> $schema, array<string, mixed> $meta = [], array<string, mixed> $links = [], ?string $correlationId = null |
fromResponse(ResponseData $response): self, fromResource(array $resource, array $links = [], ?string $correlationId = null): self |
RFC 9457 Problem Details & Exceptions
ProblemDetails & ValidationIssue
| Class | Public Readonly Properties | Notes |
|---|---|---|
PhrameCms\Sdk\Problem\ProblemDetails |
string $type, string $title, int $status, ?string $detail = null, ?string $instance = null, list<ValidationIssue> $errors = [], ?string $correlationId = null, array<string, mixed> $extensions = [] |
fromArray(array $payload, int $fallbackStatus, ?string $correlationId = null): self, fallback(int $status, ?string $detail = null, ?string $correlationId = null): self, defaultTitle(int $status): string. Unknown RFC 9457 keys are preserved in $extensions. |
PhrameCms\Sdk\Problem\ValidationIssue |
string $path, string $message, ?string $rule = null |
Parsed from RFC 9457 errors[] items (rule or keyword key). |
Exception Hierarchy & HTTP Status Mapping
All SDK exceptions implement the marker interface PhrameCms\Sdk\Exception\PhrameException (extends Throwable).
| Exception FQCN | Parent | HTTP Status / Trigger | Extra Members |
|---|---|---|---|
PhrameCms\Sdk\Exception\TransportException |
RuntimeException |
PSR-18 ClientExceptionInterface, invalid header newline, JSON encode/decode failure, malformed JSON:API document shape |
— |
PhrameCms\Sdk\Exception\ApiException |
RuntimeException |
Any non-2xx HTTP response not matched by a more specific subclass | public readonly ProblemDetails $problem, public readonly int $statusCode; problem(), statusCode(), correlationId() |
PhrameCms\Sdk\Exception\AuthenticationException |
ApiException |
HTTP 401 Unauthorized |
Inherits from ApiException |
PhrameCms\Sdk\Exception\AuthorizationException |
ApiException |
HTTP 403 Forbidden |
Inherits from ApiException |
PhrameCms\Sdk\Exception\NotFoundException |
ApiException |
HTTP 404 Not Found |
Inherits from ApiException |
PhrameCms\Sdk\Exception\ConflictException |
ApiException |
HTTP 409 Conflict |
Inherits from ApiException |
PhrameCms\Sdk\Exception\ValidationException |
ApiException |
HTTP 422 Unprocessable Content |
public readonly array $issues (list<ValidationIssue>), issues(): array |
Symfony Bundle (PhrameCmsBundle)
Class: PhrameCms\Sdk\Symfony\PhrameCmsBundle (extends Symfony\Component\HttpKernel\Bundle\AbstractBundle)
Configuration Schema (phrame_cms:)
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
base_uri |
string |
Yes | — | Base URL of the PhrameCMS API (cannot be empty). |
token |
?string |
No | null |
Bearer AI Agent Token (omit or null for public-only endpoints such as OpenAPI). |
http_client |
?string |
No | null |
Service ID of a custom PSR-18 ClientInterface. When null, uses phrame_cms.psr18_client (wrapping Symfony's http_client). |
user_agent |
string |
No | phramecms-php-sdk/0.1 |
Custom User-Agent header value (cannot be empty). |
Registered Service IDs & Autowiring Aliases
| Service ID | Concrete Class | Aliases |
|---|---|---|
phrame_cms.config |
PhrameCms\Sdk\ClientConfig |
ClientConfig::class |
phrame_cms.psr18_client |
Symfony\Component\HttpClient\Psr18Client |
— |
phrame_cms.transport |
PhrameCms\Sdk\Http\HttpTransport |
HttpTransport::class, HttpTransportInterface::class |
phrame_cms.content_client |
PhrameCms\Sdk\Client\ContentClient |
ContentClient::class, ContentClientInterface::class |
phrame_cms.config_client |
PhrameCms\Sdk\Client\ConfigClient |
ConfigClient::class, ConfigClientInterface::class |
phrame_cms.schema_client |
PhrameCms\Sdk\Client\SchemaClient |
SchemaClient::class, SchemaClientInterface::class |
phrame_cms.client |
PhrameCms\Sdk\PhrameClient |
PhrameClient::class, PhrameClientInterface::class |
Testing Helpers (PhrameCms\Sdk\Testing\*)
PhrameCms\Sdk\Testing\FakePhrameClient implements PhrameClientInterface with in-memory FakeContentClient, FakeConfigClient, FakeSchemaClient, and FakeHttpTransport (which throws TransportException if raw HTTP transport calls are attempted directly).
Helper Method on FakePhrameClient |
Signature | Behavior |
|---|---|---|
withResource() |
withResource(ResourceObject $resource, ?string $entityType = null, ?string $bundle = null): self |
Seeds a resource; infers $entityType and $bundle from <entityType>--<bundle> in $resource->type when omitted. |
withResources() |
withResources(ResourceObject ...$resources): self |
Seeds multiple resources in one fluent call. |
withConfig() |
withConfig(string $name, array $data, ?string $hash = null): self |
Seeds a config document and records it as the diff() baseline. |
withSchema() |
withSchema(BundleSchema $schema): self |
Seeds a BundleSchema keyed by <entityType>--<bundle>. |
withOpenApi() |
withOpenApi(array $spec): self |
Overrides the default OpenAPI 3.1 stub returned by schemas()->openApi(). |
recordedMutations() |
recordedMutations(): list<array<string, mixed>> |
Returns all live (non-dry-run) mutations performed via content() (content.create, content.update, content.delete, content.transition) and configs() (config.set, config.delete). |
clearRecordedMutations() |
clearRecordedMutations(): void |
Clears the recorded mutation log between test phases. |
FakeContentClient supports exact scalar filters, list-IN filters, operator maps (eq, neq, gt, gte, lt, lte, in, contains), multi-field sorting, pagination (limit/offset + PageLinks), sparseFields, dot-path include resolution, and automatic RevisionRecord generation.