digipolisgent/domainator9k-sock-bundle
Installation
composer require digipolisgent/domainator9k-sock-bundle
Ensure your project uses Symfony 3.4.x (no newer versions supported).
Register Bundle
Add to app/AppKernel.php:
new DigipolisGent\Domainator9k\SockBundle\DigipolisGentDomainator9kSockBundle(),
Configure
Add to app/config/config.yml:
digipolis_gent_domainator9k_sock:
host: 'your-domainator9k-endpoint'
user_token: 'your-user-token'
client_token: 'your-client-token'
First Use Case Inject the service in a controller/service:
use DigipolisGent\Domainator9k\SockBundle\Service\Domainator9kService;
class MyController extends Controller
{
public function __construct(Domainator9kService $domainator9k)
{
$this->domainator9k = $domainator9k;
}
public function fetchData()
{
$response = $this->domainator9k->fetchData('endpoint');
return new Response($response);
}
}
Service Injection
Use dependency injection for Domainator9kService in controllers, commands, or other services.
// services.yml
services:
App\Service\MyService:
arguments:
- '@digipolis_gent_domainator9k_sock.service.domainator9k'
API Endpoint Abstraction Wrap raw API calls in domain-specific methods:
$this->domainator9k->getUserData($userId);
$this->domainator9k->postEvent($eventPayload);
Event Listeners Subscribe to bundle events (if available) for post-processing:
// src/AppBundle/EventListener/DomainatorListener.php
class DomainatorListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'domainator9k.response' => 'onResponse',
];
}
public function onResponse(ResponseEvent $event)
{
// Transform/validate response
}
}
Configuration Overrides
Override config per environment (e.g., config_test.yml):
digipolis_gent_domainator9k_sock:
host: '%env(DOMAINATOR_TEST_HOST)%'
$this->domainator9k->setLogger($logger);
class RetryDomainatorService implements Domainator9kInterface
{
public function fetchData($endpoint, $retries = 3)
{
try {
return $this->decorated->fetchData($endpoint);
} catch (Exception $e) {
if ($retries > 0) {
sleep(1);
return $this->fetchData($endpoint, $retries - 1);
}
throw $e;
}
}
}
$message = new Domainator9kMessage($endpoint, $payload);
$this->messageBus->dispatch($message);
Deprecation Risk
Configuration Sensitivity
user_token/client_token are hardcoded in YAML (unencrypted). Use environment variables:
user_token: '%env(DOMAINATOR_USER_TOKEN)%'
Error Handling
try {
$response = $this->domainator9k->fetchData($endpoint);
} catch (Exception $e) {
throw new \RuntimeException(
"Domainator9k failed for endpoint {$endpoint}: " . $e->getMessage(),
0, $e
);
}
Network Dependencies
$cacheKey = "domainator_{$endpoint}";
$data = $this->cache->get($cacheKey);
if (!$data) {
$data = $this->domainator9k->fetchData($endpoint);
$this->cache->set($cacheKey, $data, 300); // 5-minute cache
}
$this->domainator9k->setDebug(true); // If supported
class DebugDomainatorService implements Domainator9kInterface
{
public function fetchData($endpoint)
{
$response = $this->decorated->fetchData($endpoint);
file_put_contents(
'debug_domainator.log',
print_r(['endpoint' => $endpoint, 'response' => $response], true),
FILE_APPEND
);
return $response;
}
}
Custom Endpoints Extend the service to add domain-specific methods:
class ExtendedDomainatorService extends Domainator9kService
{
public function getUserProfile($userId)
{
return $this->fetchData("/users/{$userId}/profile");
}
}
Authentication Override token handling if the bundle uses a non-standard auth flow:
$this->domainator9k->setAuthToken($customToken);
Response Transformation Decorate the service to normalize responses:
class NormalizingDomainatorService implements Domainator9kInterface
{
public function fetchData($endpoint)
{
$raw = $this->decorated->fetchData($endpoint);
return $this->normalize($raw);
}
private function normalize($data)
{
// Transform to your domain model
}
}
host includes the scheme (e.g., https://api.example.com), not just the domain.public function __construct(Domainator9kService $service)
{
$service->ping(); // Hypothetical method; implement if missing
}
How can I help you explore Laravel packages today?