Skip to content

Instantly share code, notes, and snippets.

@augustohp
Created December 28, 2011 18:53
Show Gist options
  • Save augustohp/1529167 to your computer and use it in GitHub Desktop.
Save augustohp/1529167 to your computer and use it in GitHub Desktop.
Example iterator
<?php
class Entidade
{
public function toArray()
{
return array('uhull');
}
}
class EntityIterator extends \ArrayIterator
{
public function append($value)
{
if (!$value instanceof Entidade)
throw new \InvalidArgumentException('Esperada entidade');
parent::append($value);
}
public function current()
{
return parent::current()->toArray();
}
}
$all = array();
for ($i=0; $i<5; $i++)
$all[] = new Entidade();
$iterator = new EntityIterator($all);
var_dump($iterator);
foreach ($iterator as $one) {
var_dump($one);
}
@augustohp
Copy link
Author

@flechaweb see this =D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment