Beispiel #1
0
 public static function index()
 {
     $pancakeHouseMenu = new PancakeHouseMenu();
     $dinerMenu = new DinerMenu();
     // ---------------------------
     // with no iterators
     echo "<br/>MENU<br/>----<br/>BREAKFAST";
     $breakfastItems = $pancakeHouseMenu->getMenuItems();
     for ($i = 0; $i < count($breakfastItems); $i++) {
         $menuItem = $breakfastItems[$i];
         echo $menuItem . '<br/>';
     }
     // or foreach
     echo "<br/>LUNCH";
     $lunchItems = $dinerMenu->getMenuItems();
     for ($i = 0; $i < count($lunchItems); $i++) {
         $menuItem = $lunchItems[$i];
         echo $menuItem . '<br/>';
     }
     // or foreach
     // ---------------------------
     // with iterators
     $pancakeIterator = $pancakeHouseMenu->createIterator();
     $dinerIterator = $dinerMenu->createIterator();
     echo "<br/>MENU (with iterators)<br/>----<br/>BREAKFAST";
     self::printMenu($pancakeIterator);
     echo "<br/>LUNCH";
     self::printMenu($dinerIterator);
 }
 private function printVegetarianMenu(My2Iterator $iterator = NULL)
 {
     if ($iterator == NULL) {
         printVegetarianMenu($this->pancakeHouseMenu->createIterator());
         printVegetarianMenu($this->dinerMenu->createIterator());
     } else {
         while ($iterator->hasNext()) {
             $menuItem = $iterator->next();
             if ($menuItem->isVegetarian()) {
                 print $menuItem->getName();
                 println("\t\t" . $menuItem->getPrice());
                 println("\t" . $menuItem->getDescription());
             }
         }
     }
 }
 public static function printMenu()
 {
     $pancakeHouseMenu = new PancakeHouseMenu();
     $dinerMenu = new DinerMenu();
     $breakfastItems = $pancakeHouseMenu->getMenuItems();
     for ($i = 0; $i < $breakfastItems->size(); $i++) {
         $menuItem = $breakfastItems->get($i);
         print $menuItem->getName();
         println("\t\t" . $menuItem->getPrice());
         println("\t" . $menuItem->getDescription());
     }
     $lunchItems = $dinerMenu->getMenuItems();
     for ($i = 0; $i < count($lunchItems); $i++) {
         $menuItem = $lunchItems[$i];
         print $menuItem->getName();
         println("\t\t" . $menuItem->getPrice());
         println("\t" . $menuItem->getDescription());
     }
 }
Beispiel #4
0
<?php

function __autoload($class_name)
{
    require_once $class_name . '.php';
}
function printMenu(MyIterator $iterator)
{
    while ($iterator->hasNext()) {
        $menuItem = $iterator->next();
        echo $menuItem->getName() . "\n";
        echo $menuItem->getPrice() . "\n";
        echo $menuItem->getDescription() . "\n";
        echo "\n";
    }
}
$pancakeHouseMenu = new PancakeHouseMenu();
$breakfastItems = $pancakeHouseMenu->createIterator();
$dinerMenu = new DinerMenu();
$lunchItems = $dinerMenu->createIterator();
echo "Breakfast Items\n";
echo printMenu($breakfastItems);
echo "Lunch Items\n";
echo printMenu($lunchItems);