class_WebActionResolver.php

Go to the documentation of this file.
00001 <?php
00024 class WebActionResolver extends BaseActionResolver implements ActionResolver {
00028         private $lastActionInstance = "";
00029 
00035         protected function __construct () {
00036                 // Call parent constructor
00037                 parent::__construct(__CLASS__);
00038 
00039                 // Set prefix to "Web"
00040                 $this->setActionPrefix("Web");
00041         }
00042 
00052         public final static function createWebActionResolver ($actionName, ManageableApplication $appInstance) {
00053                 // Create the new instance
00054                 $resolverInstance = new WebActionResolver();
00055 
00056                 // Is the variable $actionName set and the action is valid?
00057                 if (empty($actionName)) {
00058                         // Then thrown an exception here
00059                         throw new EmptyVariableException(array($resolverInstance, 'defaultAction'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00060                 } elseif ($resolverInstance->isActionValid($actionName) === false) {
00061                         // Invalid action found
00062                         throw new InvalidActionException(array($resolverInstance, $actionName), self::EXCEPTION_INVALID_ACTION);
00063                 }
00064 
00065                 // Set the application instance
00066                 $resolverInstance->setApplicationInstance($appInstance);
00067 
00068                 // Return the prepared instance
00069                 return $resolverInstance;
00070         }
00071 
00083         public function resolveActionByRequest (Requestable $requestInstance) {
00084                 // Init variables
00085                 $actionName = "";
00086                 $actionInstance = null;
00087 
00088                 // This goes fine so let's resolv the action
00089                 $actionName = $requestInstance->getRequestElement('action');
00090 
00091                 // Is the action empty? Then fall back to default action
00092                 if (empty($actionName)) $actionName = $this->getConfigInstance()->readConfig('default_action');
00093 
00094                 // Check if action is valid
00095                 if ($this->isActionValid($actionName) === false) {
00096                         // This action is invalid!
00097                         throw new InvalidActionException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION);
00098                 } // END - if
00099 
00100                 // Get the action
00101                 $actionInstance = $this->loadAction();
00102 
00103                 // And validate it
00104                 if ((!is_object($actionInstance)) || (!$actionInstance instanceof Actionable)) {
00105                         // This action has an invalid instance!
00106                         throw new InvalidActionInstanceException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION);
00107                 } // END - if
00108 
00109                 // Set last action
00110                 $this->lastActionInstance = $actionInstance;
00111 
00112                 // Return the resolved action instance
00113                 return $actionInstance;
00114         }
00115 
00122         public function resolveAction () {
00123                 // Initiate the instance variable
00124                 $actionInstance = null;
00125 
00126                 // Get action name
00127                 $actionName = $this->getActionName();
00128 
00129                 // Is the action empty? Then fall back to default action
00130                 if (empty($actionName)) $actionName = $this->getConfigInstance()->readConfig('default_action');
00131 
00132                 // Check if action is valid
00133                 if ($this->isActionValid($actionName) === false) {
00134                         // This action is invalid!
00135                         throw new InvalidActionException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION);
00136                 }
00137 
00138                 // Get the action
00139                 $actionInstance = $this->loadAction();
00140 
00141                 // Return the instance
00142                 return $actionInstance;
00143         }
00144 }
00145 
00146 // [EOF]
00147 ?>

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