From: Roland Haeder Date: Sat, 25 Apr 2015 22:30:13 +0000 (+0200) Subject: Fixes for crawler: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a5540330a99c3edde8dcd6613ff12fb8b4e26c66;p=hub.git Fixes for crawler: - Removed 2nd parameter $crawlerInstance as this can be get from object registry - Other improvements Signed-off-by: Roland Haeder --- diff --git a/application/hub/config.php b/application/hub/config.php index 8b39d7ed4..1a8e5fa6b 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -920,7 +920,7 @@ $cfg->setConfigEntry('miner_default_mode', 'chash'); // CFG: MINER-BUFFER-STACKER-CLASS $cfg->setConfigEntry('miner_buffer_stacker_class', 'FiFoStacker'); -// CFG: HUBCONSOLE-CMD-CRUNCHER-RESOLVER-CLASS +// CFG: HUB-CONSOLE-CMD-CRUNCHER-RESOLVER-CLASS $cfg->setConfigEntry('hub_console_cmd_miner_resolver_class', 'HubConsoleCommandResolver'); // CFG: MINER-PHP-REQUIREMENTS-FILTER @@ -1008,7 +1008,7 @@ $cfg->setConfigEntry('cruncher_default_mode', 'mcrypt'); // CFG: CRUNCHER-BUFFER-STACKER-CLASS $cfg->setConfigEntry('cruncher_buffer_stacker_class', 'FiFoStacker'); -// CFG: HUBCONSOLE-CMD-CRUNCHER-RESOLVER-CLASS +// CFG: HUB-CONSOLE-CMD-CRUNCHER-RESOLVER-CLASS $cfg->setConfigEntry('hubconsole_cmd_cruncher_resolver_class', 'HubConsoleCommandResolver'); // CFG: CRUNCHER-PHP-REQUIREMENTS-FILTER @@ -1147,7 +1147,7 @@ $cfg->setConfigEntry('cruncher_per_unit_key_limit', 1000); // Chat Configuration /////////////////////////////////////////////////////////////////////////////// -// CFG: HUBCONSOLE-CMD-CHAT-RESOLVER-CLASS +// CFG: HUB-CONSOLE-CMD-CHAT-RESOLVER-CLASS $cfg->setConfigEntry('hubconsole_cmd_chat_resolver_class', 'HubConsoleCommandResolver'); // CFG: CHAT-PHP-REQUIREMENTS-FILTER @@ -1199,8 +1199,8 @@ $cfg->setConfigEntry('file_stacks_extension', 'stack'); // CFG: INDEX-EXTENSION $cfg->setConfigEntry('index_extension', '.idx'); -// CFG: HUBCONSOLE-CMD-CHAT-RESOLVER-CLASS -$cfg->setConfigEntry('hubconsole_cmd_crawler_resolver_class', 'HubConsoleCommandResolver'); +// CFG: HUB-CONSOLE-CMD-CHAT-RESOLVER-CLASS +$cfg->setConfigEntry('hub_console_cmd_crawler_resolver_class', 'HubConsoleCommandResolver'); // CFG: CRAWLER-PHP-REQUIREMENTS-FILTER $cfg->setConfigEntry('crawler_php_requirements_filter', 'CrawlerPhpRequirementsFilter'); @@ -1480,8 +1480,8 @@ $cfg->setConfigEntry('news_home_limit', 10); // Apt-Proxy Configuration /////////////////////////////////////////////////////////////////////////////// -// CFG: HUBCONSOLE-CMD-APT-PROXY-RESOLVER-CLASS -$cfg->setConfigEntry('hubconsole_cmd_apt_proxy_resolver_class', 'HubConsoleCommandResolver'); +// CFG: HUB-CONSOLE-CMD-APT-PROXY-RESOLVER-CLASS +$cfg->setConfigEntry('hub_console_cmd_apt_proxy_resolver_class', 'HubConsoleCommandResolver'); // CFG: APT-PROXY-PHP-REQUIREMENTS-FILTER $cfg->setConfigEntry('apt_proxy_php_requirements_filter', 'AptProxyPhpRequirementsFilter'); diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index 0dc699244..e3264277f 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -54,11 +54,6 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $communicatorInstance = NULL; - /** - * An instance of a crawler - */ - private $crawlerInstance = NULL; - /** * An instance of a cruncher */ @@ -158,25 +153,6 @@ class BaseHubSystem extends BaseFrameworkSystem { $this->communicatorInstance = $communicatorInstance; } - /** - * Getter for crawler instance - * - * @return $crawlerInstance An instance of a Crawler class - */ - public final function getCrawlerInstance () { - return $this->crawlerInstance; - } - - /** - * Setter for crawler instance - * - * @param $crawlerInstance An instance of a Crawler class - * @return void - */ - protected final function setCrawlerInstance (Crawler $crawlerInstance) { - $this->crawlerInstance = $crawlerInstance; - } - /** * Getter for cruncher instance * diff --git a/application/hub/main/crawler/class_BaseNodeCrawler.php b/application/hub/main/crawler/class_BaseNodeCrawler.php index 62ab12074..d5ce4a5d8 100644 --- a/application/hub/main/crawler/class_BaseNodeCrawler.php +++ b/application/hub/main/crawler/class_BaseNodeCrawler.php @@ -37,6 +37,9 @@ class BaseNodeCrawler extends BaseHubSystem { // Call parent constructor parent::__construct($className); + // Set this crawler instance in registry + Registry::getRegistry()->addInstance('crawler', $this); + // Init state which sets the state to 'init' $this->initState(); } @@ -48,7 +51,7 @@ class BaseNodeCrawler extends BaseHubSystem { */ private function initState() { // Get the state factory and create the initial state. - CrawlerStateFactory::createCrawlerStateInstanceByName('init', $this); + CrawlerStateFactory::createCrawlerStateInstanceByName('init'); } /** diff --git a/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php b/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php index 08e0cc554..4b0eb52fb 100644 --- a/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php +++ b/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php @@ -37,15 +37,17 @@ class CrawlerStateFactory extends ObjectFactory { * given crawler instance. * * @param $stateName Name of the state - * @param $crawlerInstance A Crawler class instance * @return $stateInstance A Stateable class instance */ - public static final function createCrawlerStateInstanceByName ($stateName, Crawler $crawlerInstance) { + public static final function createCrawlerStateInstanceByName ($stateName) { // Then construct the class' configuraton entry $className = 'crawler_' . $stateName . '_state_class'; // Get a class from that configuration entry - $stateInstance = self::createObjectByConfiguredName($className, array($crawlerInstance)); + $stateInstance = self::createObjectByConfiguredName($className); + + // Get crawler instance + $crawlerInstance = Registry::getRegistry()->getInstance('crawler'); // Debug message self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Crawler state has changed from ' . $crawlerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); diff --git a/application/hub/main/filter/crawler/class_CrawlerInitializationFilter.php b/application/hub/main/filter/crawler/class_CrawlerInitializationFilter.php index 31ae09a9a..570346eec 100644 --- a/application/hub/main/filter/crawler/class_CrawlerInitializationFilter.php +++ b/application/hub/main/filter/crawler/class_CrawlerInitializationFilter.php @@ -65,9 +65,6 @@ class CrawlerInitializationFilter extends BaseCrawlerFilter implements Filterabl // Add crawler-specific filters $crawlerInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); - - // Set the crawler instance in registry - Registry::getRegistry()->addInstance('crawler', $crawlerInstance); } } diff --git a/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php b/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php index 4c28ab0c5..33caffaf8 100644 --- a/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php +++ b/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php @@ -161,7 +161,7 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvData()=' . count($csvData) . ' - CALLED!'); - // The array has 3 elements, later enhancements may accept more + // The array must have a fixed amount of elements, later enhancements may accept more assert(count($csvData) == self::CRAWL_ENTRY_SIZE); /* @@ -282,7 +282,7 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R return; } // END - if - // ... with 3 elements, later enhancements may accept more + // ... with a fixed amount of elements, later enhancements may accept more assert(count($csvData) == self::CRAWL_ENTRY_SIZE); /* @@ -313,7 +313,7 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvData[' . gettype($csvData) . ']=' . print_r($csvData, TRUE)); - // It must have 3 elements (see method parseCsvFile() for details) + // It must have a fixed amount of elements (see method parseCsvFile() for details) assert(count($csvData) == self::CRAWL_ENTRY_SIZE); // Save it in crawler queue (which will enrich it with way more informations diff --git a/application/hub/main/states/crawler/active/class_CrawlerActiveState.php b/application/hub/main/states/crawler/active/class_CrawlerActiveState.php index e06e9f4d9..5abe58723 100644 --- a/application/hub/main/states/crawler/active/class_CrawlerActiveState.php +++ b/application/hub/main/states/crawler/active/class_CrawlerActiveState.php @@ -41,13 +41,10 @@ class CrawlerActiveState extends BaseCrawlerState implements Stateable { * @param $crawlerInstance An instance of a Crawler class * @return $stateInstance An instance of a Stateable class */ - public static final function createCrawlerActiveState (Crawler $crawlerInstance) { + public static final function createCrawlerActiveState () { // Get new instance $stateInstance = new CrawlerActiveState(); - // Set the crawler instance - $stateInstance->setCrawlerInstance($crawlerInstance); - // Return the prepared instance return $stateInstance; } diff --git a/application/hub/main/states/crawler/booting/class_CrawlerBootingState.ph b/application/hub/main/states/crawler/booting/class_CrawlerBootingState.ph index 289d49e6c..ffb733e30 100644 --- a/application/hub/main/states/crawler/booting/class_CrawlerBootingState.ph +++ b/application/hub/main/states/crawler/booting/class_CrawlerBootingState.ph @@ -10,5 +10,5 @@ $this->partialStub('Unfinished method.'); // Change state to 'active' - CrawlerStateFactory::createCrawlerStateInstanceByName('active', $this->getCrawlerInstance()); + CrawlerStateFactory::createCrawlerStateInstanceByName('active'); } diff --git a/application/hub/main/states/crawler/booting/class_CrawlerBootingState.php b/application/hub/main/states/crawler/booting/class_CrawlerBootingState.php index 7e7e52b96..6edbdbbd7 100644 --- a/application/hub/main/states/crawler/booting/class_CrawlerBootingState.php +++ b/application/hub/main/states/crawler/booting/class_CrawlerBootingState.php @@ -38,16 +38,12 @@ class CrawlerBootingState extends BaseCrawlerState implements Stateable { /** * Creates an instance of this class * - * @param $crawlerInstance An instance of a Crawler class - * @return $stateInstance An instance of a Stateable class + * @return $stateInstance An instance of a Stateable class */ - public static final function createCrawlerBootingState (Crawler $crawlerInstance) { + public static final function createCrawlerBootingState () { // Get new instance $stateInstance = new CrawlerBootingState(); - // Set the crawler instance - $stateInstance->setCrawlerInstance($crawlerInstance); - // Return the prepared instance return $stateInstance; } diff --git a/application/hub/main/states/crawler/init/class_CrawlerInitState.php b/application/hub/main/states/crawler/init/class_CrawlerInitState.php index 1e2e4dc2c..fffd219ed 100644 --- a/application/hub/main/states/crawler/init/class_CrawlerInitState.php +++ b/application/hub/main/states/crawler/init/class_CrawlerInitState.php @@ -38,16 +38,12 @@ class CrawlerInitState extends BaseCrawlerState implements Stateable { /** * Creates an instance of this class * - * @param $crawlerInstance An instance of a Crawler class - * @return $stateInstance An instance of a Stateable class + * @return $stateInstance An instance of a Stateable class */ - public static final function createCrawlerInitState (Crawler $crawlerInstance) { + public static final function createCrawlerInitState () { // Get new instance $stateInstance = new CrawlerInitState(); - // Set the crawler instance - $stateInstance->setCrawlerInstance($crawlerInstance); - // Return the prepared instance return $stateInstance; } @@ -74,7 +70,7 @@ class CrawlerInitState extends BaseCrawlerState implements Stateable { $this->partialStub('Unfinished method.'); // Change state to 'booting' - CrawlerStateFactory::createCrawlerStateInstanceByName('booting', $this->getCrawlerInstance()); + CrawlerStateFactory::createCrawlerStateInstanceByName('booting'); } }