Example use case:
<?php
class MyIterator implements IteratorAggregate
{
/**
* @var string
*/
private $url;
/**
* MyIterator constructor.
* @param $url
*/
public function __construct($url)
{
$this->url = $url;
}
/**
* @inheritDoc
*/
public function getIterator()
{
$content = file_get_contents($this->url);
try {
return @new SimpleXMLIterator($content);
} catch (Exception $e) { // Case $content is not valid XML, but you don't care
return new EmptyIterator();
}
}
}
?>