Index: branches/5.2.x/core/install/install_toolkit.php =================================================================== diff -u -r14244 -r14428 --- branches/5.2.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 14244) +++ branches/5.2.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 14428) @@ -1,6 +1,6 @@ Application->refreshModuleInfo(); // this module configs are now processed // because of configs was read only from installed before modules (in-portal), then reread configs - $unit_config_reader =& $this->Application->recallObject('kUnitConfigReader'); - /* @var $unit_config_reader kUnitConfigReader */ + $this->Application->UnitConfigReader->scanModules(MODULES_PATH . DIRECTORY_SEPARATOR . $module_folder); - $unit_config_reader->scanModules(MODULES_PATH . DIRECTORY_SEPARATOR . $module_folder); - // create correct columns in CustomData table $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); $ml_helper->createFields($prefix . '-cdata', true); Index: branches/5.2.x/core/units/helpers/mod_rewrite_helper.php =================================================================== diff -u -r14244 -r14428 --- branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14428) @@ -1,6 +1,6 @@ Array (), + 'registerAgent' => Array (), + 'registerHook' => Array (), + 'registerBuildEvent' => Array (), + 'registerAggregateTag' => Array (), + ); + /** * Creates caching manager instance * @@ -204,6 +212,8 @@ $cache = unserialize($data); // 126 KB all modules unset($data); + $this->Application->InitManagers(); + $this->Application->Factory->setFromCache($cache); $this->Application->UnitConfigReader->setFromCache($cache); $this->Application->EventManager->setFromCache($cache); @@ -224,6 +234,31 @@ } /** + * Empties factory and event manager cache (without storing changes) + */ + public function EmptyUnitCache() + { + $cache_keys = Array ( + 'Factory.Files', 'Factory.realClasses', 'Factory.Dependencies', + 'EventManager.buildEvents', 'EventManager.beforeHooks', + 'EventManager.afterHooks', 'EventManager.beforeRegularEvents', + 'EventManager.afterRegularEvents' + ); + + $empty_cache = Array (); + + foreach ($cache_keys as $cache_key) { + $empty_cache[$cache_key] = Array (); + } + + $this->Application->Factory->setFromCache($empty_cache); + $this->Application->EventManager->setFromCache($empty_cache); + + // otherwise ModulesHelper indirectly used from includeConfigFiles won't work + $this->Application->RegisterDefaultClasses(); + } + + /** * Updates data, that was parsed from unit configs this time * * @access public @@ -256,6 +291,32 @@ } } + public function delayUnitProcessing($method, $params) + { + if ($this->Application->InitDone) { + // init already done -> call immediately (happens during installation) + $function = Array (&$this->Application, $method); + call_user_func_array($function, $params); + + return ; + } + + $this->temporaryCache[$method][] = $params; + } + + public function applyDelayedUnitProcessing() + { + foreach ($this->temporaryCache as $method => $method_calls) { + $function = Array (&$this->Application, $method); + + foreach ($method_calls as $method_call) { + call_user_func_array($function, $method_call); + } + + $this->temporaryCache[$method] = Array (); + } + } + /** * Deletes all data, that was cached during unit config parsing (including unit config locations) * Index: branches/5.2.x/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -r14244 -r14428 --- branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 14244) +++ branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 14428) @@ -1,6 +1,6 @@ StoreCache = $cache; + + if (!$this->Application->InitDone) { + // scanModules is called multiple times during installation process + $this->Application->InitManagers(); + } + + $this->Application->cacheManager->applyDelayedUnitProcessing(); } function findConfigFiles($folderPath, $level = 0) @@ -316,19 +323,8 @@ */ function ReReadConfigs() { - // clear restored cache (not in db) - $this->Application->Factory->Files = Array (); - $this->Application->Factory->realClasses = Array (); - $this->Application->Factory->Dependencies = Array (); + $this->Application->cacheManager->EmptyUnitCache(); - $this->Application->EventManager->beforeRegularEvents = Array (); - $this->Application->EventManager->afterRegularEvents = Array (); - $this->Application->EventManager->beforeHooks = Array (); - $this->Application->EventManager->afterHooks = Array (); - - // otherwise ModulesHelper indirectly used from includeConfigFiles won't work - $this->Application->RegisterDefaultClasses(); - // parse all configs $this->ProcessAllConfigs = true; $this->AfterConfigProcessed = Array (); @@ -350,11 +346,15 @@ $new_clones = Array(); foreach ($this->configData as $prefix => $config) { $clones = $this->postProcessConfig($prefix, 'Clones', 'prefix'); + if ($clones) { $new_clones = array_merge($new_clones, $clones); } } + // execute delayed methods for cloned unit configs + $this->Application->cacheManager->applyDelayedUnitProcessing(); + // call OnAfterConfigRead for cloned configs $new_clones = array_unique($new_clones); foreach ($new_clones as $prefix) { @@ -439,7 +439,7 @@ ); if ( isset($class_info['build_event']) && $class_info['build_event'] ) { - $this->Application->EventManager->registerBuildEvent($class_info['pseudo'], $class_info['build_event']); + $this->Application->delayUnitProcessing('registerBuildEvent', Array ($class_info['pseudo'], $class_info['build_event'])); } } } @@ -456,7 +456,7 @@ foreach ($regular_events as $short_name => $regular_event_info) { $event_status = array_key_exists('Status', $regular_event_info) ? $regular_event_info['Status'] : STATUS_ACTIVE; - $this->Application->EventManager->registerAgent( $short_name, $config['Prefix'] . ':' . $regular_event_info['EventName'], $regular_event_info['RunInterval'], $regular_event_info['Type'], $event_status ); + $this->Application->delayUnitProcessing('registerAgent', Array ( $short_name, $config['Prefix'] . ':' . $regular_event_info['EventName'], $regular_event_info['RunInterval'], $regular_event_info['Type'], $event_status )); } } @@ -502,7 +502,7 @@ $hook_event = $hook['HookToPrefix'] . '.' . $hook['HookToSpecial'] . ':' . $hook_event; $do_event = $do_prefix . '.' . $hook['DoSpecial'] . ':' . $hook['DoEvent']; - $this->Application->registerHook($hook_event, $do_event, $hook['Mode'], $hook['Conditional']); + $this->Application->delayUnitProcessing('registerHook', Array ($hook_event, $do_event, $hook['Mode'], $hook['Conditional'])); } } } @@ -524,7 +524,7 @@ } $aggregate_tag['LocalPrefix'] = $config['Prefix']; - $this->Application->registerAggregateTag($aggregate_tag); + $this->Application->delayUnitProcessing('registerAggregateTag', Array ($aggregate_tag)); } } Index: branches/5.2.x/core/install.php =================================================================== diff -u -r14244 -r14428 --- branches/5.2.x/core/install.php (.../install.php) (revision 14244) +++ branches/5.2.x/core/install.php (.../install.php) (revision 14428) @@ -1,6 +1,6 @@ toolkit = new kInstallToolkit(); Index: branches/5.2.x/core/kernel/constants.php =================================================================== diff -u -r14244 -r14428 --- branches/5.2.x/core/kernel/constants.php (.../constants.php) (revision 14244) +++ branches/5.2.x/core/kernel/constants.php (.../constants.php) (revision 14428) @@ -1,6 +1,6 @@ Conn = new kDBConnection(SQL_TYPE, Array(&$this, 'handleSQLError') ); - $this->Conn->debugMode = $this->isDebugMode(); - $this->Conn->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB); - $this->Factory = new kFactory(); $this->registerDefaultClasses(); - $this->Phrases = new PhrasesCache(); + $this->Conn =& $this->Factory->makeClass( 'kDBConnection', Array (SQL_TYPE, Array (&$this, 'handleSQLError')) ); + $this->Conn->debugMode = $this->isDebugMode(); + $this->Conn->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB); + $this->cacheManager =& $this->makeClass('kCacheManager'); $this->cacheManager->InitCache(); - $this->UrlManager =& $this->makeClass('kUrlManager'); - $this->EventManager =& $this->makeClass('EventManager'); - $this->Factory->Storage['EventManager'] =& $this->EventManager; - $this->RegisterDefaultBuildEvents(); - if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->appendTimestamp('Before UnitConfigReader'); } - $this->UnitConfigReader =& $this->recallObject('kUnitConfigReader'); + $this->UnitConfigReader =& $this->makeClass('kUnitConfigReader'); $this->UnitConfigReader->scanModules(MODULES_PATH); $this->registerModuleConstants(); @@ -409,6 +406,20 @@ return true; } + function InitManagers() + { + if ($this->InitDone) { + throw new Exception('Duplicate call of ' . __METHOD__, E_USER_ERROR); + return ; + } + + $this->UrlManager =& $this->makeClass('kUrlManager'); + $this->EventManager =& $this->makeClass('EventManager'); + $this->Phrases =& $this->makeClass('kPhraseCache'); + + $this->RegisterDefaultBuildEvents(); + } + /** * Returns module information. Searches module by requested field * @@ -442,7 +453,7 @@ return false; } - $modules_helper =& $this->recallObject('ModulesHelper'); + $modules_helper =& $this->makeClass('ModulesHelper'); /* @var $modules_helper kModulesHelper */ $this->Conn->nextQueryCachable = true; @@ -662,55 +673,55 @@ */ function RegisterDefaultClasses() { + $this->registerClass('kHelper', KERNEL_PATH . '/kbase.php'); + $this->registerClass('kMultipleFilter', KERNEL_PATH . '/utility/filters.php'); $this->registerClass('kiCacheable', KERNEL_PATH . '/interfaces/cacheable.php', 'kiCacheable'); - $this->registerClass('kTempTablesHandler', KERNEL_PATH . '/utility/temp_handler.php'); - $this->registerClass('kEventManager', KERNEL_PATH . '/event_manager.php', 'EventManager', 'kiCacheable'); $this->registerClass('kHookManager', KERNEL_PATH . '/managers/hook_manager.php', null, 'kiCacheable'); $this->registerClass('kAgentManager', KERNEL_PATH . '/managers/agent_manager.php', null, 'kiCacheable'); $this->registerClass('kRequestManager', KERNEL_PATH . '/managers/request_manager.php'); $this->registerClass('kUrlManager', KERNEL_PATH . '/managers/url_manager.php'); $this->registerClass('kCacheManager', KERNEL_PATH . '/managers/cache_manager.php', null, 'kiCacheable'); + $this->registerClass('PhrasesCache', KERNEL_PATH . '/languages/phrases_cache.php', 'kPhraseCache'); + $this->registerClass('kTempTablesHandler', KERNEL_PATH . '/utility/temp_handler.php'); $this->registerClass('kUnitConfigReader', KERNEL_PATH . '/utility/unit_config_reader.php'); + // Params class descendants $this->registerClass('kArray', KERNEL_PATH . '/utility/params.php'); $this->registerClass('Params', KERNEL_PATH . '/utility/params.php'); $this->registerClass('Params', KERNEL_PATH . '/utility/params.php', 'kActions'); $this->registerClass('kCache', KERNEL_PATH . '/utility/cache.php', 'kCache', 'Params'); $this->registerClass('kHTTPQuery', KERNEL_PATH . '/utility/http_query.php', 'HTTPQuery', 'Params'); - $this->registerClass('kHelper', KERNEL_PATH . '/kbase.php'); - $this->registerClass('kMultipleFilter', KERNEL_PATH . '/utility/filters.php'); - + // session $this->registerClass('Session', KERNEL_PATH . '/session/session.php'); $this->registerClass('SessionStorage', KERNEL_PATH . '/session/session_storage.php'); $this->registerClass('InpSession', KERNEL_PATH . '/session/inp_session.php', 'Session'); $this->registerClass('InpSessionStorage', KERNEL_PATH . '/session/inp_session_storage.php', 'SessionStorage'); + // template parser $this->registerClass('kTagProcessor', KERNEL_PATH . '/processors/tag_processor.php'); - $this->registerClass('kMainTagProcessor', KERNEL_PATH . '/processors/main_processor.php','m_TagProcessor', 'kTagProcessor'); - - $this->registerClass('kDBList', KERNEL_PATH . '/db/dblist.php'); - $this->registerClass('kDBItem', KERNEL_PATH . '/db/dbitem.php'); - $this->registerClass('kDBEventHandler', KERNEL_PATH . '/db/db_event_handler.php'); + $this->registerClass('kMainTagProcessor', KERNEL_PATH . '/processors/main_processor.php', 'm_TagProcessor', 'kTagProcessor'); $this->registerClass('kDBTagProcessor', KERNEL_PATH . '/db/db_tag_processor.php', null, 'kTagProcessor'); - $this->registerClass('kCatDBItem', KERNEL_PATH . '/db/cat_dbitem.php'); - $this->registerClass('kCatDBList', KERNEL_PATH . '/db/cat_dblist.php'); - $this->registerClass('kCatDBEventHandler', KERNEL_PATH . '/db/cat_event_handler.php'); - $this->registerClass('kCatDBTagProcessor', KERNEL_PATH . '/db/cat_tag_processor.php'); - + $this->registerClass('kCatDBTagProcessor', KERNEL_PATH . '/db/cat_tag_processor.php', null, 'kDBTagProcessor'); $this->registerClass('NParser', KERNEL_PATH . '/nparser/nparser.php'); $this->registerClass('TemplatesCache', KERNEL_PATH . '/nparser/template_cache.php', null, Array ('kHelper', 'kDBTagProcessor')); + // database + $this->registerClass('kDBConnection', KERNEL_PATH . '/db/db_connection.php'); + $this->registerClass('kDBItem', KERNEL_PATH . '/db/dbitem.php'); + $this->registerClass('kCatDBItem', KERNEL_PATH . '/db/cat_dbitem.php', null, 'kDBItem'); + $this->registerClass('kDBList', KERNEL_PATH . '/db/dblist.php'); + $this->registerClass('kCatDBList', KERNEL_PATH . '/db/cat_dblist.php', null, 'kDBList'); + $this->registerClass('kDBEventHandler', KERNEL_PATH . '/db/db_event_handler.php'); + $this->registerClass('kCatDBEventHandler', KERNEL_PATH . '/db/cat_event_handler.php', null, 'kDBEventHandler'); + + // email sending $this->registerClass('kEmailSendingHelper', KERNEL_PATH . '/utility/email_send.php', 'EmailSender', 'kHelper'); $this->registerClass('kSocket', KERNEL_PATH . '/utility/socket.php', 'Socket'); - if ( file_exists(MODULES_PATH . '/in-commerce/units/currencies/currency_rates.php') ) { - $this->registerClass('kCurrencyRates', MODULES_PATH . '/in-commerce/units/currencies/currency_rates.php'); - } - // do not move to config - this helper is used before configs are read $this->registerClass('kModulesHelper', KERNEL_PATH . '/../units/helpers/modules_helper.php', 'ModulesHelper'); } @@ -1628,10 +1639,6 @@ $event = new kEvent($params, $specific_params); } - if ( !isset($this->EventManager) ) { - $this->EventManager =& $this->recallObject('EventManager'); - } - $this->EventManager->HandleEvent($event); } @@ -1675,8 +1682,25 @@ } /** + * Add new agent + * + * @param string $short_name name to be used to store last maintenace run info + * @param string $event_name + * @param int $run_interval run interval in seconds + * @param int $type before or after agent + * @param int $status + * @access public + */ + public function registerAgent($short_name, $event_name, $run_interval, $type = reBEFORE, $status = STATUS_ACTIVE) + { + $this->EventManager->registerAgent($short_name, $event_name, $run_interval, $type, $status); + } + + /** * Registers Hook from subprefix event to master prefix event * + * Pattern: Observer + * * @param string $hook_event * @param string $do_event * @param int $mode @@ -1689,6 +1713,18 @@ } /** + * Registers build event for given pseudo class + * + * @param string $pseudo_class + * @param string $event_name + * @access public + */ + public function registerBuildEvent($pseudo_class, $event_name) + { + $this->EventManager->registerBuildEvent($pseudo_class, $event_name); + } + + /** * Allows one TagProcessor tag act as other TagProcessor tag * * @param Array $tag_info @@ -1697,7 +1733,15 @@ function registerAggregateTag($tag_info) { $aggregator =& $this->recallObject('TagsAggregator', 'kArray'); - $aggregator->SetArrayValue($tag_info['AggregateTo'], $tag_info['AggregatedTagName'], Array($tag_info['LocalPrefix'], $tag_info['LocalTagName'], getArrayValue($tag_info, 'LocalSpecial'))); + /* @var $aggregator kArray */ + + $tag_data = Array( + $tag_info['LocalPrefix'], + $tag_info['LocalTagName'], + getArrayValue($tag_info, 'LocalSpecial') + ); + + $aggregator->SetArrayValue($tag_info['AggregateTo'], $tag_info['AggregatedTagName'], $tag_data); } /** @@ -1756,6 +1800,8 @@ /** * Get's real class name for pseudo class, includes class file and creates class instance * + * Pattern: Factory Method + * * @param string $pseudo_class * @param Array $arguments * @return kBase @@ -2520,4 +2566,9 @@ 'Application.ModuleInfo' => $this->ModuleInfo, ); } + + public function delayUnitProcessing($method, $params) + { + $this->cacheManager->delayUnitProcessing($method, $params); + } } \ No newline at end of file Index: branches/5.2.x/core/kernel/managers/agent_manager.php =================================================================== diff -u -r14244 -r14428 --- branches/5.2.x/core/kernel/managers/agent_manager.php (.../agent_manager.php) (revision 14244) +++ branches/5.2.x/core/kernel/managers/agent_manager.php (.../agent_manager.php) (revision 14428) @@ -1,6 +1,6 @@ dbType = $dbType; // $this->initMetaFunctions(); if (!$errorHandler) { @@ -148,11 +145,6 @@ } $this->_captureStatistics = defined('DBG_CAPTURE_STATISTICS') && DBG_CAPTURE_STATISTICS && !(defined('ADMIN') && ADMIN); - - if (class_exists('kApplication')) { - // prevents "Fatal Error" on 2nd installation step (when database is empty) - $this->Application =& kApplication::Instance(); - } } /** Index: branches/5.2.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -r14244 -r14428 --- branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14244) +++ branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14428) @@ -1,6 +1,6 @@ Application, 'handleSQLError') ); + $connection =& $this->Application->makeClass( 'kDBConnection', Array (SQL_TYPE, Array (&$this->Application, 'handleSQLError')) ); $connection->debugMode = $this->Application->isDebugMode(); $connection->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB, true); } Index: branches/5.2.x/core/kernel/event_manager.php =================================================================== diff -u -r14244 -r14428 --- branches/5.2.x/core/kernel/event_manager.php (.../event_manager.php) (revision 14244) +++ branches/5.2.x/core/kernel/event_manager.php (.../event_manager.php) (revision 14428) @@ -1,6 +1,6 @@