use Org\Mxchange\CoreFramework\Controller\Controller;
use Org\Mxchange\CoreFramework\Controller\DefaultControllerException;
use Org\Mxchange\CoreFramework\Controller\InvalidControllerException;
-use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
-use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
use Org\Mxchange\CoreFramework\Resolver\BaseResolver;
use Org\Mxchange\CoreFramework\Resolver\Controller\ControllerResolver;
+use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
// Import SPL stuff
use \InvalidArgumentException;
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
* @param $className Name of the real class
* @return void
*/
- protected function __construct ($className) {
+ protected function __construct (string $className) {
// Call parent constructor
parent::__construct($className);
}
* @throws InvalidControllerException Thrown if even the requested
* controller class is missing (bad!)
*/
- protected function loadController ($controllerName) {
+ protected function loadController (string $controllerName) {
// Cache default controller
$defaultController = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('default_' . strtolower($this->getClassPrefix()) . '_controller');
- // Init controller instance
- $controllerInstance = NULL;
-
// Create full class name
$className = sprintf(
'%s\%sDefaultNewsController',
'%s\%s%sController',
$this->getNamespace(),
$this->getCapitalizedClassPrefix(),
- self::convertToClassName($controllerName)
+ StringUtils::convertToClassName($controllerName)
);
// ... and set it
// No news at main controller or non-news controller
$this->setClassName($className);
}
- //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('AFTER: controller=' . $this->getClassName());
// Is this class loaded?
+ //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('AFTER: controller=' . $this->getClassName());
if (!class_exists($this->getClassName())) {
// Throw an exception here
throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- } // END - if
+ }
// Try to read a config entry for our resolver including controller name... ;-)
$resolverConfigEntry = sprintf('%s_cmd_%s_resolver_class', strtolower($this->getClassPrefix()), strtolower($controllerName));
$resolverConfigEntry,
array(
$controllerName,
- GenericRegistry::getRegistry()->getInstance('application')
+ ApplicationHelper::getSelfInstance()
)
);
+
+ // Get controller instance
$controllerInstance = ObjectFactory::createObjectByName(
$this->getClassName(),
array($resolverInstance)
* @throws InvalidArgumentException Thrown if given controller is not set
* @throws DefaultControllerException Thrown if default controller was not found
*/
- protected function isControllerValid ($namespace, $controllerName) {
+ protected function isControllerValid (string $namespace, string $controllerName) {
// Is a action set?
if (empty($namespace)) {
// Then thrown an exception here
- throw new InvalidArgumentException('Parameter "namespace" is empty');
+ throw new InvalidArgumentException('Parameter "namespace" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
} elseif (empty($controllerName)) {
// Then thrown an exception here
- throw new InvalidArgumentException('Parameter "controllerName" is empty');
+ throw new InvalidArgumentException('Parameter "controllerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
}
// By default nothing shall be valid
// Create class name
$className = sprintf(
- '%s\%sController',
+ '%s\%s%sController',
$namespace,
- $this->getCapitalizedClassPrefix() . self::convertToClassName($controllerName)
+ $this->getCapitalizedClassPrefix(),
+ StringUtils::convertToClassName($controllerName)
);
- $newsControllerName = sprintf(
+
+ // Application's default news controller
+ $appDefaultControllerName = sprintf(
'%s\%sDefaultNewsController',
$namespace,
$this->getCapitalizedClassPrefix()
);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('className=%s', $className));
+ // Framework's default news controller
+ $defaultControllerName = sprintf(
+ 'Org\Mxchange\CoreFramework\Controller\News\%sDefaultNewsController',
+ $this->getCapitalizedClassPrefix()
+ );
// Now, let us create the full name of the controller class
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('className=%s', $className));
$this->setClassName($className);
// Try it hard to get an controller
if (class_exists($this->getClassName())) {
// This class does exist. :-)
$isValid = true;
- } elseif ($this->getClassName() != $newsControllerName) {
- // Set default controller
- $this->setClassName($newsControllerName);
+ } elseif ($this->getClassName() != $appDefaultControllerName) {
+ // Set application's default controller
+ $this->setClassName($appDefaultControllerName);
+ } elseif ($this->getClassName() != $defaultControllerName) {
+ // Set framework's default controller
+ $this->setClassName($defaultControllerName);
} else {
// All is tried, give it up here
throw new DefaultControllerException($this, self::EXCEPTION_DEFAULT_CONTROLLER_GONE);
}
- } // END - while
+ }
// Return the result
return $isValid;
*/
public function resolveController () {
// Init variables
- $controllerName = '';
- $controllerInstance = NULL;
-
- // Get namespace and controller name
$controllerName = $this->getControllerName();
// Get the controller
if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
// This controller has an invalid instance!
throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- } // END - if
+ }
// Set last controller
$this->setResolvedInstance($controllerInstance);