dev-master
9999999-dev https://github.com/merorafael/MeroCorreiosBundleSymfony Bundle with Correios integration
MIT
The Requires
The Development Requires
by Rafael Mello
symfony brazil correios sf mero
Symfony Bundle with Correios integration
Symfony Bundle with Correios integration, (*2)
composer require mero/correios-bundle
to add MeroCorreiosBundle in your project vendor;Mero\Bundle\CorreiosBundle\MeroCorreiosBundle()
.This bundle is only alias to use MeroCorreios., (*3)
Service | MeroCorreios Class |
---|---|
mero_correios.client | Client |
namespace Acme\Bundle\ApiBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; /** * @Route("/correios") */ class CorreiosController extends Controller { /** * @Route("/{zipCode}/address", name="search_zipcode") */ public function searchAction(string $zipCode) { $client = $this->get('mero_correios.client'); // Return the Mero\Correios\Client try { $address = $client->findAddressByZipCode($zipCode); return new JsonResponse([ 'zip_code' => $zipCode, 'address' => $address->getAddress(), 'neighborhood' => $address->getNeighborhood(), 'city' => $address->getCity(), 'state' => $address->getState(), ]); } catch (AddressNotFoundException $e) { return new JsonResponse([ 'message' => $e->getMessage(), ], 404); } catch (InvalidZipCodeException $e) { return new JsonResponse([ 'message' => $e->getMessage(), ], 404); } } }
Symfony Bundle with Correios integration
MIT
symfony brazil correios sf mero