From 5a3daf63337c633f90208bbc59560d25ad6397dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 1 May 2009 20:07:34 +0000 Subject: [PATCH] Rewritten class structure to make it more OOP-friendly (stupid comment, I know) --- application/hub/class_ApplicationHelper.php | 10 ++-------- .../hub/main/nodes/boot/class_HubBootNode.php | 16 +++++++++++++--- application/hub/main/nodes/class_ | 7 +++++-- .../hub/main/nodes/class_BaseHubNode.php | 17 ++++++++--------- .../hub/main/nodes/list/class_BootListNode.php | 14 ++++++++++++-- .../main/nodes/master/class_HubMasterNode.php | 14 ++++++++++++-- .../main/nodes/regular/class_HubRegularNode.php | 14 ++++++++++++-- index.php | 3 ++- 8 files changed, 66 insertions(+), 29 deletions(-) diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 4a3992720..ed5f03642 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -185,16 +185,10 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica die('Node mode ' . $nodeMode . ' is invalid.' . "\n"); } - // --------------------- Hub-id acquirement phase --------------------- - // Acquire a hub-id. This step generates on first launch anew one and - // on any later launches it will restore the hub-id from the database. - // A passed 'nickname=xxx' argument will be used to add some - // 'personality' to the hub. - $nodeInstance->acquireHubId($requestInstance); - // --------------------- Bootstrapping phase --------------------- // Try to bootstrap the node and pass the request instance to it for - // extra arguments which mostly override config entries + // extra arguments which mostly override config entries or enable special + // features within the hub (none is ready at this development stage) $nodeInstance->doBootstrapping($requestInstance); } diff --git a/application/hub/main/nodes/boot/class_HubBootNode.php b/application/hub/main/nodes/boot/class_HubBootNode.php index 0be26c3d3..32bb6366d 100644 --- a/application/hub/main/nodes/boot/class_HubBootNode.php +++ b/application/hub/main/nodes/boot/class_HubBootNode.php @@ -45,6 +45,13 @@ class HubBootNode extends BaseHubNode implements NodeHelper { // Set the request instance $nodeInstance->setRequestInstance($requestInstance); + // --------------------- Hub-id acquirement phase --------------------- + // Acquire a hub-id. This step generates on first launch a new one and + // on any later launches it will restore the hub-id from the database. + // A passed 'nickname=xxx' argument will be used to add some + // 'personality' to the hub. + $nodeInstance->acquireHubId(); + // Return the instance return $nodeInstance; } @@ -58,12 +65,12 @@ class HubBootNode extends BaseHubNode implements NodeHelper { * @todo add some more special bootstrap things for this boot node */ public function doBootstrapping () { - // Call generic (parent) bootstrapping method + // Call generic (parent) bootstrapping method first parent::doGenericBootstrapping(); // Now check if the IP address matches one of the bootstrap nodes if ($this->ifAddressMatchesBootstrappingNodes($_SERVER['REMOTE_ADDR'])) { - // Get our port + // Get our port from configuration $ourPort = $this->getConfigInstance()->readConfig('node_listen_port'); // Is the port the same? @@ -83,7 +90,10 @@ class HubBootNode extends BaseHubNode implements NodeHelper { } // END - if // This might not be all... - $this->partialStub("Please implement more bootsrapping steps."); + $this->partialStub('Please implement more bootsrapping steps.'); + + // This should be the last thing to do: output teaser lines + $this->outputConsoleTeaser(); } } diff --git a/application/hub/main/nodes/class_ b/application/hub/main/nodes/class_ index c357328a7..215ade831 100644 --- a/application/hub/main/nodes/class_ +++ b/application/hub/main/nodes/class_ @@ -58,9 +58,12 @@ class Hub???Node extends BaseHubNode implements NodeHelper { * @todo Implement this method */ public function doBootstrapping () { - // Call generic (parent) bootstrapping method + // Call generic (parent) bootstrapping method first parent::doGenericBootstrapping(); - $this->partialStub("Please implement this method."); + $this->partialStub('Please implement this method.'); + + // This is the last line: output teaser + $this->outputTeaserLines(); } } diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 03f8f5052..319ae987a 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -120,7 +120,7 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { * * @return void */ - private function outputConsoleTeaser () { + protected function outputConsoleTeaser () { // Get the app instance (for shortening our code) $app = $this->getApplicationInstance(); @@ -139,12 +139,12 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { * Do generic things for bootup phase. This can be e.g. checking if the * right node mode is selected for this hub's IP number. * - * @todo This method is maybe not yet finished. * @return void + * @todo This method is maybe not yet finished. */ protected function doGenericBootstrapping () { - // Finally output our teaser. This should be the last line! - $this->outputConsoleTeaser(); + // @TODO Empty method + $this->partialStub('Add some generic bootstrap steps here.'); } /** @@ -152,10 +152,9 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { * based on many pseudo-random data. On any later run, unless the id * got not removed from database, it will be restored from the database. * - * @param $requestInstance An instance of a Requestable class * @return void */ - public function acquireHubId (Requestable $requestInstance) { + protected function acquireHubId () { // Get a wrapper instance $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class'); @@ -164,7 +163,7 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { // Search for the node number zero which is hard-coded the default $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1); - $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $requestInstance->getRequestElement('mode')); + $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode')); $searchInstance->setLimit(1); // Get a result back @@ -185,7 +184,7 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); // Generate a pseudo-random string - $randomString = $rngInstance->randomString(255) . ':' . $requestInstance->getRequestElement('mode'); + $randomString = $rngInstance->randomString(255) . ':' . $this->getRequestInstance()->getRequestElement('mode'); // Get a crypto instance $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class'); @@ -194,7 +193,7 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { $this->setNodeId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString))); // Register the node id with our wrapper - $wrapperInstance->registerNodeId($this, $requestInstance); + $wrapperInstance->registerNodeId($this, $this->getRequestInstance()); // Output message $this->getDebugInstance()->output('Created new node-id: ' . $this->getNodeId() . ''); diff --git a/application/hub/main/nodes/list/class_BootListNode.php b/application/hub/main/nodes/list/class_BootListNode.php index d0addef0d..2b5257fe7 100644 --- a/application/hub/main/nodes/list/class_BootListNode.php +++ b/application/hub/main/nodes/list/class_BootListNode.php @@ -45,6 +45,13 @@ class HubListNode extends BaseHubNode implements NodeHelper { // Set the request instance $nodeInstance->setRequestInstance($requestInstance); + // --------------------- Hub-id acquirement phase --------------------- + // Acquire a hub-id. This step generates on first launch a new one and + // on any later launches it will restore the hub-id from the database. + // A passed 'nickname=xxx' argument will be used to add some + // 'personality' to the hub. + $nodeInstance->acquireHubId(); + // Return the instance return $nodeInstance; } @@ -58,9 +65,12 @@ class HubListNode extends BaseHubNode implements NodeHelper { * @todo Implement this method */ public function doBootstrapping () { - // Call generic (parent) bootstrapping method + // Call generic (parent) bootstrapping method first parent::doGenericBootstrapping(); - $this->partialStub("Please implement this method."); + $this->partialStub('Please implement this method.'); + + // This should be the last line: output teaser + $this->outputConsoleTeaser(); } } diff --git a/application/hub/main/nodes/master/class_HubMasterNode.php b/application/hub/main/nodes/master/class_HubMasterNode.php index 9f41a0311..5de2a59dd 100644 --- a/application/hub/main/nodes/master/class_HubMasterNode.php +++ b/application/hub/main/nodes/master/class_HubMasterNode.php @@ -45,6 +45,13 @@ class HubMasterNode extends BaseHubNode implements NodeHelper { // Set the request instance $nodeInstance->setRequestInstance($requestInstance); + // --------------------- Hub-id acquirement phase --------------------- + // Acquire a hub-id. This step generates on first launch a new one and + // on any later launches it will restore the hub-id from the database. + // A passed 'nickname=xxx' argument will be used to add some + // 'personality' to the hub. + $nodeInstance->acquireHubId(); + // Return the instance return $nodeInstance; } @@ -58,9 +65,12 @@ class HubMasterNode extends BaseHubNode implements NodeHelper { * @todo Implement this method */ public function doBootstrapping () { - // Call generic (parent) bootstrapping method + // Call generic (parent) bootstrapping method first parent::doGenericBootstrapping(); - $this->partialStub("Please implement this method."); + $this->partialStub('Please implement this method.'); + + // This should be the last line: output teaser + $this->outputConsoleTeaser(); } } diff --git a/application/hub/main/nodes/regular/class_HubRegularNode.php b/application/hub/main/nodes/regular/class_HubRegularNode.php index fd3dbab98..4c497e613 100644 --- a/application/hub/main/nodes/regular/class_HubRegularNode.php +++ b/application/hub/main/nodes/regular/class_HubRegularNode.php @@ -45,6 +45,13 @@ class HubRegularNode extends BaseHubNode implements NodeHelper { // Set the request instance $nodeInstance->setRequestInstance($requestInstance); + // --------------------- Hub-id acquirement phase --------------------- + // Acquire a hub-id. This step generates on first launch a new one and + // on any later launches it will restore the hub-id from the database. + // A passed 'nickname=xxx' argument will be used to add some + // 'personality' to the hub. + $nodeInstance->acquireHubId(); + // Return the instance return $nodeInstance; } @@ -58,9 +65,12 @@ class HubRegularNode extends BaseHubNode implements NodeHelper { * @todo Implement this method */ public function doBootstrapping () { - // Call generic (parent) bootstrapping method + // Call generic (parent) bootstrapping method first parent::doGenericBootstrapping(); - $this->partialStub("Please implement this method."); + $this->partialStub('Please implement this method.'); + + // This is the last line: output teaser + $this->outputConsoleTeaser(); } } diff --git a/index.php b/index.php index b77289f9a..005004646 100644 --- a/index.php +++ b/index.php @@ -161,7 +161,8 @@ final class ApplicationEntryPoint { } /** - * Determines the correct absolute path for all includes + * Determines the correct absolute path for all includes only once per run. + * Other calls of this method are being "cached". * * @return $basePath Base path (core) for all includes */ -- 2.39.2