PHP code example of wuemv / content-sdk-php

1. Go to this page and download the library: Download wuemv/content-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wuemv / content-sdk-php example snippets


use Wuemv\ContentSdk\Client;

$wue = new Client(
    apiKey: 'wue_...',                              // bearer token from CMS settings
    siteId: 'portfolio',                             // optional, for clarity in your code
    baseUrl: 'https://your-wue-instance.com/api',    // API root — INCLUDE /api suffix
);

// Health check / setup confirmation
$health = $wue->ping->check();
// → ['ok' => true, 'api_version' => 'v1', 'site' => [...], 'server_time' => '...']

// Schema discovery
$types = $wue->contentTypes->list();
foreach ($types as $ct) {
    echo $ct->slug;                    // 'blog', 'product', ...
    echo $ct->name;
    foreach ($ct->fields as $field) {
        echo "  - {$field->key} ({$field->type})";
    }
}

// Single content type
$blog = $wue->contentTypes->retrieve('blog');

// List entries
$posts = $wue->entries->list('blog');
foreach ($posts as $post) {
    echo $post->slug;                              // typed static property
    echo $post->fields->string('title');            // typed dynamic accessor
    echo $post->fields->date('published_at');       // ?DateTimeImmutable
    echo $post->fields['body'];                     // array access also works
}

// Single entry
$post = $wue->entries->retrieve('blog', 'hello-world');

use GuzzleHttp\Client as GuzzleClient;

$wue = new Client(
    apiKey: '...',
    baseUrl: 'https://cms.yoursite.test/api',
    httpClient: new GuzzleClient(['verify' => false]),
);

use App\Wue\BlogEntry;
use App\Wue\ContentType;

// Pass the enum — the SDK hydrates into BlogEntry, not generic Entry
$posts = $wue->entries->list(ContentType::Blog);

foreach ($posts as $post) {
    /** @var BlogEntry $post */
    echo $post->title();              // string, type-safe
    echo $post->publishedAt()?->format('Y-m-d');
    echo $post->slug;                  // inherited from Entry
}

try {
    $wue->ping->check();
} catch (\Wuemv\ContentSdk\Exception\AuthenticationException $e) {
    // Invalid API key
} catch (\Wuemv\ContentSdk\Exception\ContentSdkException $e) {
    // Anything else from the SDK
}

$mock = new GuzzleHttp\Handler\MockHandler([
    new GuzzleHttp\Psr7\Response(200, [], '{"ok": true}'),
]);
$client = new Wuemv\ContentSdk\Client(
    apiKey: 'wue_test',
    baseUrl: 'https://api.example.com',
    httpClient: new GuzzleHttp\Client([
        'handler' => GuzzleHttp\HandlerStack::create($mock),
    ]),
);

src/Wue/
├── ContentType.php          ← enum { Blog = 'blog', Product = 'product', ... }
├── BlogEntry.php             ← typed: title(), excerpt(), publishedAt(), ...
└── ProductEntry.php