/**
  * initCommandChain
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  * @return void
  */
 private function initCommandChain()
 {
     $this->core->logger->debug('core->controllers->FolderController->initCommandChain()');
     $this->objCommandChain = new CommandChain();
     if ($this->objRequest->getParam('rootLevelTypeId') == $this->core->sysConfig->root_level_types->portals) {
         $this->core->logger->debug('add page command');
         $this->objCommandChain->addCommand(new PageCommand());
     }
     if ($this->objRequest->getParam('rootLevelTypeId') == $this->core->sysConfig->root_level_types->global) {
         $this->core->logger->debug('add global command!');
         $this->objCommandChain->addCommand(new GlobalCommand((int) $this->objRequest->getParam('rootLevelGroupId'), $this->objRequest->getParam('rootLevelGroupKey')));
     }
 }
Example #2
0
}

class MailCommand implements ICommand {

    public function onCommand($name, $args) {
        if ($name != 'mail')
            return false;
        echo( "MailCommand handling 'mail'\n" );
        return true;
    }

}

$cc = new CommandChain();
$cc->addCommand(new UserCommand());
$cc->addCommand(new MailCommand());
$cc->runCommand('addUser', null);
$cc->runCommand('mail', null);
?>



<?php

/*
  « 5 - The strategy pattern »
  <<------------------------------------------------------------------------------
  resultado da execução:
  Array
  (
class CustCommand implements Command
{
    public function onCommand($name, $args)
    {
        if ($name !== 'addCustomer') {
            return false;
        } else {
            echo 'This is Customer Command handling "addCustomer"' . PHP_EOL;
            echo 'The args:' . $args . PHP_EOL;
            return true;
        }
    }
}
class MailCommand implements Command
{
    public function onCommand($name, $args)
    {
        if ($name !== 'sendMail') {
            return false;
        } else {
            echo 'This is Mail Command handling "sendMail"' . PHP_EOL;
            echo 'The args:' . $args . PHP_EOL;
            return true;
        }
    }
}
$chain = new CommandChain();
$chain->addCommand(new CustCommand());
$chain->addCommand(new MailCommand());
$chain->runCommand('addCustomer', 'lcpeng');
$chain->runCommand('sendMail', '*****@*****.**');