]> git.mxchange.org Git - core.git/commitdiff
loadController() is now more generic (TODO: check that all other apps works)
authorRoland Häder <roland@mxchange.org>
Sat, 18 Jul 2009 07:49:53 +0000 (07:49 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 18 Jul 2009 07:49:53 +0000 (07:49 +0000)
.gitattributes
inc/classes/main/factories/web/class_WebNewsFactory.php
inc/classes/main/reader/class_ConsoleNewsReader.php [new file with mode: 0644]
inc/classes/main/reader/class_DefaultNewsReader.php
inc/classes/main/resolver/command/console/class_ConsoleCommandResolver.php
inc/classes/main/resolver/controller/class_BaseControllerResolver.php
inc/classes/main/resolver/controller/console/class_ConsoleControllerResolver.php
inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php
inc/classes/main/resolver/controller/web/class_WebControllerResolver.php

index bef744e403fc6ddd659d19645233801d5baa2f8e..dfdc488d0912b115f36ead08135972354f188689 100644 (file)
@@ -401,6 +401,7 @@ inc/classes/main/output/class_WebOutput.php -text
 inc/classes/main/points/.htaccess -text
 inc/classes/main/points/class_UserPoints.php -text
 inc/classes/main/reader/.htaccess -text
+inc/classes/main/reader/class_ConsoleNewsReader.php -text
 inc/classes/main/reader/class_DefaultNewsReader.php -text
 inc/classes/main/registration/.htaccess -text
 inc/classes/main/registration/class_BaseRegistration.php -text
index 10386e232f47f14ab480f48e66949ee7e972e90b..304d5a15406f40501889235d275149d5ec0bf699 100644 (file)
@@ -46,7 +46,7 @@ class WebNewsFactory extends BaseFactory {
         */
        public final static function createFactoryByRequest (Requestable $requestInstance) {
                // Set default news reader class
-               $configEntry = "news_reader_class";
+               $configEntry = 'news_reader_class';
 
                // Get "page"
                $page = $requestInstance->getRequestElement('page');
diff --git a/inc/classes/main/reader/class_ConsoleNewsReader.php b/inc/classes/main/reader/class_ConsoleNewsReader.php
new file mode 100644 (file)
index 0000000..0240b74
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+/**
+ * A default news reader class reads news from database layer
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class DefaultNewsReader extends BaseFrameworkSystem implements ReadableNews, Registerable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Clean up a little
+               $this->removeNumberFormaters();
+               $this->removeSystemArray();
+       }
+
+       /**
+        * Creates an instance of this reader by a provided request instance
+        *
+        * @param       $requestInstance        An instance of a Requestable class
+        * @return      $readerInstance         An instance of this reader class
+        */
+       public final static function createDefaultNewsReader (Requestable $requestInstance) {
+               // Get a new instance
+               $readerInstance = new DefaultNewsReader();
+
+               // Set request instance
+               $readerInstance->setRequestInstance($requestInstance);
+
+               // Return prepared instance
+               return $readerInstance;
+       }
+
+       /**
+        * Initializes this reader class by pre-fetching news depending on 'page'
+        * (outside or login area), which amount of news and how much to skip
+        *
+        * @return      void
+        */
+       public function initializeReader () {
+               // Get 'page' for saving some calls
+               $page = $this->getRequestInstance()->getRequestElement('page');
+
+               // First get a wrapper instance
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('news_db_wrapper_class');
+
+               // Next create a searchable criteria instance
+               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Add the page as criteria to it at lease
+               $criteriaInstance->addCriteria('page', $page);
+
+               // Add limitation from config
+               $criteriaInstance->setLimit($this->getConfigInstance()->readConfig('news_' . $page . '_limit'));
+
+               // Get a resultInstance back from the database
+               $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+
+               // Save that resultInstance in this class
+               $this->setResultInstance($resultInstance);
+       }
+}
+
+// [EOF]
+?>
index a0c4fb615205a4f72a8824f2e283a14e8a31bce0..0240b74da57e77a262cce8181f67735205b307c1 100644 (file)
@@ -54,13 +54,13 @@ class DefaultNewsReader extends BaseFrameworkSystem implements ReadableNews, Reg
        }
 
        /**
-        * Initializes this reader class by pre-fetching news depending on "page"
+        * Initializes this reader class by pre-fetching news depending on 'page'
         * (outside or login area), which amount of news and how much to skip
         *
         * @return      void
         */
        public function initializeReader () {
-               // Get "page" for saving some calls
+               // Get 'page' for saving some calls
                $page = $this->getRequestInstance()->getRequestElement('page');
 
                // First get a wrapper instance
@@ -70,10 +70,10 @@ class DefaultNewsReader extends BaseFrameworkSystem implements ReadableNews, Reg
                $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                // Add the page as criteria to it at lease
-               $criteriaInstance->addCriteria("page", $page);
+               $criteriaInstance->addCriteria('page', $page);
 
                // Add limitation from config
-               $criteriaInstance->setLimit($this->getConfigInstance()->readConfig("news_{$page}_limit"));
+               $criteriaInstance->setLimit($this->getConfigInstance()->readConfig('news_' . $page . '_limit'));
 
                // Get a resultInstance back from the database
                $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
index 9a212ab7e8da474ed8acee9863adc682bd77d0fb..5dffd57696fbc9374ef9b212f93c0ebc1b5771f5 100644 (file)
@@ -86,7 +86,7 @@ class ConsoleCommandResolver extends BaseCommandResolver implements CommandResol
                $commandInstance = null;
 
                // This goes fine so let's resolve the command
-               $commandName = $requestInstance->getRequestElement('page');
+               $commandName = $requestInstance->getRequestElement('command');
 
                // Is the command empty? Then fall back to default command
                if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_console_command');
index 23e449ac913386c2b6092539f41cdfc2d39004b5..ece1f26d8b64679c905dcf762235a46374ec4336 100644 (file)
@@ -72,6 +72,79 @@ class BaseControllerResolver extends BaseResolver {
                return $this->controllerName;
        }
 
+       /**
+        * "Loads" a given controller and instances it if not yet cached. If the
+        * controller was not found one of the default controllers will be used
+        * depending on wether news shall be displayed.
+        *
+        * @param       $controllerName                 A controller name we shall look for
+        * @return      $controllerInstance             A loaded controller instance
+        * @throws      InvalidControllerException      Thrown if even the requested
+        *                                                                              controller class is missing (bad!)
+        */
+       protected function loadController ($controllerName) {
+               // Cache default command
+               $defaultController = $this->getConfigInstance()->readConfig('default_' . strtolower($this->getControllerPrefix()) . '_command');
+
+               // Init controller instance
+               $controllerInstance = null;
+
+               // Default controller
+               $this->setClassName($this->getControllerPrefix() . 'DefaultNewsController');
+
+               // Generate the class name
+               //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
+               if ($controllerName != $defaultController) {
+                       // Create controller class name
+                       $className = $this->getControllerPrefix() . '' . $this->convertToClassName($controllerName) . 'Controller';
+
+                       // ... and set it
+                       $this->setClassName($className);
+               } else {
+                       // No news at main command or non-news command
+                       $this->setClassName($this->getControllerPrefix() . 'DefaultNewsController');
+               }
+               //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
+
+               // Is this class loaded?
+               if (!class_exists($this->getClassName())) {
+                       // Throw an exception here
+                       throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+               } // END - if
+
+               // Set default resolver config name
+               $resolverConfigEntry = '';
+
+               // Try to read a config entry for our resolver including controller name... ;-)
+               try {
+                       // Create the resolver name
+                       $resolverConfigEntry = sprintf("%s_cmd_%s_resolver_class", strtolower($this->getControllerPrefix(), strtolower($controllerName));
+
+                       // Get the config, this will throw an exception if there is no special command resolver
+                       $resolverClass = $this->getConfigInstance()->readConfig($resolverConfigEntry);
+               } catch (ConfigEntryNotFoundException $e) {
+                       // Use default resolver entry
+                       // @TODO Maybe we need to log this?
+                       $resolverConfigEntry = $this->getControllerPrefix() . '_cmd_resolver_class';
+               }
+
+               // Initiate the resolver and controller
+               $resolverInstance = ObjectFactory::createObjectByConfiguredName(
+                       $resolverConfigEntry,
+                       array(
+                               $controllerName,
+                               $this->getApplicationInstance()
+                       )
+               );
+               $controllerInstance = ObjectFactory::createObjectByName(
+                       $this->getClassName(),
+                       array($resolverInstance)
+               );
+
+               // Return the result
+               return $controllerInstance;
+       }
+
        /**
         * Checks wether the given controller is valid
         *
index f5cbe43f18c7849a01a806011b74749ff136a835..35430d4342cd94d17c060e526b6874af14d262e6 100644 (file)
@@ -108,79 +108,6 @@ class ConsoleControllerResolver extends BaseControllerResolver implements Contro
                // Return the maybe resolved instance
                return $controllerInstance;
        }
-
-       /**
-        * "Loads" a given controller and instances it if not yet cached. If the
-        * controller was not found one of the default controllers will be used
-        * depending on wether news shall be displayed.
-        *
-        * @param       $controllerName                 A controller name we shall look for
-        * @return      $controllerInstance             A loaded controller instance
-        * @throws      InvalidControllerException      Thrown if even the requested
-        *                                                                              controller class is missing (bad!)
-        */
-       private function loadController ($controllerName) {
-               // Cache default command
-               $defaultController = $this->getConfigInstance()->readConfig('default_console_command');
-
-               // Init controller instance
-               $controllerInstance = null;
-
-               // Default controller
-               $this->setClassName('ConsoleDefaultNewsController');
-
-               // Generate the class name
-               //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
-               if ($controllerName != $defaultController) {
-                       // Create controller class name
-                       $className = 'Console' . $this->convertToClassName($controllerName) . 'Controller';
-
-                       // ... and set it
-                       $this->setClassName($className);
-               } else {
-                       // No news at main command or non-news command
-                       $this->setClassName('ConsoleDefaultNewsController');
-               }
-               //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
-
-               // Is this class loaded?
-               if (!class_exists($this->getClassName())) {
-                       // Throw an exception here
-                       throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
-               } // END - if
-
-               // Set default resolver config name
-               $resolverConfigEntry = '';
-
-               // Try to read a config entry for our resolver including controller name... ;-)
-               try {
-                       // Create the resolver name
-                       $resolverConfigEntry = sprintf("console_cmd_%s_resolver_class", strtolower($controllerName));
-
-                       // Get the config, this will throw an exception if there is no special command resolver
-                       $resolverClass = $this->getConfigInstance()->readConfig($resolverConfigEntry);
-               } catch (ConfigEntryNotFoundException $e) {
-                       // Use default resolver entry
-                       // @TODO Maybe we need to log this?
-                       $resolverConfigEntry = 'console_cmd_resolver_class';
-               }
-
-               // Initiate the resolver and controller
-               $resolverInstance = ObjectFactory::createObjectByConfiguredName(
-                       $resolverConfigEntry,
-                       array(
-                               $controllerName,
-                               $this->getApplicationInstance()
-                       )
-               );
-               $controllerInstance = ObjectFactory::createObjectByName(
-                       $this->getClassName(),
-                       array($resolverInstance)
-               );
-
-               // Return the result
-               return $controllerInstance;
-       }
 }
 
 // [EOF]
index a8b136aa73c1fd202472fc3723cd2461b755ab59..fea3a8263cf26f903bf51584285a61cbe811e962 100644 (file)
@@ -108,60 +108,6 @@ class ImageControllerResolver extends BaseControllerResolver implements Controll
                // Return the maybe resolved instance
                return $controllerInstance;
        }
-
-       /**
-        * "Loads" a given controller and instances it if not yet cached. If the
-        * controller was not found one of the default controllers will be used
-        * depending on wether news shall be displayed.
-        *
-        * @param       $controllerName                 A controller name we shall look for
-        * @return      $controllerInstance             A loaded controller instance
-        * @throws      InvalidControllerException      Thrown if even the requested
-        *                                                                              controller class is missing (bad!)
-        */
-       private function loadController ($controllerName) {
-               // Cache default command
-               $defaultController = $this->getConfigInstance()->readConfig('default_image_command');
-
-               // Init controller instance
-               $controllerInstance = null;
-
-               // Default controller
-               $this->setClassName($defaultController);
-
-               // Generate the class name
-               //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
-               if ($controllerName != $defaultController) {
-                       // Create controller class name
-                       $className = 'Image' . $this->convertToClassName($controllerName) . 'Controller';
-
-                       // ... and set it
-                       $this->setClassName($className);
-               } // END - if
-               //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
-
-               // Is this class loaded?
-               if (!class_exists($this->getClassName())) {
-                       // Class not found, so or throw an exception
-                       throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
-               } // END - if
-
-               // Initiate the resolver and controller
-               $resolverInstance = ObjectFactory::createObjectByConfiguredName(
-                       'image_cmd_resolver_class',
-                       array(
-                               $controllerName,
-                               $this->getApplicationInstance()
-                       )
-               );
-               $controllerInstance = ObjectFactory::createObjectByName(
-                       $this->getClassName(),
-                       array($resolverInstance)
-               );
-
-               // Return the result
-               return $controllerInstance;
-       }
 }
 
 // [EOF]
index a941f53c2309c7cb6991779847491f0c7fc3408e..b43274d3e3a16e876e2fc815acbfeafd0106d3a0 100644 (file)
@@ -108,79 +108,6 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
                // Return the maybe resolved instance
                return $controllerInstance;
        }
-
-       /**
-        * "Loads" a given controller and instances it if not yet cached. If the
-        * controller was not found one of the default controllers will be used
-        * depending on wether news shall be displayed.
-        *
-        * @param       $controllerName                 A controller name we shall look for
-        * @return      $controllerInstance             A loaded controller instance
-        * @throws      InvalidControllerException      Thrown if even the requested
-        *                                                                              controller class is missing (bad!)
-        */
-       private function loadController ($controllerName) {
-               // Cache default command
-               $defaultController = $this->getConfigInstance()->readConfig('default_web_command');
-
-               // Init controller instance
-               $controllerInstance = null;
-
-               // Default controller
-               $this->setClassName('WebDefaultNewsController');
-
-               // Generate the class name
-               //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
-               if ($controllerName != $defaultController) {
-                       // Create controller class name
-                       $className = 'Web' . $this->convertToClassName($controllerName) . 'Controller';
-
-                       // ... and set it
-                       $this->setClassName($className);
-               } else {
-                       // No news at home page or non-news page
-                       $this->setClassName('WebDefaultNewsController');
-               }
-               //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
-
-               // Is this class loaded?
-               if (!class_exists($this->getClassName())) {
-                       // Throw an exception here
-                       throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
-               } // END - if
-
-               // Set default resolver config name
-               $resolverConfigEntry = '';
-
-               // Try to read a config entry for our resolver including controller name... ;-)
-               try {
-                       // Create the resolver name
-                       $resolverConfigEntry = sprintf("web_cmd_%s_resolver_class", strtolower($controllerName));
-
-                       // Get the config, this will throw an exception if there is no special command resolver
-                       $resolverClass = $this->getConfigInstance()->readConfig($resolverConfigEntry);
-               } catch (ConfigEntryNotFoundException $e) {
-                       // Use default resolver entry
-                       // @TODO Maybe we need to log this?
-                       $resolverConfigEntry = 'web_cmd_resolver_class';
-               }
-
-               // Initiate the resolver and controller
-               $resolverInstance = ObjectFactory::createObjectByConfiguredName(
-                       $resolverConfigEntry,
-                       array(
-                               $controllerName,
-                               $this->getApplicationInstance()
-                       )
-               );
-               $controllerInstance = ObjectFactory::createObjectByName(
-                       $this->getClassName(),
-                       array($resolverInstance)
-               );
-
-               // Return the result
-               return $controllerInstance;
-       }
 }
 
 // [EOF]