Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

primeira versao back end pronta #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desafio-php/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
32 changes: 32 additions & 0 deletions desafio-php/app/webService/viaCep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\WebService;

class ViaCep{

/* consultando cep no via service
recebe string
retorna array */
public static function consultarCep($cep)
{
// configura curl
$curl = curl_init();
curl_setopt_array($curl,[
CURLOPT_URL => 'https://viacep.com.br/ws/'.$cep.'/xml/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST=>'GET'
]);

// reponse
$responseXml = curl_exec($curl);
// fecha conexao curl
curl_close($curl);
// convertendo xml para um array
$responseXml = simplexml_load_string($responseXml);
$responseJson = json_encode($responseXml);
$array = json_decode ($responseJson,TRUE);

// retorando conteudo e ja tratando erro
return isset($array['cep']) ? $array : null;
}
}
8 changes: 8 additions & 0 deletions desafio-php/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "desafio/c2tec",
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
18 changes: 18 additions & 0 deletions desafio-php/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions desafio-php/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

require __DIR__ . '/vendor/autoload.php';

// dependencias do projeto
use \App\WebService\ViaCep;

if(!isset($argv[1])){
die("CEP não definido\n");
}

// consutlta
$dados = ViaCep::consultarCep($argv[1]);

// imprime
print_r($dados);
7 changes: 7 additions & 0 deletions desafio-php/vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit9ce7e478f4d992be0924d3f052859784::getLoader();
Loading