Ejemplo n.º 1
0
 protected function initialize()
 {
     if ($this->initialized) {
         return;
     }
     $items = $this->items;
     // Handle search
     if (isset($this->searchExpression)) {
         $searchCallback = $this->buildExpressionCallback($this->searchExpression);
         $items = array_filter($items, $searchCallback);
     }
     // Handle filters
     if (isset($this->filterExpression)) {
         $filterCallback = $this->buildExpressionCallback($this->filterExpression);
         $items = array_filter($items, $filterCallback);
     }
     // @TODO Handle sort
     // Handle pagination
     if (isset($this->limitPerPage)) {
         $paginator = new ArrayPaginator($items);
         $paginator->setLimitPerPage($this->limitPerPage)->setRangeLimit($this->rangeLimit)->setPage($this->page);
         $this->iterator = $paginator->getIterator();
         $this->paginator = $paginator;
     } else {
         $this->iterator = new \ArrayIterator($items);
         $this->paginator = null;
     }
     $this->initialized = true;
 }
Ejemplo n.º 2
0
 /**
  * Test the IteratorAggregate implementation
  *
  */
 public function testIteration()
 {
     $items = $this->buildItems(20);
     $eleventhItem = $items[10];
     $paginator = new ArrayPaginator($items);
     $paginator->setLimitPerPage(10);
     $paginator->setPage(2);
     foreach ($paginator as $item) {
         break;
     }
     $this->assertEquals($eleventhItem, $item);
 }