zendframework/zendservice-livedocx
ZendService\LiveDocx provides a PHP component for interacting with LiveDocx document services. Install via Composer and follow the docs in the documentation folder for usage. Note: repository abandoned since 2019-12-05 and no longer maintained.
Installation Add the package via Composer (if still needed for legacy projects):
composer require zendframework/zendservice-livedocx
(Note: Due to archival, ensure compatibility with your Laravel version—likely ZF2-era projects.)
Service Initialization
Register the LiveDocx client in Laravel’s config/services.php:
'livedocx' => [
'api_key' => env('LIVEDOCX_API_KEY'),
'account_id' => env('LIVEDOCX_ACCOUNT_ID'),
'endpoint' => env('LIVEDOCX_ENDPOINT', 'https://api.livedocx.com'),
],
Bind the service in AppServiceProvider:
$this->app->singleton('livedocx', function ($app) {
$config = $app['config']['services.livedocx'];
return new \ZendService\LiveDocx\Client($config['api_key'], $config['account_id'], $config['endpoint']);
});
First Use Case: Generate a Document Inject the client into a controller/service and call the API:
use ZendService\LiveDocx\Client;
public function generateDocument(Client $livedocx) {
$templateId = 'your_template_id';
$data = ['name' => 'John Doe', 'date' => now()->format('Y-m-d')];
$response = $livedocx->generate($templateId, $data);
return response()->download($response->getDocumentUrl());
}
Template Management
$livedocx->getTemplates().$livedocx->uploadTemplate($filePath, $name) for custom templates.generate() for placeholders like {name}.Document Operations
foreach ($templates as $template) {
$livedocx->generate($template['id'], $data)->storeAs($template['name'] . '.docx');
}
Error Handling Wrap API calls in try-catch blocks:
try {
$result = $livedocx->generate($templateId, $data);
} catch (\ZendService\LiveDocx\Exception\RuntimeException $e) {
Log::error("LiveDocx Error: " . $e->getMessage());
abort(500, "Document generation failed.");
}
storage/app/livedocx:
$livedocx->generate($templateId, $data)->storeAs('invoices/invoice_' . $id . '.docx');
GenerateDocumentJob):
GenerateDocumentJob::dispatch($templateId, $data, $userId)->onQueue('livedocx');
Deprecated Dependencies
zendframework/zend-servicemanager if needed.API Key Security
.env and env() helper:
'api_key' => env('LIVEDOCX_API_KEY', 'fallback_if_needed'),
.env file permissions (chmod 600 .env).Document Size Limits
if ($file->getSize() > 50 * 1024 * 1024) {
throw new \Exception("File too large.");
}
Rate Limits
$livedocx->getAccountUsage(); // Hypothetical; check API docs.
Enable Guzzle Logging: Add to config/services.php:
'livedocx' => [
'http_client' => [
'handler' => \GuzzleHttp\HandlerStack::create([
'debug' => function ($handler) {
$debugHandler = new \GuzzleHttp\Handler\CurlHandler();
return \GuzzleHttp\HandlerStack::create($debugHandler);
},
]),
],
],
Logs appear in storage/logs/laravel.log.
Validate API Responses: Inspect raw responses for errors:
$response = $livedocx->generate($templateId, $data);
if ($response->hasError()) {
Log::debug("Raw Response: " . $response->getRawBody());
}
Custom Response Handlers Extend the client to handle responses differently:
class CustomLiveDocxClient extends \ZendService\LiveDocx\Client {
public function generate($templateId, $data) {
$response = parent::generate($templateId, $data);
return new CustomDocumentResponse($response->getDocumentUrl());
}
}
Webhook Integration
Use Laravel’s queue:work to process webhook callbacks from LiveDocx (e.g., for async completion events).
Fallback Templates Implement a local fallback for offline use:
if (!$livedocx->isOnline()) {
return view('pdf.fallback', ['data' => $data]);
}
How can I help you explore Laravel packages today?