contentpulse / contentpulse-php
The official PHP SDK for ContentPulse.io - content rendering, API client, and publishing utilities.
Package info
github.com/contentpulseio/contentpulse-php-sdk
pkg:composer/contentpulse/contentpulse-php
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.8
- psr/http-client: ^1.0
- psr/log: ^3.0
Requires (Dev)
- laravel/pint: ^1.0
- mockery/mockery: ^1.6
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
README
Official PHP SDK for ContentPulse.io - content rendering, API client, and publishing utilities.
Requirements
- PHP 8.2+
Installation
composer require contentpulse/contentpulse-php
Quick Start
Create a client
use ContentPulse\Http\ContentPulseClient; $client = new ContentPulseClient( baseUrl: 'https://contentpulse.io', apiKey: 'your-api-key' );
Resolve WordPress endpoints (SDK-managed)
use ContentPulse\WordPress\Support\ContentPulseEndpointResolver; $apiBaseUrl = ContentPulseEndpointResolver::resolveApiBaseUrlFromEnvironment(); $appBaseUrl = ContentPulseEndpointResolver::resolveAppBaseUrlFromEnvironment(); $publishEndpoint = ContentPulseEndpointResolver::buildPublishWordPressEndpoint($apiBaseUrl, $contentId); $contentUrl = ContentPulseEndpointResolver::buildContentUrl($appBaseUrl, $contentId);
When no overrides are provided, the resolver auto-selects sensible defaults:
- Local/dev:
http://contentpulse.test:8080andhttp://app.contentpulse.test:5173(whencontentpulse.testis resolvable) - Otherwise:
https://contentpulse.ioandhttps://app.contentpulse.io
Overrides (highest to lowest precedence): explicit argument → PHP constant (CONTENTPULSE_API_URL, CONTENTPULSE_APP_URL) → environment variable.
Fetch content feed
use ContentPulse\Core\DTO\ContentFilters; $feed = $client->getContentFeed(new ContentFilters( websiteId: 1, perPage: 20, )); foreach ($feed->items as $item) { // $item contains content metadata and structure }
Render content to HTML
use ContentPulse\Rendering\HtmlRenderer; $renderer = new HtmlRenderer(); $html = $renderer->renderAll($content->sections);
Section normalizer
use ContentPulse\Rendering\SectionNormalizer; $normalizer = new SectionNormalizer(); $normalized = $normalizer->normalize($rawSections);
SEO meta tags
use ContentPulse\Core\DTO\SeoMeta; $seo = SeoMeta::fromArray($content->seo_metadata); $html = $seo->toHtml(); // Renders <title>, meta description, og:*, twitter:*
Publish payloads
Build platform-specific payloads for WordPress or Shopify:
use ContentPulse\Publishing\PublishPayloadBuilder; use ContentPulse\Rendering\HtmlRenderer; $builder = new PublishPayloadBuilder(new HtmlRenderer()); $payload = $builder->buildForWordPress($content); // or $payload = $builder->buildForShopify($content);
Architecture
| Module | Purpose |
|---|---|
Core/Contracts/ |
Interfaces for API client, renderers, and publishers |
Core/DTO/ |
Data transfer objects (CompatibilityInfo, PublicationRecord, SeoMeta, PublishResult) |
Core/Exceptions/ |
Exception hierarchy for API and validation errors |
Http/ |
REST API client for ContentPulse endpoints |
Rendering/ |
HtmlRenderer, SectionNormalizer, SEO meta renderer |
Publishing/ |
Publish payload builder for WordPress, Shopify, and custom platforms |
Supported Section Types
The HtmlRenderer supports all section types produced by the ContentPulse content generation pipeline:
Fixed sections: titles, hero, cta, seo_keywords, references
Content sections: content, content_seo, conclusion
Component sections: steps, table, grid, checklist, faq, dos_donts, alert, quote, pros_cons, summary_box, definition, key_stats, tip_box, comparison_card, comparison_table, timeline, accordion, testimonial, code_snippet
Testing
composer test
Or directly:
./vendor/bin/phpunit
License
MIT