3 namespace CoreFramework\Resolver\Controller;
6 * A resolver for resolving controllers locally
8 * @author Roland Haeder <webmaster@shipsimu.org>
10 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11 * @license GNU GPL 3.0 or any newer version
12 * @link http://www.shipsimu.org
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 class TestsConsoleControllerResolver extends BaseControllerResolver implements ControllerResolver {
29 * Protected constructor
33 protected function __construct () {
34 // Call parent constructor
35 parent::__construct(__CLASS__);
37 // Set prefix to "TestsConsole"
38 $this->setClassPrefix('tests_console');
42 * Creates an instance of a resolver class with a given command
44 * @param $controllerName The controller we shall resolve
45 * @param $applicationInstance An instance of a manageable application helper class
46 * @return $resolverInstance The prepared controller resolver instance
47 * @throws EmptyVariableException Thrown if default command is not set
48 * @throws InvalidControllerException Thrown if default controller is invalid
50 public static final function createTestsConsoleControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
51 // Create the new instance
52 $resolverInstance = new TestsConsoleControllerResolver();
54 // Is the variable $controllerName set and the command is valid?
55 if (empty($controllerName)) {
56 // Then thrown an exception here
57 throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
58 } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) {
59 // Invalid command found
60 throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
63 // Set the application instance
64 $resolverInstance->setApplicationInstance($applicationInstance);
67 $resolverInstance->setControllerName($controllerName);
69 // Return the prepared instance
70 return $resolverInstance;
74 * Resolves the default controller of the given command
76 * @return $controllerInstance A controller instance for the default
78 * @throws InvalidControllerInstanceException Thrown if $controllerInstance
81 public function resolveController () {
84 $controllerInstance = NULL;
86 // Get the command name
87 $controllerName = $this->getControllerName();
90 $controllerInstance = $this->loadController($controllerName);
93 if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
94 // This command has an invalid instance!
95 throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
98 // Set last controller
99 $this->setResolvedInstance($controllerInstance);
101 // Return the maybe resolved instance
102 return $controllerInstance;