]> git.mxchange.org Git - hub.git/blob - application/hub/main/unl/class_UniversalNodeLocator.php
Updated 'core'.
[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 - 2015 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         //------- UNL parts -------
26         // Protocol
27         const UNL_PART_PROTOCOL = 'protocol';
28         // Address
29         const UNL_PART_ADDRESS  = 'address';
30         // Extra part
31         const UNL_PART_EXTRA    = 'extra';
32         // Port (if any)
33         const UNL_PART_PORT     = 'port';
34
35         /**
36          * UNL data array
37          */
38         private $unlData = array();
39
40         /**
41          * Protected constructor
42          *
43          * @return      void
44          */
45         protected function __construct () {
46                 // Call parent constructor
47                 parent::__construct(__CLASS__);
48         }
49
50         /**
51          * Creates an instance of this class
52          *
53          * @param       $current                An array with "raw" data from the database layer for the UNL. This parameter is optional.
54          * @return      $unlInstance    An instance of a LocateableNode class
55          */
56         public final static function createUniversalNodeLocator (array $current = array()) {
57                 // Get new instance
58                 $unlInstance = new UniversalNodeLocator();
59
60                 // Init instance
61                 $unlInstance->initUniversalNodeLocator($current);
62
63                 // Return the prepared instance
64                 return $unlInstance;
65         }
66
67         /**
68          * Initializes the UNL instance by givena array. If an entry is found, it
69          * will be copied, otherwise the entry is set empty.
70          *
71          * @param       $current        An array with "raw" data from the database layer for the UNL. This parameter is optional.
72          * @return      void
73          */
74         private function initUniversalNodeLocator (array $current = array()) {
75                 // Init UNL array
76                 $this->unlData = array();
77
78                 // Copy all found entries
79                 foreach (array(
80                         NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID,
81                         NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID,
82                         NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH,
83                         NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE,
84                         NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL,
85                         NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) {
86                                 // Init entry
87                                 $this->unlData[$key] = NULL;
88
89                                 // Is the key found?
90                                 if (isset($current[$key])) {
91                                         // The copy the entry
92                                         $this->unlData[$key] = $current[$key];
93                                 } // END - if
94                 } // END - foreach
95         }
96
97         /**
98          * Getter for UNL data array
99          *
100          * @return      $unlData        An array with UNL data
101          */
102         public final function getUnlData () {
103                 return $this->unlData;
104         }
105 }
106
107 // [EOF]
108 ?>