-
-
Save netojoaobatista/7449164 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 | |
/** | |
* Eu já disse que o nome Entidades é muito ruim para um namespace? | |
*/ | |
namespace Entidades; | |
class Company | |
{ | |
private $contacts = array(); | |
private $contactIterator; | |
public function addContact(Contact $contact) | |
{ | |
$this->contacts[] = $contact; | |
} | |
public function getContactIterator() | |
{ | |
if ($this->contactIterator == null) { | |
$this->contactIterator = new ArrayIterator($this->contacts) | |
} | |
return $this->contactIterator; | |
} | |
} |
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 | |
/** | |
* Consigo pensar em poucos nomes tão ruins para um namespace, | |
* quando Entidades. | |
*/ | |
namespace Entidades; | |
class Contact | |
{ | |
private $id; | |
private $key; | |
private $value; | |
public function __construct($key, $value) | |
{ | |
$this->key = $key; | |
$this->value = $value; | |
} | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function getKey() | |
{ | |
return $this->key; | |
} | |
public function getValue() | |
{ | |
return $this->value; | |
} | |
} |
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\Company; | |
use Entidades\Contact; | |
$company = new Company(); | |
$company->addContact(new Contact('Telefone Financeiro', '16-3202-xxxx')); | |
$company->addContact(new Contact('Telefone Comercial', '16-3202-xxxx')); | |
$company->addContact(new Contact('Site', 'www.empresa.com')); | |
$company->addContact(new Contact('Facebook', 'facebook.com/empresa')); | |
$company->addContact(new Contact('Twitter', 'twitter.com/empresa')); | |
foreach ($company->getContactIterator() as $contact) { | |
printf("%10s: %s\n", $contact->getKey(), $contact->getValue()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Na linha 21 do arquivo Company.php ta faltando um ponto e vírgula e falta uma contra barra na instanciação da classe ArrayIterator.