cm2tech/soluti-bird-id-symfony-bundle
Installation
composer require cm2tech/soluti-bird-id-symfony-bundle
Ensure your config/packages/soluti_bird_id.yaml is properly configured (if auto-generated, verify credentials).
First Use Case: Fetching a Client Token
use Soluti\BirdIdSymfonyBundle\Service\OauthService;
use Soluti\BirdIdSymfonyBundle\Request\ClientToken;
$request = new ClientToken('CLIENT_ID', 'CLIENT_SECRET');
$response = OauthService::clientToken($request);
// Parse response (e.g., JSON)
$data = json_decode($response->getContent(false), true);
Where to Look First
src/Service/OauthService.php (core logic for API calls).src/Request/ (e.g., ClientToken.php for payloads).config/packages/soluti_bird_id.yaml (credentials, endpoints).OAuth Token Flow
ClientToken for initial token acquisition (e.g., in a LoginController or AuthService).CacheInterface) to avoid repeated requests.// Example: Cached token retrieval
$cache = $this->get('cache.app');
$token = $cache->get('bird_id_token');
if (!$token) {
$token = OauthService::clientToken(new ClientToken($clientId, $clientSecret));
$cache->set('bird_id_token', $token, 3500); // 1h TTL
}
API Integration
HttpClient middleware).$client = $this->get('http_client');
$client->setDefaultOptions([
'headers' => [
'Authorization' => 'Bearer ' . $token->getContent(),
],
]);
Event-Driven Patterns
KernelEvents::REQUEST) to inject BirdID logic dynamically.OauthService via constructor for testability.
public function __construct(private OauthService $oauthService) {}
CLIENT_ID/CLIENT_SECRET in .env (e.g., BIRD_ID_CLIENT_ID).ClientException/ServerException.
try {
$response = $this->oauthService->clientToken($request);
} catch (\Exception $e) {
$this->logger->error('BirdID API failed: ' . $e->getMessage());
throw new \RuntimeException('BirdID service unavailable');
}
Hardcoded Endpoints
api.birdid.com.br). Override via config if testing locally:
# config/packages/soluti_bird_id.yaml
soluti_bird_id:
endpoints:
oauth_application: 'http://localhost:8000/oauth/application'
Token Expiry
if ($response->getStatusCode() === 401) {
$token = OauthService::clientToken(new ClientToken(...));
// Retry request with new token
}
No Symfony HTTP Client Integration
Limited Request Types
ClientToken is exposed. For other endpoints (e.g., /v0/oauth/application), extend OauthService:
// src/Service/OauthService.php (extend)
public static function applicationToken(ApplicationRequest $request) { ... }
APP_DEBUG=true in .env to see raw API responses.Monolog to log payloads:
$this->logger->debug('BirdID Response', ['status' => $response->getStatusCode(), 'body' => $response->getContent()]);
Custom Requests
Request\AbstractRequest to support additional BirdID endpoints:
class CustomRequest extends AbstractRequest {
public function __construct(string $customParam) { ... }
}
Response Decorators
OauthService to transform responses (e.g., auto-parse JSON):
class DecoratedOauthService implements OauthServiceInterface {
public function clientToken(ClientToken $request): ResponseInterface {
$response = $this->decorated->clientToken($request);
return new JsonResponse(json_decode($response->getContent(), true));
}
}
Event Listeners
// src/EventListener/BirdIdListener.php
public function onKernelRequest(GetResponseEvent $event) {
if ($event->isMasterRequest()) {
$token = OauthService::clientToken(...);
// Attach to request
}
}
How can I help you explore Laravel packages today?