コード例 #1
0
ファイル: UfTest.php プロジェクト: gabrielfs7/brasil-utils
 /**
  * @return array
  */
 public function ufPorCepProvider()
 {
     $out = [];
     foreach (Cep::getIntervalosDeCep() as $uf => $intervalosCep) {
         foreach ($intervalosCep as $intervalo) {
             foreach ($intervalo as $cep) {
                 $out[] = array_merge([$uf], [$cep]);
             }
         }
     }
     return $out;
 }
コード例 #2
0
ファイル: Uf.php プロジェクト: gabrielfs7/brasil-utils
 /**
  * @param $cep
  * @return string
  * @throws EnderecoInvalidoException
  */
 public static function getUfPorCep($cep)
 {
     foreach (Cep::getIntervalosDeCep() as $uf => $intervalos) {
         foreach ($intervalos as $ceps) {
             $prefixoCep = substr($cep, 0, 3);
             $prefixoInicial = substr($ceps[0], 0, 3);
             $prefixoFinal = substr($ceps[1], 0, 3);
             if ($prefixoCep >= $prefixoInicial && $prefixoCep <= $prefixoFinal) {
                 return $uf;
             }
         }
     }
     throw new EnderecoInvalidoException('O CEP ' . $cep . ' não pertence a nenhum estado.');
 }