Issues

ZF-7602: Patch to add IteratorAggregate like behaviour to Zend_Paginator

Issue Type: Patch Created: 2009-08-15T02:04:23.000+0000 Last Updated: 2009-08-16T05:30:10.000+0000 Status: Resolved Fix version(s): - 1.9.1 (11/Aug/09)

Reporter: Benjamin Eberlei (beberlei) Assignee: Jurrien Stutterheim (norm2782) Tags: - Zend_Paginator

Related issues: Attachments: - zf7602.diff

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:

<pre class="highlight">
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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts