brazilianfriendsofsymfony/frete-bundle
ContainerInterface, DependencyInjection, and HttpClient. Laravel’s DI container and HTTP stack (Guzzle) are incompatible without adapters.brazilianfriends/frete-calculator) and consume it via Laravel’s HTTP client.symfony/http-client v4.x), which could conflict with Laravel’s ecosystem.| Component | Symfony Fit | Laravel Fit | Mitigation Strategy |
|---|---|---|---|
| Dependency Injection | Native (ContainerInterface) |
Incompatible (Laravel’s Container) |
Use Laravel’s bind() or a facade pattern. |
| HTTP Client | Symfony’s HttpClient |
Guzzle (default) or Laravel HTTP Client | Abstract HTTP calls to a shared interface. |
| Configuration | Symfony’s Configuration |
Laravel’s .env + config/ |
Map Symfony params to Laravel config/environment variables. |
| Event System | Symfony Events | Laravel Events | Decouple event listeners if needed. |
| Validation | Symfony Validator | Laravel Validator | Use a shared validation library (e.g., Respect/Validation). |
composer require brazilianfriendsofsymfony/frete-bundle
config/bundles.php.parameters.yml or .env with Correios credentials:
bfos_frete:
codigo_empresa: "%env(CORREIOS_CODE)%"
senha: "%env(CORREIOS_PASSWORD)%"
BFOS\FreteBundle\Service\FreteService into controllers/services.$frete = $freteService->calcularFrete([
'codigo_servico' => '40010',
'peso' => 1.5,
'largura' => 20,
'altura' => 10,
'comprimento' => 30,
'cidade_origem' => '01001000',
'cidade_destino' => '01311000',
]);
HttpClient for unit tests.// app/Providers/FreteServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use BFOS\FreteBundle\Service\FreteService as SymfonyFreteService;
use Illuminate\Support\Facades\Http;
class FreteServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton('frete', function ($app) {
return new class {
public function calcularFrete(array $params) {
// Use Guzzle/Laravel HTTP client to call Correios API directly
// or extract bundle logic into a standalone class.
$response = Http::post('https://api.correios.com/v1/frete', $params);
return $response->json();
}
};
});
}
}
brazilianfriends/frete-calculator).composer require brazilianfriends/frete-calculator
.env:
CORREIOS_CODE=your_code
CORREIOS_PASSWORD=your_password
config/services.php:
'frete' => [
'codigo_empresa' => env('CORREIOS_CODE'),
'senha' => env('CORREIOS_PASSWORD'),
],
use Illuminate\Support\Facades\Frete;
$frete = Frete::calcularFrete([
'codigo_servico' => '40010',
'peso' => 1.5,
// ... other params
]);
Http::fake() for API responses./api/frete/calculate).How can I help you explore Laravel packages today?