Details
-
Type:
Patch
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.9.1
-
Component/s: Zend_Paginator
-
Labels:None
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()); } }
Here are the diff of the existing code, plus the new interface