mero/correios-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Symfony Bundle with Correios integration

dev-master / 0.1.x-dev 2017-06-03 19:31 UTC

This package is auto-updated.

Last update: 2023-04-17 02:43:17 UTC


README

SensioLabsInsight Latest Stable Version Total Downloads License

Symfony Bundle with Correios integration

Requirements

  • PHP 5.4.9 or above
  • SOAP extension
  • Symfony 2.8 or above

Instalation with composer

  1. Open your project directory;
  2. Run composer require mero/correios-bundle to add MeroCorreiosBundle in your project vendor;
  3. Open my/project/dir/app/AppKernel.php;
  4. 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);
        }
    }

}