Skip to content

Instantly share code, notes, and snippets.

@Bolinha1
Last active December 28, 2015 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Bolinha1/7448437 to your computer and use it in GitHub Desktop.
Save Bolinha1/7448437 to your computer and use it in GitHub Desktop.
<?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;
}
}
<?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;
}
}
use Entidades\Empresa;
use Entidades\Contato;
$contato = new Contato;
$empresa = new Empresa($contato);
$empresa->setNomeResponsavel('Eduardo');
$empresa->addContato('16-3202-xxxx', 'eduardo-borsato@hotmail.com');
$empresa->addContato('16-3202-wwww', 'eduardo.borsato.oli@gmail.com');
$empresa->addContato('16-9295-yyyy', 'eduardo.oliveira@atualgestaoti.com.br');
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] => eduardo-borsato@hotmail.com
)
[1] => Entidades\Contato Object
(
[idContato:Entidades\Contato:private] =>
[telefone:Entidades\Contato:private] => 16-3202-wwww
[email:Entidades\Contato:private] => eduardo.borsato.oli@gmail.com
)
[2] => Entidades\Contato Object
(
[idContato:Entidades\Contato:private] =>
[telefone:Entidades\Contato:private] => 16-9295-yyyy
[email:Entidades\Contato:private] => eduardo.oliveira@atualgestaoti.com.br
)
)
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment