3 namespace CoreFramework\Tests\Resolver\Command;
5 // Import framework stuff
6 use CoreFramework\Command\InvalidCommandException;
7 use CoreFramework\Generic\EmptyVariableException;
8 use CoreFramework\Manager\ManageableApplication;
9 use CoreFramework\Resolver\Command\BaseCommandResolver;
10 use CoreFramework\Resolver\Command\CommandResolver;
13 * A command resolver for console commands
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
21 * This program is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 class TestsConsoleCommandResolver extends BaseCommandResolver implements CommandResolver {
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
44 // Set prefix to "TestsConsole"
45 $this->setClassPrefix('tests_console');
49 * Creates an instance of a TestsConsole command resolver with a given default command
51 * @param $commandName The default command we shall execute
52 * @param $applicationInstance An instance of a manageable application helper class
53 * @return $resolverInstance The prepared command resolver instance
54 * @throws EmptyVariableException Thrown if default command is not set
55 * @throws InvalidCommandException Thrown if default command is invalid
57 public static final function createTestsConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) {
58 // Create the new instance
59 $resolverInstance = new TestsConsoleCommandResolver();
61 // Is the variable $commandName set and the command is valid?
62 if (empty($commandName)) {
63 // Then thrown an exception here
64 throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
65 } elseif ($resolverInstance->isCommandValid('CoreFramework\Tests\Command', $commandName) === FALSE) {
66 // Invalid command found
67 throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
70 // Set the application instance
71 $resolverInstance->setApplicationInstance($applicationInstance);
73 // Return the prepared instance
74 return $resolverInstance;