class_WebLoginAreaCommand.php

Go to the documentation of this file.
00001 <?php
00024 class WebLoginAreaCommand extends BaseCommand implements Commandable {
00028         private $actionName = "";
00029 
00035         protected function __construct () {
00036                 // Call parent constructor
00037                 parent::__construct(__CLASS__);
00038         }
00039 
00046         public final static function createWebLoginAreaCommand (CommandResolver $resolverInstance) {
00047                 // Get new instance
00048                 $commandInstance = new WebLoginAreaCommand();
00049 
00050                 // Set the application instance
00051                 $commandInstance->setResolverInstance($resolverInstance);
00052 
00053                 // Load general data like user status and such
00054                 $commandInstance->prepareCommand();
00055 
00056                 // Return the prepared instance
00057                 return $commandInstance;
00058         }
00059 
00066         protected function prepareCommand () {
00067         }
00068 
00076         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
00077                 // Get the action instance from registry
00078                 $actionInstance = Registry::getRegistry()->getInstance('action');
00079 
00080                 // Do we have an action here?
00081                 if ($actionInstance instanceof PerformableAction) {
00082                         // Execute the action (shall not output anything, see below why)
00083                         $actionInstance->execute($requestInstance, $responseInstance);
00084                 } // END - if
00085 
00086                 // Get the application instance
00087                 $appInstance = $this->getResolverInstance()->getApplicationInstance();
00088 
00089                 // Prepare a template instance
00090                 $templateInstance = $this->prepareTemplateInstance($appInstance);
00091 
00092                 // Assign base URL
00093                 $templateInstance->assignConfigVariable('base_url');
00094 
00095                 // Assign all the application's data with template variables
00096                 $templateInstance->assignApplicationData($appInstance);
00097 
00098                 // Load the master template
00099                 $masterTemplate = $appInstance->getMasterTemplate();
00100 
00101                 // Load header template
00102                 $templateInstance->loadCodeTemplate('header');
00103 
00104                 // Compile and assign it with a variable
00105                 $templateInstance->compileTemplate();
00106                 $templateInstance->assignTemplateWithVariable('header', 'header');
00107 
00108                 // Load footer template
00109                 $templateInstance->loadCodeTemplate('footer');
00110 
00111                 // Compile and assign it with a variable
00112                 $templateInstance->compileTemplate();
00113                 $templateInstance->assignTemplateWithVariable('footer', 'footer');
00114 
00115                 // Load the matching template
00116                 $templateInstance->loadCodeTemplate('action_' . $this->actionName);
00117 
00118                 // Assign the template with the master template as a content ... ;)
00119                 $templateInstance->compileTemplate();
00120                 $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
00121 
00122                 // Load main template
00123                 $templateInstance->loadCodeTemplate('login_main');
00124 
00125                 // Assign the main template with the master template as a content ... ;)
00126                 $templateInstance->compileTemplate();
00127                 $templateInstance->assignTemplateWithVariable('login_main', 'content');
00128 
00129                 // Load the master template
00130                 $templateInstance->loadCodeTemplate($masterTemplate);
00131 
00132                 // Set title
00133                 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title'));
00134 
00135                 // ... and all variables. This should be merged together in a pattern
00136                 // to make things easier. A cache mechanism should be added between
00137                 // these two calls to cache compiled templates.
00138                 $templateInstance->compileVariables();
00139 
00140                 // Get the content back from the template engine and put it in response class
00141                 $templateInstance->transferToResponse($responseInstance);
00142         }
00143 
00151         public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
00152                 // Default is no action
00153                 $actionInstance = null;
00154 
00155                 // Get registry
00156                 $registryInstance = Registry::getRegistry();
00157 
00158                 // Get our application instance from the registry
00159                 $appInstance = $registryInstance->getInstance('application');
00160 
00161                 // Default action is the one from configuration
00162                 $this->actionName = sprintf("%s_login_%s",
00163                         str_replace("-", "_", $appInstance->getAppShortName()),
00164                         $this->getConfigInstance()->readConfig('login_default_action')
00165                 );
00166 
00167                 // Get "action" from request
00168                 $actReq = $requestInstance->getRequestElement('action');
00169 
00170                 // Do we have a "action" parameter set?
00171                 if ((is_string($actReq)) && (!empty($actReq))) {
00172                         // Then use it with prefix
00173                         $this->actionName = sprintf("%s_login_%s",
00174                                 str_replace("-", "_", $appInstance->getAppShortName()),
00175                                 $actReq
00176                         );
00177                 } // END - if
00178 
00179                 // Get application instance
00180                 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
00181 
00182                 // Get a resolver
00183                 $actionResolver = WebActionResolver::createWebActionResolver($this->actionName, $applicationInstance);
00184 
00185                 // Resolve the action
00186                 $actionInstance = $actionResolver->resolveAction();
00187 
00188                 // Add more action-specific filters
00189                 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
00190 
00191                 // Remember this action in registry
00192                 Registry::getRegistry()->addInstance('action', $actionInstance);
00193         }
00194 }
00195 
00196 // [EOF]
00197 ?>

Generated on Mon Dec 8 01:06:45 2008 for Ship-Simulator by  doxygen 1.5.6