From: Roland Haeder Date: Fri, 24 Feb 2017 21:57:24 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=7504d226278b9473da4c70d7fb80d008129f43e1 Continued: - add "import" for InvalidCommandException - isValid() methods now have 2 parameters: $namespace and $fooName - InvalidCommandException is no longer deprecated - removed [EOF] and ?> Signed-off-by: Roland Häder --- diff --git a/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php b/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php index 266ee542..355fc53f 100644 --- a/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php +++ b/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php @@ -140,7 +140,5 @@ class TestsConsoleDefaultNewsController extends BaseController implements Contro public function executeActivationFilters (Requestable $requestInstance, Responseable $responseInstance) { $this->executeFilters('activation', $requestInstance, $responseInstance); } -} -// [EOF] -?> +} diff --git a/application/tests/classes/resolver/command/.htaccess b/application/tests/classes/resolver/command/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/application/tests/classes/resolver/command/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/tests/classes/resolver/command/console/.htaccess b/application/tests/classes/resolver/command/console/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/application/tests/classes/resolver/command/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/tests/classes/resolver/command/console/class_TestsConsoleCommandResolver.php b/application/tests/classes/resolver/command/console/class_TestsConsoleCommandResolver.php new file mode 100644 index 00000000..c6c5c3cf --- /dev/null +++ b/application/tests/classes/resolver/command/console/class_TestsConsoleCommandResolver.php @@ -0,0 +1,76 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 . + */ +class TestsConsoleCommandResolver extends BaseCommandResolver implements CommandResolver { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to "TestsConsole" + $this->setClassPrefix('tests_console'); + } + + /** + * Creates an instance of a TestsConsole command resolver with a given default command + * + * @param $commandName The default command we shall execute + * @param $applicationInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared command resolver instance + * @throws EmptyVariableException Thrown if default command is not set + * @throws InvalidCommandException Thrown if default command is invalid + */ + public static final function createTestsConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) { + // Create the new instance + $resolverInstance = new TestsConsoleCommandResolver(); + + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif ($resolverInstance->isCommandValid('CoreFramework\Tests\Command', $commandName) === FALSE) { + // Invalid command found + throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($applicationInstance); + + // Return the prepared instance + return $resolverInstance; + } + +} diff --git a/application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php b/application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php index f707e1f0..ad250cab 100644 --- a/application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php +++ b/application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php @@ -108,7 +108,5 @@ class TestsConsoleControllerResolver extends BaseControllerResolver implements C // Return the maybe resolved instance return $controllerInstance; } -} -// [EOF] -?> +} diff --git a/application/tests/config.php b/application/tests/config.php index c9653716..f9ca6ea7 100644 --- a/application/tests/config.php +++ b/application/tests/config.php @@ -35,3 +35,6 @@ $cfg->setConfigEntry('default_tests_console_command', 'main'); // CFG: DEFAULT-TESTS-CONSOLE-CONTROLLER $cfg->setConfigEntry('default_tests_console_controller', 'main'); + +// CFG: TESTS-CONSOLE-CMD-MAIN-RESOLVER-CLASS +$cfg->setConfigEntry('tests_console_cmd_main_resolver_class', 'CoreFramework\Tests\Resolver\Command\TestsConsoleCommandResolver'); diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index eee9fce1..0d0356e8 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -191,7 +191,7 @@ class ClassLoader { */ public static function scanFrameworkClasses () { // Trace message - /* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); // Cache loader instance $loaderInstance = self::getSelfInstance(); @@ -199,7 +199,7 @@ class ClassLoader { // Load all classes foreach (self::$frameworkPaths as $pathName) { // Debug message - /* NOISY-DEBUG: */ printf('[%s:%d]: pathName=%s' . PHP_EOL, __METHOD__, __LINE__, $pathName); + //* NOISY-DEBUG: */ printf('[%s:%d]: pathName=%s' . PHP_EOL, __METHOD__, __LINE__, $pathName); // Try to load the framework classes $loaderInstance->scanClassPath('inc/main/' . $pathName . '/'); @@ -213,7 +213,7 @@ class ClassLoader { */ public static function scanApplicationClasses () { // Trace message - /* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); // Get config instance $cfg = FrameworkConfiguration::getSelfInstance(); @@ -224,7 +224,7 @@ class ClassLoader { $pathName = sprintf('%s/%s/%s', $cfg->getConfigEntry('application_path'), $cfg->getConfigEntry('app_name'), $class); // Debug message - /* NOISY-DEBUG: */ printf('[%s:%d]: pathName=%s' . PHP_EOL, __METHOD__, __LINE__, $pathName); + //* NOISY-DEBUG: */ printf('[%s:%d]: pathName=%s' . PHP_EOL, __METHOD__, __LINE__, $pathName); // Is the path readable? if (is_dir($pathName)) { @@ -351,7 +351,7 @@ class ClassLoader { } // Get a new iterator - /* NOISY-DEBUG: */ printf('[%s:%d] basePath=%s' . PHP_EOL, __METHOD__, __LINE__, $basePath); + //* NOISY-DEBUG: */ printf('[%s:%d] basePath=%s' . PHP_EOL, __METHOD__, __LINE__, $basePath); $iteratorInstance = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basePath), RecursiveIteratorIterator::CHILD_FIRST); // Load all entries @@ -371,23 +371,23 @@ class ClassLoader { $iteratorInstance->next(); // Skip non-file entries - /* NOISY-DEBUG: */ printf('[%s:%d] SKIP: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] SKIP: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); continue; } // END - if // Is this file wanted? - /* NOISY-DEBUG: */ printf('[%s:%d] FOUND: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] FOUND: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); if ((substr($fileName, 0, strlen($this->prefix)) == $this->prefix) && (substr($fileName, -strlen($this->suffix), strlen($this->suffix)) == $this->suffix)) { // Add it to the list - /* NOISY-DEBUG: */ printf('[%s:%d] ADD: %s,fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $fqfn); + //* NOISY-DEBUG: */ printf('[%s:%d] ADD: %s,fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $fqfn); $this->foundClasses[$fileName] = $fqfn; } else { // Not added - /* NOISY-DEBUG: */ printf('[%s:%d] NOT ADDED: %s,fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $fqfn); + //* NOISY-DEBUG: */ printf('[%s:%d] NOT ADDED: %s,fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $fqfn); } // Advance to next entry - /* NOISY-DEBUG: */ printf('[%s:%d] NEXT: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] NEXT: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); $iteratorInstance->next(); } // END - while } @@ -427,7 +427,7 @@ class ClassLoader { */ private function loadClassFile ($className) { // Trace message - /* NOISY-DEBUG: */ printf('[%s:%d] className=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className); + //* NOISY-DEBUG: */ printf('[%s:%d] className=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className); // The class name should contain at least 2 back-slashes, so split at them $classNameParts = explode("\\", $className); @@ -445,12 +445,12 @@ class ClassLoader { $fileName = $this->prefix . $shortClassName . $this->suffix; // Now look it up in our index - /* NOISY-DEBUG: */ printf('[%s:%d] ISSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] ISSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); if ((isset($this->foundClasses[$fileName])) && (!isset($this->loadedClasses[$this->foundClasses[$fileName]]))) { // File is found and not loaded so load it only once - /* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - START' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - START' . PHP_EOL, __METHOD__, __LINE__, $fileName); require($this->foundClasses[$fileName]); - /* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - END' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - END' . PHP_EOL, __METHOD__, __LINE__, $fileName); // Count this loaded class/interface/exception $this->total++; @@ -459,18 +459,18 @@ class ClassLoader { $this->loadedClasses[$this->foundClasses[$fileName]] = TRUE; // Remove it from classes list so it won't be found twice. - /* NOISY-DEBUG: */ printf('[%s:%d] UNSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] UNSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); unset($this->foundClasses[$fileName]); // Developer mode excludes caching (better debugging) if (!defined('DEVELOPER')) { // Reset cache - /* NOISY-DEBUG: */ printf('[%s:%d] classesCached=FALSE' . PHP_EOL, __METHOD__, __LINE__); + //* NOISY-DEBUG: */ printf('[%s:%d] classesCached=FALSE' . PHP_EOL, __METHOD__, __LINE__); $this->classesCached = FALSE; } // END - if } else { // Not found - /* NOISY-DEBUG: */ printf('[%s:%d] 404: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] 404: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); } } @@ -485,12 +485,12 @@ class ClassLoader { // Is this a config? if (substr($fileName, 0, strlen($this->prefix)) == $this->prefix) { // Then include it - /* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - START' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - START' . PHP_EOL, __METHOD__, __LINE__, $fileName); require($fqfn); - /* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - END' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - END' . PHP_EOL, __METHOD__, __LINE__, $fileName); // Remove it from the list - /* NOISY-DEBUG: */ printf('[%s:%d] UNSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); + //* NOISY-DEBUG: */ printf('[%s:%d] UNSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); unset($this->foundClasses[$fileName]); } // END - if } // END - foreach diff --git a/inc/main/classes/resolver/action/class_BaseActionResolver.php b/inc/main/classes/resolver/action/class_BaseActionResolver.php index 0c4841b6..45ec44c8 100644 --- a/inc/main/classes/resolver/action/class_BaseActionResolver.php +++ b/inc/main/classes/resolver/action/class_BaseActionResolver.php @@ -67,22 +67,31 @@ class BaseActionResolver extends BaseResolver { /** * Checks whether the given action is valid * - * @param $actionName The default action we shall execute + * @param $namespace Namespace to look in + * @param $actionName The default action we shall execute * @return $isValid Whether the given action is valid * @throws EmptyVariableException Thrown if given action is not set */ - public function isActionValid ($actionName) { + public function isActionValid ($namespace, $actionName) { // By default nothing shall be valid $isValid = FALSE; // Is a action set? - if (empty($actionName)) { + if (empty($namespace)) { + // Then thrown an exception here + throw new EmptyVariableException(array($this, 'namespace'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (empty($actionName)) { // Then thrown an exception here throw new EmptyVariableException(array($this, 'actionName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } // END - if // Create class name - $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($actionName) . 'Action'; + $className = sprintf( + '%s\%s%sAction', + $namespace, + $this->getCapitalizedClassPrefix(), + self::convertToClassName($actionName) + ); // Now, let us create the full name of the action class $this->setClassName($className); @@ -109,8 +118,13 @@ class BaseActionResolver extends BaseResolver { // Init action instance $actionInstance = NULL; - // Create action class name - $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($this->getActionName()) . 'Action'; + // Create class name + $className = sprintf( + '%s\%s%sAction', + $this->getNamespace(), + $this->getCapitalizedClassPrefix(), + self::convertToClassName($actionName) + ); // ... and set it $this->setClassName($className); diff --git a/inc/main/classes/resolver/command/class_BaseCommandResolver.php b/inc/main/classes/resolver/command/class_BaseCommandResolver.php index 730e2822..5f948a56 100644 --- a/inc/main/classes/resolver/command/class_BaseCommandResolver.php +++ b/inc/main/classes/resolver/command/class_BaseCommandResolver.php @@ -1,8 +1,9 @@ getCapitalizedClassPrefix() . self::convertToClassName($commandName) . 'Command'; + $className = sprintf( + '%s\%s%sCommand', + $this->getNamespace(), + $this->getCapitalizedClassPrefix(), + self::convertToClassName($commandName) + ); // Create command class name $this->setClassName($className); @@ -150,22 +156,31 @@ class BaseCommandResolver extends BaseResolver { /** * Checks whether the given command is valid * + * @param $namespace Namespace to look in * @param $commandName The default command we shall execute * @return $isValid Whether the given command is valid * @throws EmptyVariableException Thrown if given command is not set */ - public function isCommandValid ($commandName) { + protected function isCommandValid ($namespace, $commandName) { // By default nothing shall be valid $isValid = FALSE; - // Is a command set? - if (empty($commandName)) { + // Is namespace and command name set? + if (empty($namespace)) { + // Then thrown an exception here + throw new EmptyVariableException(array($this, 'namespace'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (empty($commandName)) { // Then thrown an exception here throw new EmptyVariableException(array($this, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } // END - if // Create the full class name - $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($commandName) . 'Command'; + $className = sprintf( + '%s\%s%sCommand', + $namespace, + $this->getCapitalizedClassPrefix(), + self::convertToClassName($commandName) + ); // Now, let us create the full name of the command class $this->setClassName($className); diff --git a/inc/main/classes/resolver/command/console/class_ConsoleCommandResolver.php b/inc/main/classes/resolver/command/console/class_ConsoleCommandResolver.php index 42ac4c75..7a06feb8 100644 --- a/inc/main/classes/resolver/command/console/class_ConsoleCommandResolver.php +++ b/inc/main/classes/resolver/command/console/class_ConsoleCommandResolver.php @@ -3,6 +3,7 @@ namespace CoreFramework\Resolver\Command; // Import framework stuff +use CoreFramework\Command\InvalidCommandException; use CoreFramework\Manager\ManageableApplication; /** diff --git a/inc/main/classes/resolver/command/html/class_HtmlCommandResolver.php b/inc/main/classes/resolver/command/html/class_HtmlCommandResolver.php index ce20802b..adc10cbe 100644 --- a/inc/main/classes/resolver/command/html/class_HtmlCommandResolver.php +++ b/inc/main/classes/resolver/command/html/class_HtmlCommandResolver.php @@ -3,6 +3,7 @@ namespace CoreFramework\Resolver\Command; // Import framework stuff +use CoreFramework\Command\InvalidCommandException; use CoreFramework\Manager\ManageableApplication; /** diff --git a/inc/main/classes/resolver/command/image/class_ImageCommandResolver.php b/inc/main/classes/resolver/command/image/class_ImageCommandResolver.php index 4a473b52..8d19319b 100644 --- a/inc/main/classes/resolver/command/image/class_ImageCommandResolver.php +++ b/inc/main/classes/resolver/command/image/class_ImageCommandResolver.php @@ -3,6 +3,7 @@ namespace CoreFramework\Resolver\Command; // Import framework stuff +use CoreFramework\Command\InvalidCommandException; use CoreFramework\Manager\ManageableApplication; /** diff --git a/inc/main/classes/resolver/controller/class_BaseControllerResolver.php b/inc/main/classes/resolver/controller/class_BaseControllerResolver.php index 3d318897..6f2da6fe 100644 --- a/inc/main/classes/resolver/controller/class_BaseControllerResolver.php +++ b/inc/main/classes/resolver/controller/class_BaseControllerResolver.php @@ -73,7 +73,12 @@ class BaseControllerResolver extends BaseResolver { //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BEFORE: controller=' . $controllerName); if ($controllerName != $defaultController) { // Create controller class name - $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($controllerName) . 'Controller'; + $className = sprintf( + '%s\%s%sController', + $namespace, + $this->getCapitalizedClassPrefix(), + self::convertToClassName($controllerName) + ); // ... and set it $this->setClassName($className); @@ -124,7 +129,7 @@ class BaseControllerResolver extends BaseResolver { * @throws EmptyVariableException Thrown if given controller is not set * @throws DefaultControllerException Thrown if default controller was not found */ - public function isControllerValid ($namespace, $controllerName) { + protected function isControllerValid ($namespace, $controllerName) { // By default nothing shall be valid $isValid = FALSE; diff --git a/inc/main/exceptions/class_FrameworkException.php b/inc/main/exceptions/class_FrameworkException.php index 454c1028..866e59f7 100644 --- a/inc/main/exceptions/class_FrameworkException.php +++ b/inc/main/exceptions/class_FrameworkException.php @@ -61,7 +61,8 @@ abstract class FrameworkException extends ReflectionException { // In emergency exit? if (defined('EMERGENCY_EXIT_CALLED')) { // Output message - printf("[%s:] Message: %s, Backtrace:
%s
", + printf( + '[%s:] Message: %s, Backtrace:
%s
', $this->__toString(), $message, $this->getPrintableBackTrace() @@ -74,7 +75,8 @@ abstract class FrameworkException extends ReflectionException { // Should we log exceptions? (bad implementation) if (defined('LOG_EXCEPTIONS')) { // Log the error - error_log(sprintf("[%s:] %s (%s)", + error_log(sprintf( + '[%s:] %s (%s)', $this->__toString(), $message, $this->getHexCode() diff --git a/inc/main/exceptions/main/class_InvalidCommandException.php b/inc/main/exceptions/main/class_InvalidCommandException.php index d4982fd7..274ba81c 100644 --- a/inc/main/exceptions/main/class_InvalidCommandException.php +++ b/inc/main/exceptions/main/class_InvalidCommandException.php @@ -1,6 +1,6 @@