PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1

CHAPTER 12 ■ ENTERPRISE PATTERNS


//...


class ControllerMap {
private $viewMap = array();
private $forwardMap = array();
private $classrootMap = array();


function addClassroot( $command, $classroot ) {
$this->classrootMap[$command]=$classroot;
}


function getClassroot( $command ) {
if ( isset( $this->classrootMap[$command] ) ) {
return $this->classrootMap[$command];
}
return $command;
}


function addView( $command='default', $status=0, $view ) {
$this->viewMap[$command][$status]=$view;
}


function getView( $command, $status ) {
if ( isset( $this->viewMap[$command][$status] ) ) {
return $this->viewMap[$command][$status];
}
return null;
}


function addForward( $command, $status=0, $newCommand ) {
$this->forwardMap[$command][$status]=$newCommand;
}


function getForward( $command, $status ) {
if ( isset( $this->forwardMap[$command][$status] ) ) {
return $this->forwardMap[$command][$status];
}
return null;
}
}


The $classroot property is simply an associative array that maps command handles (that is, the
names of the command elements in configuration) to the roots of Command class names (that is, AddVenue,
as opposed to woo_command_AddVenue). This is used to determine whether the cmd parameter is an alias to
a particular class file. During the parsing of the configuration file, the addClassroot() method is called to
populate this array.
The $forwardMap and $viewMap arrays are both two-dimensional, supporting combinations of
commands and statuses.

Free download pdf