Last active
December 28, 2015 05:19
-
-
Save Bolinha1/7448437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Entidades; | |
use Exception; | |
class Contato | |
{ | |
private $idContato; | |
private $telefone; | |
private $email; | |
public function setIdContato($id) | |
{ | |
if(!(int)$id) | |
throw new Exception('Espera receber um valor inteiro.'); | |
else | |
$this->idContato = $id; | |
} | |
public function getIdContato() | |
{ | |
return $this->idContato; | |
} | |
public function setTelefone($telefone) | |
{ | |
$this->telefone = $telefone; | |
} | |
public function getTelefone() | |
{ | |
return $this->telefone; | |
} | |
public function setEmail($email) | |
{ | |
$email = strtolower($email); | |
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) | |
throw new Exception('Email invalido.'); | |
else | |
$this->email = $email; | |
} | |
public function getEmail() | |
{ | |
return $this->email; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Entidades; | |
class Empresa | |
{ | |
private $contato; | |
private $contatoEmpresa; | |
public function __construct() | |
{ | |
} | |
public function addContato($telefone, $email) | |
{ | |
$this->contato = new Contato; | |
$this->contato->setTelefone($telefone); | |
$this->contato->setEmail($email); | |
$this->contatoEmpresa[] = $this->contato; | |
} | |
public function getContato() | |
{ | |
return $this->contatoEmpresa; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Entidades\Empresa; | |
use Entidades\Contato; | |
$contato = new Contato; | |
$empresa = new Empresa($contato); | |
$empresa->setNomeResponsavel('Eduardo'); | |
$empresa->addContato('16-3202-xxxx', '[email protected]'); | |
$empresa->addContato('16-3202-wwww', '[email protected]'); | |
$empresa->addContato('16-9295-yyyy', '[email protected]'); | |
print_r($empresa->getContato()); | |
/** | |
Resultado | |
Array | |
( | |
[0] => Entidades\Contato Object | |
( | |
[idContato:Entidades\Contato:private] => | |
[telefone:Entidades\Contato:private] => 16-3202-xxxx | |
[email:Entidades\Contato:private] => [email protected] | |
) | |
[1] => Entidades\Contato Object | |
( | |
[idContato:Entidades\Contato:private] => | |
[telefone:Entidades\Contato:private] => 16-3202-wwww | |
[email:Entidades\Contato:private] => [email protected] | |
) | |
[2] => Entidades\Contato Object | |
( | |
[idContato:Entidades\Contato:private] => | |
[telefone:Entidades\Contato:private] => 16-9295-yyyy | |
[email:Entidades\Contato:private] => [email protected] | |
) | |
) | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment