CHAPTER 12 ■ ENTERPRISE PATTERNS
Recall this fragment:
Here is the call the parse code will make to add the correct element to the $viewMap property:
$map->addView( 'AddVenue', 0, 'addvenue' );
and here is the call for populating the $forwardMap property:
$map->addForward( 'AddVenue', 1, 'AddSpace' );
The application controller class uses these combinations in a particular search order. Let’s say the
AddVenue command has returned CMD_OK (which maps to 1, while 0 is CMD_DEFAULT). The application
controller will search the $forwardMap array from the most specific combination of Command and status
flag to the most general. The first match found will be the command string that is returned:
$viewMap['AddVenue'][1]; // AddVenue CMD_OK [MATCHED]
$viewMap['AddVenue'][0]; // AddVenue CMD_DEFAULT
$viewMap['default'][1]; // DefaultCommand CMD_OK
$viewMap['default'][0]; // DefaultCommand CMD_DEFAULT
The same hierarchy of array elements is searched in order to retrieve a view.
Here is an application controller:
namespace woo\controller;
//..
class AppController {
private static $base_cmd;
private static $default_cmd;
private $controllerMap;
private $invoked = array();
function __construct( ControllerMap $map ) {
$this->controllerMap = $map;
if (! self::$base_cmd ) {
self::$base_cmd = new \ReflectionClass( "\woo\command\Command" );
self::$default_cmd = new \woo\command\DefaultCommand();
}
}
function getView( Request $req ) {
$view = $this->getResource( $req, "View" );
return $view;
}
function getForward( Request $req ) {
$forward = $this->getResource( $req, "Forward" );
if ( $forward ) {