Zend Framework

Patch to add IteratorAggregate like behaviour to Zend_Paginator

Details

  • Type: Patch Patch
  • Status: Resolved Resolved
  • Priority: Major 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());
    }
}
  1. zf7602_adapteraggregate_interface.php
    15/Aug/09 2:08 AM
    2 kB
    Benjamin Eberlei
  2. zf7602.diff
    15/Aug/09 2:07 AM
    6 kB
    Benjamin Eberlei

Activity

Hide
Benjamin Eberlei added a comment -

Here are the diff of the existing code, plus the new interface

Show
Benjamin Eberlei added a comment - Here are the diff of the existing code, plus the new interface
Hide
Jurrien Stutterheim added a comment -

Resolved in trunk in r.17630. Merged to release-1.9 in r.17631

Show
Jurrien Stutterheim added a comment - Resolved in trunk in r.17630. Merged to release-1.9 in r.17631

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: