mero / correios-bundle
Symfony Bundle with Correios integration
Installs: 40
Dependents: 0
Suggesters: 1
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.4.9
- mero/correios: ^0.1
- symfony/framework-bundle: ~2.8|~3.0|~4.0
Requires (Dev)
- phpunit/phpunit: ~4.4
- satooshi/php-coveralls: ~1.0
- symfony/symfony: ~2.8
Suggests
- mero/base-bundle: Bundle for Symfony with Correios integration
- mero/br-validator-bundle: Bundle for Symfony with validators for Brazilian location
- mero/telegram-handler: Monolog handler to send log via Telegram
This package is auto-updated.
Last update: 2023-04-17 02:43:17 UTC
README
Symfony Bundle with Correios integration
Requirements
- PHP 5.4.9 or above
- SOAP extension
- Symfony 2.8 or above
Instalation with composer
- Open your project directory;
- Run
composer require mero/correios-bundle
to add MeroCorreiosBundle in your project vendor; - Open my/project/dir/app/AppKernel.php;
- Add
Mero\Bundle\CorreiosBundle\MeroCorreiosBundle()
.
Correios Client
This bundle is only alias to use MeroCorreios.
Service | MeroCorreios Class |
---|---|
mero_correios.client | Client |
Usage example
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); } } }