]> git.mxchange.org Git - hub.git/blob - application/hub/main/unl/class_UniversalNodeLocator.php
Continued with refacturing:
[hub.git] / application / hub / main / unl / class_UniversalNodeLocator.php
1 <?php
2 /**
3  * A UniversalNodeLocator
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub 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 UniversalNodeLocator extends BaseFrameworkSystem implements LocateableNode {
25         /**
26          * UNL data array
27          */
28         private $unlData = array();
29
30         /**
31          * Protected constructor
32          *
33          * @return      void
34          */
35         protected function __construct () {
36                 // Call parent constructor
37                 parent::__construct(__CLASS__);
38         }
39
40         /**
41          * Creates an instance of this class
42          *
43          * @param       $current                An array with "raw" data from the database layer for the UNL. This parameter is optional.
44          * @return      $unlInstance    An instance of a LocateableNode class
45          */
46         public final static function createUniversalNodeLocator (array $current = array()) {
47                 // Get new instance
48                 $unlInstance = new UniversalNodeLocator();
49
50                 // Init instance
51                 $unlInstance->initUniversalNodeLocator($current);
52
53                 // Return the prepared instance
54                 return $unlInstance;
55         }
56
57         /**
58          * Initializes the UNL instance by givena array. If an entry is found, it
59          * will be copied, otherwise the entry is set empty.
60          *
61          * @param       $current        An array with "raw" data from the database layer for the UNL. This parameter is optional.
62          * @return      void
63          */
64         private function initUniversalNodeLocator (array $current = array()) {
65                 // Init UNL array
66                 $this->unlData = array();
67
68                 // Copy all found entries
69                 foreach (array(
70                         NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID,
71                         NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID,
72                         NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH,
73                         NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE,
74                         NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL,
75                         NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) {
76                                 // Init entry
77                                 $this->unlData[$key] = NULL;
78
79                                 // Is the key found?
80                                 if (isset($current[$key])) {
81                                         // The copy the entry
82                                         $this->unlData[$key] = $current[$key];
83                                 } // END - if
84                 } // END - foreach
85         }
86
87         /**
88          * Getter for UNL data array
89          *
90          * @return      $unlData        An array with UNL data
91          */
92         public final function getUnlData () {
93                 return $this->unlData;
94         }
95 }
96
97 // [EOF]
98 ?>