A modest collection of PHP libraries used at SparkFun.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

61 lines
1.4 KiB

<?php
namespace SparkLib\Iterator;
class Wrapper extends \SparkLib\Iterator {
protected $_iterator;
protected $_wrapperClass;
public function __construct (\Iterator $iterator, $wrapper_class = '\stdClass')
{
$this->_iterator = $iterator;
$this->_wrapperClass = $wrapper_class;
}
public function iterator ()
{
return $this->_iterator;
}
public function current ()
{
if ($this->_iterator->valid()) {
return $this->makeInstance($this->_iterator->current());
} else {
return $this->_iterator->current();
}
}
public function getNext ()
{
$result = $this->_iterator->getNext();
if ($result)
return $this->makeInstance($result);
else
return $result;
}
protected function makeInstance ($result)
{
$wclass = $this->_wrapperClass;
return new $wclass($result);
}
/**
* Pass method calls through to the underlying iterator.
*/
public function __call ($name, $arguments)
{
return call_user_func_array(array($this->_iterator, $name), $arguments);
}
/**
* These could be handled by __call(), except we're implementing
* the SPL Iterator interface, and it expects them to be defined.
*/
public function key () { return $this->_iterator->key(); }
public function next () { return $this->_iterator->next(); }
public function rewind () { return $this->_iterator->rewind(); }
public function valid () { return $this->_iterator->valid(); }
}