Installation
composer require alpixel/customerbridgebundle
Add to bundles.php:
return [
// ...
Alpixel\CustomerBridgeBundle\AlpixelCustomerBridgeBundle::class => ['all' => true],
];
Configuration
Override default settings in config/packages/alpixel_customer_bridge.yaml:
alpixel_customer_bridge:
api_endpoint: 'https://api.example.com'
api_key: '%env(API_KEY)%'
sonata_admin: 'sonata.admin.user' # Default Sonata admin class
First Use Case Extend a Sonata admin class to use the bridge:
use Alpixel\CustomerBridgeBundle\Admin\BridgeableAdminInterface;
use Alpixel\CustomerBridgeBundle\Admin\BridgeableAdminTrait;
class CustomUserAdmin extends SonataAdminService
implements BridgeableAdminInterface
{
use BridgeableAdminTrait;
// Implement required methods:
public function getBridgeableModel(): string { return 'User'; }
public function getBridgeableFields(): array { return ['email', 'name']; }
}
Bridgeable Admin Integration
BridgeableAdminInterface in Sonata admin classes.BridgeableAdminTrait to auto-generate bridge methods.syncWithBridge() to customize sync logic:
protected function syncWithBridge($object, $bridgeData): void {
$object->setEmail($bridgeData['email']);
$this->save($object);
}
API Interaction
CustomerBridgeClient service for API calls:
$client = $this->get('alpixel_customer_bridge.client');
$response = $client->getUser('user@example.com');
BridgeResponse):
class UserBridgeResponse extends BridgeResponse {
public function getExternalId(): string { return $this->data['external_id']; }
}
Event-Driven Sync
customer.bridge.sync events:
$dispatcher->addListener('customer.bridge.sync', function (SyncEvent $event) {
// Custom logic before/after sync
});
php bin/console alpixel:customer-bridge:sync --admin=sonata.admin.user
getBridgeableFields() to auto-map fields between Sonata and the bridge API.CustomerBridgeBatchProcessor for large datasets:
$processor = $this->get('alpixel_customer_bridge.batch_processor');
$processor->process($adminClass, $batchSize = 50);
WebhookHandlerInterface for incoming webhook events:
class CustomWebhookHandler implements WebhookHandlerInterface {
public function handle(array $payload): void {
// Update Sonata entities based on payload
}
}
Deprecation Warnings
composer require sonata-project/admin-bundle:2.4.* explicitly.API Key Management
api_key in config violates security best practices.%env(API_KEY)% and ensure .env is in .gitignore.Field Mismatches
getBridgeableFields() cause silent failures.Circular Dependencies
AlpixelCustomerBridgeBundle in bundles.php.config/packages/monolog.yaml:
handlers:
customer_bridge:
type: stream
path: "%kernel.logs_dir%/customer_bridge.log"
level: debug
channels: ["alpixel_customer_bridge"]
alpixel:customer-bridge:status command:
php bin/console alpixel:customer-bridge:status --admin=sonata.admin.user
Custom Sync Strategies
Override CustomerBridgeSyncStrategy to implement custom logic:
class CustomSyncStrategy extends CustomerBridgeSyncStrategy {
protected function resolveConflict($localData, $remoteData): array {
// Custom conflict resolution
}
}
Register in services.yaml:
services:
Alpixel\CustomerBridgeBundle\Sync\CustomerBridgeSyncStrategy:
class: App\Sync\CustomSyncStrategy
Webhook Validation
Extend WebhookValidatorInterface to add payload checks:
class StrictWebhookValidator implements WebhookValidatorInterface {
public function validate(array $payload): bool {
return isset($payload['signature']) && $this->verifySignature($payload);
}
}
Rate Limiting
Implement RateLimitStrategyInterface for API throttling:
class GuzzleRateLimitStrategy implements RateLimitStrategyInterface {
public function apply(GuzzleHttp\Client $client): GuzzleHttp\Client {
return $client->withConfig(['handler' => new RateLimitHandler()]);
}
}
How can I help you explore Laravel packages today?