PHP SDK
Official PHP SDK for WebinOne API
PHP SDK
The official PHP SDK provides a modern, PSR-compliant interface to the WebinOne API with full type safety and IDE support.
Installation
composer require webinone/sdk
Requirements
- PHP 8.0 or higher
- ext-json
- ext-curl
Quick Start
<?php
use WebinOne\Client;
$client = new Client([
'base_url' => 'https://your-site.webinone.com',
'client_id' => 'YOUR_CLIENT_ID',
'client_secret' => 'YOUR_CLIENT_SECRET'
]);
// List all pages
$pages = $client->pages()->list();
// Create a new page
$page = $client->pages()->create([
'name' => 'My New Page',
'url_slug' => 'my-new-page',
'enabled' => true,
'release_date' => date('Y-m-d\TH:i:s'),
'expiry_date' => '2099-12-31T00:00:00'
]);
Features
- PSR-18 HTTP Client: Works with any PSR-18 compliant HTTP client
- PSR-3 Logging: Optional logging support
- Type Safety: Full PHP 8+ type declarations
- Fluent Interface: Chainable query builder
- Exception Handling: Typed exceptions for different errors
Working with Module Items
// Get module
$module = $client->modules()->getByName('Products');
// Query with fluent interface
$products = $client->moduleItems()
->where(['$and' => [['$eq' => ['Enabled' => true]]]])
->orderBy('Name ASC')
->limit(50)
->list($module->id);
// Create item
$product = $client->moduleItems()->create($module->id, [
'name' => 'New Product',
'url_slug' => 'new-product',
'enabled' => true,
'custom_properties' => [
'Price' => '99.99',
'Stock' => '100'
]
]);
Error Handling
use WebinOne\Exception\{
AuthenticationException,
RateLimitException,
ValidationException,
NotFoundException
};
try {
$page = $client->pages()->get(123);
} catch (NotFoundException $e) {
// Handle not found
echo 'Page not found';
} catch (RateLimitException $e) {
// Handle rate limit
sleep($e->getRetryAfter());
// Retry request
} catch (ValidationException $e) {
// Handle validation errors
foreach ($e->getErrors() as $field => $message) {
echo "$field: $message\n";
}
}
Configuration Options
$client = new Client([
'base_url' => 'https://your-site.webinone.com',
'client_id' => 'YOUR_CLIENT_ID',
'client_secret' => 'YOUR_CLIENT_SECRET',
'timeout' => 30, // Request timeout in seconds
'retry' => 3, // Number of retries for failed requests
'logger' => $psrLogger, // Optional PSR-3 logger
'http_client' => $psrHttpClient // Optional PSR-18 client
]);
Code Examples
client = $client;
$this->pageModuleId = 1522; // Pages module
}
public function createPage(string $title, string $content): object
{
return $this->client->moduleItems()->create($this->pageModuleId, [
'name' => $title,
'url_slug' => $this->slugify($title),
'description' => $content,
'enabled' => true,
'release_date' => date('Y-m-d\TH:i:s'),
'expiry_date' => '2099-12-31T00:00:00'
]);
}
public function listPages(int $limit = 50): array
{
return $this->client->moduleItems()
->where(['$and' => [['$eq' => ['Enabled' => true]]]])
->orderBy('Name ASC')
->limit($limit)
->list($this->pageModuleId);
}
public function updatePage(int $id, array $data): object
{
// Get current data first (PUT overwrites)
$current = $this->client->moduleItems()->get($id);
// Merge updates
$merged = array_merge(
(array) $current,
$data
);
return $this->client->moduleItems()->update($id, $merged);
}
private function slugify(string $text): string
{
$text = strtolower($text);
$text = preg_replace('/[^a-z0-9]+/', '-', $text);
return trim($text, '-');
}
}
// Usage
$client = new Client([
'base_url' => 'https://your-site.webinone.com',
'client_id' => getenv('WEBINONE_CLIENT_ID'),
'client_secret' => getenv('WEBINONE_CLIENT_SECRET')
]);
$manager = new ContentManager($client);
// Create a page
$page = $manager->createPage(
'About Us',
'Welcome to our company...
'
);
echo "Created page: {$page->name} (ID: {$page->id})\n";
// List all pages
$pages = $manager->listPages();
foreach ($pages as $page) {
echo "- {$page->name}\n";
}