* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class UniversalNodeLocator extends BaseFrameworkSystem implements LocateableNode { //------- UNL parts ------- // Protocol const UNL_PART_PROTOCOL = 'protocol'; // Address const UNL_PART_ADDRESS = 'address'; // Extra part const UNL_PART_EXTRA = 'extra'; // Port (if any) const UNL_PART_PORT = 'port'; /** * UNL data array */ private $unlData = array(); /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Creates an instance of this class * * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional. * @return $unlInstance An instance of a LocateableNode class */ public final static function createUniversalNodeLocator (array $current = array()) { // Get new instance $unlInstance = new UniversalNodeLocator(); // Init instance $unlInstance->initUniversalNodeLocator($current); // Return the prepared instance return $unlInstance; } /** * Initializes the UNL instance by givena array. If an entry is found, it * will be copied, otherwise the entry is set empty. * * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional. * @return void */ private function initUniversalNodeLocator (array $current = array()) { // Init UNL array $this->unlData = array(); // Copy all found entries foreach (array( NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) { // Init entry $this->unlData[$key] = NULL; // Is the key found? if (isset($current[$key])) { // The copy the entry $this->unlData[$key] = $current[$key]; } // END - if } // END - foreach } /** * Getter for UNL data array * * @return $unlData An array with UNL data */ public final function getUnlData () { return $this->unlData; } } // [EOF] ?>