dbp/relay-base-publication-connector-pure-bundle
Installation Add the bundle via Composer:
composer require dbp/relay-base-publication-connector-pure-bundle
Enable the bundle in config/bundles.php:
return [
// ...
DigitalBlueprint\RelayBasePublicationConnectorPureBundle\DigitalBlueprintRelayBasePublicationConnectorPureBundle::class => ['all' => true],
];
Configuration Publish the default config:
php artisan vendor:publish --tag=relay-connector-config
Update config/relay_connector.php with your Relay API gateway credentials and endpoints.
First Use Case Publish a test resource via the connector:
use DigitalBlueprint\RelayBasePublicationConnectorPureBundle\Service\PublicationService;
$publicationService = app(PublicationService::class);
$result = $publicationService->publish([
'title' => 'Test Publication',
'content' => 'Hello, Relay!',
'type' => 'article',
]);
./docs/README.md for setup and API reference.config/relay_connector.php for endpoint and authentication settings.src/Service/PublicationService.php for core methods like publish(), update(), and delete().Publication Lifecycle
PublicationService::publish() with a normalized array of data.
$publication = $publicationService->publish($data);
$publication = $publicationService->get($id);
$publication['title'] = 'Updated Title';
$publicationService->update($id, $publication);
delete():
$publicationService->delete($id, ['force' => true]);
Event-Driven Integration
Listen for publication events (e.g., PublicationCreated, PublicationUpdated) via Laravel’s event system:
// In a service provider or listener
Event::listen(PublicationCreated::class, function ($event) {
// Trigger downstream actions (e.g., notifications, analytics)
});
Batch Processing
Use PublicationService::publishBatch() for bulk operations:
$publicationService->publishBatch([
['title' => 'Post 1', 'content' => '...'],
['title' => 'Post 2', 'content' => '...'],
]);
// In a model (e.g., Post.php)
use DigitalBlueprint\RelayBasePublicationConnectorPureBundle\Traits\RelayPublishable;
class Post extends Model
{
use RelayPublishable;
public function publishToRelay()
{
return $this->relayPublish();
}
}
Resource classes:
use Illuminate\Http\Resources\Json\JsonResource;
class PostResource extends JsonResource
{
public function toArray($request)
{
return [
'title' => $this->title,
'content' => $this->body,
'type' => 'post',
// Relay-specific fields
];
}
}
// Dispatch a job
PublishToRelay::dispatch($post);
// Job class
class PublishToRelay implements ShouldQueue
{
use Dispatchable, InteractsWithQueue;
public function handle()
{
$post->publishToRelay();
}
}
Authentication Failures
config/relay_connector.php for correct client_id, client_secret, and token_endpoint. Use php artisan relay:auth:test to validate.GuzzleHttp errors.Data Normalization Mismatches
slug, author_id), but your data lacks them.Normalizer class to pre-process data:
$normalized = app(\DigitalBlueprint\RelayBasePublicationConnectorPureBundle\Service\Normalizer::class)
->normalize($rawData);
Rate Limiting
throttle middleware.Webhook Verification
webhook_secret in the bundle’s config and use the provided RelayWebhookHandler middleware.debug: true in config to log raw Relay API responses to storage/logs/relay.log.HttpClient directly for debugging:
$client = app(\DigitalBlueprint\RelayBasePublicationConnectorPureBundle\Http\Client::class);
$response = $client->get('/publications/1');
Event::listen(PublicationCreated::class, function ($event) {
\Log::debug('Relay Publication Event', ['event' => $event->toArray()]);
});
// In a service provider
$this->app->bind(\DigitalBlueprint\RelayBasePublicationConnectorPureBundle\Http\Client::class, function ($app) {
$config = $app['config']['relay_connector'];
$config['endpoint'] = env('RELAY_ENDPOINT_OVERRIDE', $config['endpoint']);
return new Client($config);
});
// In config/relay_connector.php
'http' => [
'timeout' => 30,
'retries' => 3,
'retry_delay' => 100, // ms
],
Custom Normalizers
Extend the Normalizer class to handle domain-specific transformations:
class CustomNormalizer extends \DigitalBlueprint\RelayBasePublicationConnectorPureBundle\Service\Normalizer
{
protected function normalizeAuthor($data)
{
return [
'id' => $data['user_id'],
'name' => $data['user']['name'],
];
}
}
Register it in a service provider:
$this->app->bind(
\DigitalBlueprint\RelayBasePublicationConnectorPureBundle\Service\Normalizer::class,
CustomNormalizer::class
);
Webhook Handlers
Extend the RelayWebhookHandler to process custom event types:
class CustomWebhookHandler extends \DigitalBlueprint\RelayBasePublicationConnectorPureBundle\Event\RelayWebhookHandler
{
protected function handleCustomEvent($payload)
{
if ($payload['event'] === 'custom.event') {
// Handle custom logic
}
}
}
API Extensions
Add custom endpoints to the HttpClient:
// In a service provider
$client = $this->app->make(\DigitalBlueprint\RelayBasePublicationConnectorPureBundle\Http\Client::class);
$client->extend('custom', function ($client) {
return new CustomRelayClient($client);
});
How can I help you explore Laravel packages today?