๐ŸŒ AIๆœ็ดข & ไปฃ็† ไธป้กต
Skip to content

Guiziweb/bookstack-sdk-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

BookStack PHP SDK

A PHP SDK for the BookStack API with DTOs, validation, and comprehensive documentation.

PHP Version License: MIT PHPStan Tests

๐Ÿš€ Installation

composer require guiziweb/bookstack-sdk-php

โšก Quick Usage

Create the client

<?php

use Guiziweb\BookStackSdk\BookStackClientFactory;

$client = BookStackClientFactory::create(
    'https://your-bookstack-instance.com',
    'your-api-token-id',
    'your-api-token-secret'
);

Basic examples

$booksResult = $client->books()->list();
foreach ($booksResult['data'] as $book) {
    echo $book->name;  
}

$book = $client->books()->create([
    'name' => 'My new book',
    'description' => 'Description'
]);
echo $book->id;

$results = $client->search()->search('my search term');
foreach ($results['data'] as $result) {
    echo $result->name; 
}

๐Ÿ“‹ Available Services

The client covers the BookStack API endpoints:

Service Description DTOs
books() Books (CRUD + export) Book, BookContent, Tag, Cover, PageSummary
pages() Pages (CRUD + export) Page
chapters() Chapters (CRUD + export) Chapter
shelves() Bookshelves (CRUD) Shelf
users() Users (CRUD) User, UserRole
roles() Roles and permissions Role, RoleUser
search() Global search SearchResult
images() Images Image, ImageUser
attachments() File attachments Attachment
recycleBin() Recycle bin RecycleBinItem
contentPermissions() Permissions ContentPermission, RolePermission, etc.
auditLogs() Audit logs AuditLogEntry, AuditUser

๐Ÿ“š Detailed Examples

Books management

// List with pagination and sorting
$books = $client->books()->list(50, 0, ['name' => 'asc']);

// Complete CRUD
$book = $client->books()->create(['name' => 'Test']);
$book = $client->books()->show(1);
$book = $client->books()->update(1, ['name' => 'New name']);
$client->books()->delete(1);

// Export PDF/HTML/etc.
$pdf = $client->books()->export(1, 'pdf');
$html = $client->books()->export(1, 'html');

Search

// General search
$results = $client->search()->search('term', 20);

// Specialized search
$books = $client->search()->searchBooks('guide');
$pages = $client->search()->searchPages('installation');

User management

// Create a user
$user = $client->users()->create([
    'name' => 'John Doe',
    'email' => 'john@example.com'
]);

// List users
$users = $client->users()->list();

Content permissions

// Get book permissions
$permissions = $client->contentPermissions()->getPermissions('book', 1);

// Update permissions
$updated = $client->contentPermissions()->set('book', 1, [
    'role_permissions' => [
        2 => ['view' => true, 'update' => false, 'delete' => false]
    ]
]);

๐Ÿ›ก๏ธ Error Handling

use Guiziweb\BookStackClient\Exception\BookStackClientException;
use Guiziweb\BookStackClient\Exception\ValidationException;

try {
    $book = $client->books()->show(999);
} catch (ValidationException $e) {
    // Invalid parameters
    echo "Validation error: " . $e->getMessage();
} catch (BookStackClientException $e) {
    // API error (404, 403, etc.)
    echo "API error: " . $e->getMessage();
}

โš™๏ธ Advanced Configuration

// With custom options
$client = BookStackClientFactory::createWithOptions(
    'https://your-bookstack-instance.com',
    'your-api-token-id',
    'your-api-token-secret',
    [
        'timeout' => 60,
        'max_redirects' => 5,
        'headers' => ['User-Agent' => 'My-App/1.0']
    ]
);

// With custom HTTP client
use Symfony\Component\HttpClient\HttpClient;

$httpClient = HttpClient::create(['timeout' => 30]);
$client = BookStackClientFactory::createWithHttpClient(
    $httpClient,
    'https://your-bookstack-instance.com',
    'your-api-token-id',
    'your-api-token-secret'
);

๐Ÿงช Tests

Unit tests (fast)

# Unit tests only
make test-unit

# With code coverage
make coverage

Integration tests (require BookStack)

# Start BookStack locally with automatic API token creation
make ci-setup

# Run integration tests
make ci-test

# Stop test BookStack
make ci-down

Complete tests

# All tests (unit + integration if BookStack available)
make test

๐Ÿ“‹ Requirements

  • PHP 8.2+
  • BookStack v24.05+ (tested with v25.07)
  • Valid API keys

Note: For ZIP exports with BookStack v25.05+, add 'zip' to the EXPORT_FORMATS array in src/Validator/ParameterValidator.php

๐Ÿ“„ License

MIT License. See LICENSE for more details.

๐Ÿ”— Links

About

A PHP SDK for BookStack API

Resources

License

Stars

Watchers

Forks

Packages

No packages published