ZF-7602: Patch to add IteratorAggregate like behaviour to Zend_Paginator
Description
The IteratorAggregate Interface is a nice way to write Iterators that contain only small deviations from any existing iterator.
I have a patch to propose the same for Zend_Paginator, an interface called "Zend_Paginator_AdapterAggregate" which has the method getPaginatorAdapter() that creates a Paginator Adapter.
This interface must be supported in two locations of Zend_Paginator, the factory method and the constructor.
Here is the testcode, that shows the behaviour:
class Zend_Paginator_TestArrayAggregate implements Zend_Paginator_AdapterAggregate
{
public function getPaginatorAdapter()
{
return new Zend_Paginator_Adapter_Array(array(1, 2, 3, 4));
}
}
class Zend_PaginatorTest extends PHPUnit_Framework_TestCase
{
//...
public function testAcceptAndHandlePaginatorAdapterAggregateDataInFactory()
{
$p = Zend_Paginator::factory(new Zend_Paginator_TestArrayAggregate());
$this->assertEquals(1, count($p));
$this->assertType('Zend_Paginator_Adapter_Array', $p->getAdapter());
$this->assertEquals(4, count($p->getAdapter()));
}
public function testAcceptAndHandlePaginatorAdapterAggreageInConstructor()
{
$p = new Zend_Paginator(new Zend_Paginator_TestArrayAggregate());
$this->assertEquals(1, count($p));
$this->assertType('Zend_Paginator_Adapter_Array', $p->getAdapter());
$this->assertEquals(4, count($p->getAdapter()));
}
public function testInvalidDataInConstructor_ThrowsException()
{
$this->setExpectedException("Zend_Paginator_Exception");
$p = new Zend_Paginator(array());
}
}
Comments
Posted by Benjamin Eberlei (beberlei) on 2009-08-15T02:08:23.000+0000
Here are the diff of the existing code, plus the new interface
Posted by Jurrien Stutterheim (norm2782) on 2009-08-16T05:30:07.000+0000
Resolved in trunk in r.17630. Merged to release-1.9 in r.17631