added files for database format-upgrade
[core.git] / inc / main / classes / resolver / class_
1 <?php
2 /**
3  * A ??? resolver
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class ???Resolver extends BaseResolver implements Resolver {
25         /**
26          * Protected constructor
27          *
28          * @return      void
29          */
30         protected function __construct () {
31                 // Call parent constructor
32                 parent::__construct(__CLASS__);
33
34                 // Set prefix to '???'
35                 $this->setClassPrefix('???');
36         }
37
38         /**
39          * Creates an instance of a ??? resolver with a given default action
40          *
41          * @param       $!!!Name                                The default action we shall execute
42          * @param       $appInstance                    An instance of a manageable application helper class
43          * @return      $resolverInstance               The prepared action resolver instance
44          * @throws      EmptyVariableException  Thrown if default action is not set
45          * @throws      Invalid|||Exception     Thrown if default action is invalid
46          */
47         public static final function create???Resolver ($!!!Name, ManageableApplication $appInstance) {
48                 // Create the new instance
49                 $resolverInstance = new ???Resolver();
50
51                 // Is the variable $!!!Name set and the action is valid?
52                 if (empty($!!!Name)) {
53                         // Then thrown an exception here
54                         throw new EmptyVariableException(array($resolverInstance, 'default|||'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
55                 } elseif ($resolverInstance->is|||Valid($!!!Name) === FALSE) {
56                         // Invalid action found
57                         throw new Invalid|||Exception(array($resolverInstance, $!!!Name), self::EXCEPTION_INVALID_ACTION);
58                 }
59
60                 // Set the application instance
61                 $resolverInstance->setApplicationInstance($appInstance);
62
63                 // Return the prepared instance
64                 return $resolverInstance;
65         }
66
67         /**
68          * Returns an action instance for a given request class or null if
69          * it was not found
70          *
71          * @param       $requestInstance        An instance of a request class
72          * @return      $!!!Instance    An instance of the resolved action
73          * @throws      Invalid|||Exception                             Thrown if $!!!Name is
74          *                                                                                              invalid
75          * @throws      Invalid|||InstanceException             Thrown if $!!!Instance
76          *                                                                                              is an invalid instance
77          */
78         public function resolve|||ByRequest (Requestable $requestInstance) {
79                 // Init variables
80                 $!!!Name = '';
81                 $!!!Instance = null;
82
83                 // This goes fine so let's resolve the action
84                 $!!!Name = $requestInstance->getRequestElement('action');
85
86                 // Is the action empty? Then fall back to default action
87                 if (empty($!!!Name)) $!!!Name = $this->getConfigInstance()->getConfigEntry('default_action');
88
89                 // Check if action is valid
90                 if ($this->is|||Valid($!!!Name) === FALSE) {
91                         // This action is invalid!
92                         throw new Invalid|||Exception(array($this, $!!!Name), self::EXCEPTION_INVALID_ACTION);
93                 } // END - if
94
95                 // Get the action
96                 $!!!Instance = $this->load|||();
97
98                 // And validate it
99                 if ((!is_object($!!!Instance)) || (!$!!!Instance instanceof |||able)) {
100                         // This action has an invalid instance!
101                         throw new Invalid|||InstanceException(array($this, $!!!Name), self::EXCEPTION_INVALID_ACTION);
102                 } // END - if
103
104                 // Set last action
105                 $this->setResolvedInstance($!!!Instance);
106
107                 // Return the resolved action instance
108                 return $!!!Instance;
109         }
110
111         /**
112          * Resolves the action by its direct name and returns an instance of its class
113          *
114          * @return      $!!!Instance            An instance of the action class
115          * @throws      Invalid|||Exception     Thrown if $!!!Name is invalid
116          */
117         public function resolve||| () {
118                 // Initiate the instance variable
119                 $!!!Instance = null;
120
121                 // Get action name
122                 $!!!Name = $this->get|||Name();
123
124                 // Is the action empty? Then fall back to default action
125                 if (empty($!!!Name)) {
126                         $!!!Name = $this->getConfigInstance()->getConfigEntry('default_action');
127                 } // END - if
128
129                 // Check if action is valid
130                 if ($this->is|||Valid($!!!Name) === FALSE) {
131                         // This action is invalid!
132                         throw new Invalid|||Exception(array($this, $!!!Name), self::EXCEPTION_INVALID_ACTION);
133                 } // END - if
134
135                 // Get the action
136                 $!!!Instance = $this->load|||();
137
138                 // Return the instance
139                 return $!!!Instance;
140         }
141
142 }