adc10cbeaae25ee40adda608bba7aa27ef2f2cb4
[core.git] / inc / main / classes / resolver / command / html / class_HtmlCommandResolver.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Resolver\Command;
4
5 // Import framework stuff
6 use CoreFramework\Command\InvalidCommandException;
7 use CoreFramework\Manager\ManageableApplication;
8
9 /**
10  * A command resolver for local (non-hubbed) HTML commands
11  *
12  * @author              Roland Haeder <webmaster@shipsimu.org>
13  * @version             0.0.0
14  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15  * @license             GNU GPL 3.0 or any newer version
16  * @link                http://www.shipsimu.org
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program. If not, see <http://www.gnu.org/licenses/>.
30  */
31 class HtmlCommandResolver extends BaseCommandResolver implements CommandResolver {
32         /**
33          * Last successfull resolved command
34          */
35         private $lastCommandInstance = NULL;
36
37         /**
38          * Protected constructor
39          *
40          * @return      void
41          */
42         protected function __construct () {
43                 // Call parent constructor
44                 parent::__construct(__CLASS__);
45
46                 // Set prefix to "html"
47                 $this->setClassPrefix('html');
48         }
49
50         /**
51          * Creates an instance of a Html command resolver with a given default command
52          *
53          * @param       $commandName                            The default command we shall execute
54          * @param       $applicationInstance            An instance of a manageable application helper class
55          * @return      $resolverInstance                       The prepared command resolver instance
56          * @throws      EmptyVariableException          Thrown if default command is not set
57          * @throws      InvalidCommandException         Thrown if default command is invalid
58          */
59         public static final function createHtmlCommandResolver ($commandName, ManageableApplication $applicationInstance) {
60                 // Create the new instance
61                 $resolverInstance = new HtmlCommandResolver();
62
63                 // Is the variable $commandName set and the command is valid?
64                 if (empty($commandName)) {
65                         // Then thrown an exception here
66                         throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
67                 } elseif ($resolverInstance->isCommandValid($commandName) === FALSE) {
68                         // Invalid command found
69                         throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
70                 }
71
72                 // Set the application instance
73                 $resolverInstance->setApplicationInstance($applicationInstance);
74
75                 // Return the prepared instance
76                 return $resolverInstance;
77         }
78
79 }