blancohugo/correios

Consulta de cep no SIGEP dos Correios com PHP

v1.0 2018-09-11 21:16 UTC

This package is auto-updated.

Last update: 2024-10-26 09:32:51 UTC


README

Latest version CircleCI Code Coverage Download count

A service for fetching data from an address from a provided zip code.

Installation

$ composer require blancohugo/correios

How-to

See the example below of how to implement a search for address data:

<?php

require 'vendor/autoload.php';

use BlancoHugo\Correios\Zipcode;
use BlancoHugo\Correios\Client;
use BlancoHugo\Correios\Exception;

$client = new Client();
$address = $client->query(new Zipcode('01311-929'));

The client class uses exceptions for data treatments. Make sure your code will have a treatment for the following situations:

<?php

try {
    $address = $client->query(new Zipcode('01311-929'));
} catch (Exception\InvalidZipcodeException $e) {
    // Invalid zipcode
} catch (Exception\ZipcodeNotFoundException $e) {
    // Address data not found
} catch (Exception\UnexpectedResponseException $e) {
    // Unexpected response from SIGEP
}

Contributing

See how to CONTRIBUTE to this project.