darkmatterfr/constellation-sdk
Laravel-friendly PHP SDK for Darkmatterfr Constellation: provides API client helpers, authentication and request handling to integrate Constellation services into your app quickly, with clean abstractions, configuration support and extendable components.
Install the package via Composer:
composer require darkmatterfr/constellation-sdk
Publish the configuration file (if needed) with:
php artisan vendor:publish --provider="Darkmatter\ConstellationSdk\ConstellationSdkServiceProvider"
The package now includes exception tracing and type handling, making debugging easier. Start by wrapping API calls in a try-catch block to leverage the new exception details:
use Darkmatter\ConstellationSdk\Exceptions\ConstellationException;
try {
$response = Constellation::apiCall('endpoint', ['param' => 'value']);
} catch (ConstellationException $e) {
// Access trace and exception type via $e->getTrace() and $e->getExceptionType()
logger()->error('Constellation API Error', [
'trace' => $e->getTrace(),
'type' => $e->getExceptionType(),
]);
}
try-catch blocks to catch ConstellationException.getTrace() and getExceptionType() methods:
catch (ConstellationException $e) {
$this->logErrorWithContext($e->getTrace(), $e->getExceptionType());
}
ConstellationException:
Event::listen(ConstellationException::class, function ($e) {
// Custom logic (e.g., Slack alerts, retries)
});
Use the package’s exception details in Laravel’s logging channels:
catch (ConstellationException $e) {
Log::channel('slack')->error('API Failed', [
'exception' => $e->getExceptionType(),
'trace' => $e->getTrace(),
]);
}
Mock exceptions in tests to verify error handling:
$mockException = new ConstellationException('Test Error', [], 'API_TIMEOUT');
$this->expectException(ConstellationException::class);
$this->expectExceptionMessage('Test Error');
getTrace() method now returns a structured array of the error’s call stack, useful for debugging.getExceptionType() (e.g., 'API_TIMEOUT', 'VALIDATION_ERROR') to categorize errors in logs or UI.if ($e->getExceptionType() === 'API_TIMEOUT') {
// Retry logic
}
logger()->debug('Full trace', ['trace' => $e->getTrace()]);
getTrace(), getExceptionType()) are final; extend via custom exceptions if needed.$filteredTrace = collect($e->getTrace())->reject(fn($item) => str_contains($item, 'password'));
ConstellationException to add domain-specific logic:
class PaymentConstellationException extends ConstellationException {
public function getSeverity(): string {
return 'CRITICAL';
}
}
ConstellationException to trigger workflows (e.g., notifications):
Event::listen(ConstellationException::class, function ($e) {
Notification::route('mail', 'admin@example.com')
->notify(new ApiFailure($e));
});
How can I help you explore Laravel packages today?