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