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