Installation
composer require fontai/fcc-bundle
Add to config/bundles.php (Symfony) or config/app.php (Laravel via bridge):
return [
// ...
Fontai\FccBundle\FontaiFccBundle::class => ['all' => true],
];
Configuration Publish the default config:
php artisan vendor:publish --provider="Fontai\FccBundle\FontaiFccBundle" --tag="config"
Edit config/fontai_fcc.php to set API endpoints, credentials, and default options.
First Use Case: API Request Inject the client into a service/controller:
use Fontai\FccBundle\Client\FccClient;
public function __construct(private FccClient $fccClient) {}
public function fetchData()
{
$response = $this->fccClient->get('/api/v1/data');
return $response->json();
}
API Integration
$this->fccClient->get('/endpoint', ['param' => 'value'])
->withHeaders(['Authorization' => 'Bearer token'])
->send();
$this->fccClient->setAuthToken('dynamic_token');
Data Transformation
Response wrapper to parse/validate:
$data = $this->fccClient->post('/transform', $payload)
->assertStatus(200)
->getData();
Event-Driven Extensions
fcc.before_request/fcc.after_response events in EventServiceProvider:
protected $listen = [
'fcc.before_request' => [
\App\Listeners\LogFccRequest::class,
],
];
AppServiceProvider:
$this->app->bind(FccClient::class, function ($app) {
return new FccClient(config('fontai_fcc.base_uri'));
});
$cachedClient = new CachedFccClient($this->fccClient, new FileCache());
$this->mock(FccClient::class)->shouldReceive('get')->andReturn(new Response(200, [], '{}'));
Deprecated Guzzle Version
composer require guzzlehttp/guzzle:^7.0
$this->app->bind(\GuzzleHttp\Client::class, function () {
return new \GuzzleHttp\Client();
});
No Laravel-Specific Docs
KernelEvents::REQUEST).Config Overrides
config/fontai_fcc.php may not load by default. Ensure the bundle is registered in config/app.php:
'providers' => [
// ...
Fontai\FccBundle\FontaiFccBundle::class,
],
Enable Guzzle Debugging:
Add to config/fontai_fcc.php:
'debug' => env('APP_DEBUG', false),
Logs will appear in storage/logs/laravel.log.
Common Errors:
auth_token in config or use dynamic auth.base_uri endpoint and payload structure.Custom Clients
Extend FccClient to add middleware:
class CustomFccClient extends FccClient {
public function __construct(string $baseUri) {
parent::__construct($baseUri);
$this->getEmitter()->addListener(
'request',
function (RequestInterface $request) {
$request = $request->withHeader('X-Custom-Header', 'value');
return $request;
}
);
}
}
Response Decorators Create a decorator to transform responses:
class DecoratedFccClient implements FccClientInterface {
public function __construct(private FccClient $client) {}
public function get(string $uri, array $options = []): ResponseInterface {
$response = $this->client->get($uri, $options);
return $this->decorateResponse($response);
}
private function decorateResponse(ResponseInterface $response): ResponseInterface {
// Add custom logic (e.g., normalize data)
return $response;
}
}
Event Listeners
Listen for fcc.response to modify responses globally:
public function handle(FccResponseEvent $event) {
$event->setData($this->normalizeData($event->getData()));
}
How can I help you explore Laravel packages today?