class_ImageControllerResolver.php

Go to the documentation of this file.
00001 <?php
00024 class ImageControllerResolver extends BaseControllerResolver implements ControllerResolver {
00028         private $lastControllerName = "";
00029 
00033         private $lastControllerInstance = null;
00034 
00040         protected function __construct () {
00041                 // Call parent constructor
00042                 parent::__construct(__CLASS__);
00043 
00044                 // Set prefix to "Image"
00045                 $this->setControllerPrefix("Image");
00046         }
00047 
00057         public final static function createImageControllerResolver ($controllerName, ManageableApplication $appInstance) {
00058                 // Create the new instance
00059                 $resolverInstance = new ImageControllerResolver();
00060 
00061                 // Is the variable $controllerName set and the command is valid?
00062                 if (empty($controllerName)) {
00063                         // Then thrown an exception here
00064                         throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00065                 } elseif ($resolverInstance->isControllerValid($controllerName) === false) {
00066                         // Invalid command found
00067                         throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
00068                 }
00069 
00070                 // Set the application instance
00071                 $resolverInstance->setApplicationInstance($appInstance);
00072 
00073                 // Set command name
00074                 $resolverInstance->setControllerName($controllerName);
00075 
00076                 // Return the prepared instance
00077                 return $resolverInstance;
00078         }
00079 
00088         public function resolveController () {
00089                 // Init variables
00090                 $controllerName = "";
00091                 $controllerInstance = null;
00092 
00093                 // Get the command name 
00094                 $controllerName = $this->getControllerName();
00095 
00096                 // Get the command
00097                 $controllerInstance = $this->loadController($controllerName);
00098 
00099                 // And validate it
00100                 if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
00101                         // This command has an invalid instance!
00102                         throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
00103                 } // END - if
00104 
00105                 // Set last controller
00106                 $this->lastControllerInstance = $controllerInstance;
00107 
00108                 // Return the maybe resolved instance
00109                 return $controllerInstance;
00110         }
00111 
00122         private function loadController ($controllerName) {
00123                 // Cache default command
00124                 $defaultController = $this->getConfigInstance()->readConfig('default_image_command');
00125 
00126                 // Init controller instance
00127                 $controllerInstance = null;
00128 
00129                 // Default controller
00130                 $this->setClassName($defaultController);
00131 
00132                 // Generate the class name
00133                 //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
00134                 if ($controllerName != $defaultController) {
00135                         // Create controller class name
00136                         $this->setClassName(sprintf("Image%sController",
00137                                 $this->convertToClassName($controllerName)
00138                         ));
00139                 } // END - if
00140                 //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
00141 
00142                 // Is this class loaded?
00143                 if (!class_exists($this->getClassName())) {
00144                         // Class not found, so or throw an exception
00145                         throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
00146                 } // END - if
00147 
00148                 // Initiate the resolver and controller
00149                 $resolverInstance = ObjectFactory::createObjectByConfiguredName('image_cmd_resolver_class', array($controllerName, $this->getApplicationInstance()));
00150                 $controllerInstance = ObjectFactory::createObjectByName($this->getClassName(), array($resolverInstance));
00151 
00152                 // Remove resolver
00153                 unset($resolverInstance);
00154 
00155                 // Return the result
00156                 return $controllerInstance;
00157         }
00158 }
00159 
00160 // [EOF]
00161 ?>

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