コード例 #1
0
 /**
  * get book at current index
  *
  * @return Object
  */
 public function next()
 {
     /** @var Book $book */
     $book = $this->bookShelf->getBookAt($this->index);
     $this->index++;
     return $book;
 }
コード例 #2
0
<?php

require 'interfaces/Aggregate.php';
require 'interfaces/Iterator.php';
require 'classes/Book.php';
require 'classes/BookShelf.php';
require 'classes/BookShelfIterator.php';
require 'classes/BookShelfReverseIterator.php';
use classes\Book;
use classes\BookShelf;
use classes\BookShelfIterator;
use classes\BookShelfReverseIterator;
$bookShelf = new BookShelf();
$bookShelf->appendBook(new Book('perfect php'));
$bookShelf->appendBook(new Book('perfect ruby'));
$bookShelf->appendBook(new Book('perfect java'));
$bookShelf->appendBook(new Book('perfect c++'));
$bookShelf->appendBook(new Book('perfect rails'));
/** @var BookShelfIterator $iterator */
$iterator = $bookShelf->iterator();
/** @var BookShelfReverseIterator $reverseIterator */
$reverseIterator = $bookShelf->reverseIterator();
echo "-------  Order -------\n";
while ($iterator->hasNext()) {
    /** @var Book $book */
    $book = $iterator->next();
    echo $book->getName() . "\n";
}
echo "------- Reverse Order -------\n";
while ($reverseIterator->hasNext()) {
    /** @var Book $book */
コード例 #3
0
 /**
  * @return Object
  */
 public function next()
 {
     $book = $this->bookShelf->getBookAt($this->index);
     $this->index--;
     return $book;
 }