Hello World! <?php

class Cmd_Macro
{
   private 
$_commands = array();
  
  public function 
add(Cmd_ICommand $c)
  {
     
$this->_commands[] = $c;
  }
  
  public function 
run()
  {
    
// iterator $it
    
foreach ($this->_commands as $it) {
        
$it->execute();
    }
  }
};


// Interface for the Command Pattern 

interface Cmd_ICommand {
     public function 
execute();
     
// public function undo();
};


// Anwendung
class Hello implements Cmd_ICommand 
{
      public function 
execute() 
      {
              echo 
"Hello ";
      }
};
  
class 
World implements Cmd_ICommand 
{
     public function 
execute() 
     {
        echo 
"World!\n";
     }
};
 
$macro = new Cmd_Macro();
 
$macro->add(new Hello);
$macro->add(new World);
$macro->run(); // Hello World!


show_source(__FILE__);
?>