Index: branches/5.3.x/core/kernel/utility/unit_config.php
===================================================================
diff -u -r15698 -r15732
--- branches/5.3.x/core/kernel/utility/unit_config.php (.../unit_config.php) (revision 15698)
+++ branches/5.3.x/core/kernel/utility/unit_config.php (.../unit_config.php) (revision 15732)
@@ -324,6 +324,22 @@
class kUnitConfig {
/**
+ * Reference to global kApplication instance
+ *
+ * @var kApplication
+ * @access protected
+ */
+ protected $Application = null;
+
+ /**
+ * Connection to database
+ *
+ * @var kDBConnection
+ * @access protected
+ */
+ protected $Conn = null;
+
+ /**
* Unit config prefix
*
* @var string
@@ -332,6 +348,14 @@
protected $_prefix = '';
/**
+ * Filename, where unit config is stored
+ *
+ * @var string
+ * @access protected
+ */
+ protected $_filename = '';
+
+ /**
* Default unit config data
*
* @var Array
@@ -435,9 +459,24 @@
$merge_with = $use_global_defaults ? self::$_defaults : Array ();
$this->_data = array_merge($merge_with, isset($defaults) ? $defaults : Array ());
+
+ $this->Application =& kApplication::Instance();
+ $this->Conn =& $this->Application->GetADODBConnection();
}
/**
+ * Sets filename, where unit config is stored
+ *
+ * @param string $filename
+ * @return void
+ * @access public
+ */
+ public function setFilename($filename)
+ {
+ $this->_filename = $filename;
+ }
+
+ /**
* Returns unit config prefix
*
* @return string
@@ -456,7 +495,7 @@
*/
public function __sleep()
{
- return Array ('_prefix', '_data');
+ return Array ('_prefix', '_data', 'Application', 'Conn');
}
/**
@@ -1026,4 +1065,316 @@
return $first_only ? $value[0] : $value;
}
+
+ /**
+ * Register necessary classes
+ * This method should only process the data which is cached!
+ *
+ * @return void
+ * @access public
+ */
+ public function parse()
+ {
+ $this->_parseClasses();
+ $this->_parseScheduledTasks();
+ $this->_parseHooks();
+ $this->_parseAggregatedTags();
+ }
+
+ protected function _parseClasses()
+ {
+ $register_classes = $this->_getClasses();
+
+ foreach ($register_classes as $class_info) {
+ $this->Application->registerClass(
+ $class_info['class'],
+ $this->getBasePath() . DIRECTORY_SEPARATOR . $class_info['file'],
+ $class_info['pseudo']
+ );
+
+ if ( isset($class_info['build_event']) && $class_info['build_event'] && $class_info['build_event'] != 'OnBuild' ) {
+ $this->Application->delayUnitProcessing('registerBuildEvent', Array ($class_info['pseudo'], $class_info['build_event']));
+ }
+ }
+ }
+
+ protected function _getClasses()
+ {
+ $register_classes = $this->getRegisterClasses();
+ $class_params = Array ('ItemClass', 'ListClass', 'EventHandlerClass', 'TagProcessorClass');
+
+ foreach ($class_params as $param_name) {
+ $value = $this->getSetting($param_name);
+
+ if ( !$value ) {
+ continue;
+ }
+
+ $value['pseudo'] = $this->_getPseudoByOptionName($param_name);
+ $this->setSetting($param_name, $value);
+
+ $register_classes[] = $value;
+ }
+
+ return $register_classes;
+ }
+
+ protected function _getPseudoByOptionName($option_name)
+ {
+ $pseudo_class_map = Array (
+ 'ItemClass' => '%s',
+ 'ListClass' => '%s_List',
+ 'EventHandlerClass' => '%s_EventHandler',
+ 'TagProcessorClass' => '%s_TagProcessor'
+ );
+
+ return sprintf($pseudo_class_map[$option_name], $this->_prefix);
+ }
+
+ protected function _parseScheduledTasks()
+ {
+ if ( !$this->getScheduledTasks() ) {
+ return ;
+ }
+
+ $scheduled_tasks = $this->getScheduledTasks();
+
+ foreach ($scheduled_tasks as $short_name => $scheduled_task_info) {
+ $event_status = array_key_exists('Status', $scheduled_task_info) ? $scheduled_task_info['Status'] : STATUS_ACTIVE;
+ $this->Application->delayUnitProcessing('registerScheduledTask', Array ($short_name, $this->_prefix . ':' . $scheduled_task_info['EventName'], $scheduled_task_info['RunSchedule'], $event_status));
+ }
+ }
+
+ protected function _parseHooks()
+ {
+ $hooks = $this->getHooks();
+
+ if ( !$hooks ) {
+ return;
+ }
+
+ foreach ($hooks as $hook) {
+ if ( $this->getParentPrefix() && ($hook['HookToPrefix'] == $this->getParentPrefix()) ) {
+ trigger_error('Deprecated Hook Usage [prefix: ' . $this->_prefix . '; do_prefix: ' . $hook['DoPrefix'] . '] use #PARENT# as HookToPrefix value, where HookToPrefix is same as ParentPrefix', defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_NOTICE);
+ }
+
+ if ( $hook['HookToPrefix'] == '' ) {
+ // new: set hooktoprefix to current prefix if not set
+ $hook['HookToPrefix'] = $this->_prefix;
+ }
+
+ if ( $this->getParentPrefix() ) {
+ // new: allow to set hook to parent prefix what ever it is
+ if ( $hook['HookToPrefix'] == '#PARENT#' ) {
+ $hook['HookToPrefix'] = $this->getParentPrefix();
+ }
+
+ if ( $hook['DoPrefix'] == '#PARENT#' ) {
+ $hook['DoPrefix'] = $this->getParentPrefix();
+ }
+ }
+ elseif ( $hook['HookToPrefix'] == '#PARENT#' || $hook['DoPrefix'] == '#PARENT#' ) {
+ // we need parent prefix but it's not set !
+ continue;
+ }
+
+ $hook_events = (array)$hook['HookToEvent'];
+ $do_prefix = $hook['DoPrefix'] == '' ? $this->_prefix : $hook['DoPrefix'];
+
+ foreach ($hook_events as $hook_event) {
+ $hook_event = $hook['HookToPrefix'] . '.' . $hook['HookToSpecial'] . ':' . $hook_event;
+ $do_event = $do_prefix . '.' . $hook['DoSpecial'] . ':' . $hook['DoEvent'];
+
+ $this->Application->delayUnitProcessing('registerHook', Array ($hook_event, $do_event, $hook['Mode'], $hook['Conditional']));
+ }
+ }
+ }
+
+ protected function _parseAggregatedTags()
+ {
+ $aggregated_tags = $this->getAggregateTags();
+
+ if ( !$aggregated_tags ) {
+ return;
+ }
+
+ foreach ($aggregated_tags as $aggregate_tag) {
+ if ( $this->getParentPrefix() ) {
+ if ( $aggregate_tag['AggregateTo'] == $this->getParentPrefix() ) {
+ trigger_error('Deprecated Aggregate Tag Usage [prefix: ' . $this->_prefix . '; AggregateTo: ' . $aggregate_tag['AggregateTo'] . '] use #PARENT# as AggregateTo value, where AggregateTo is same as ParentPrefix', defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_NOTICE);
+ }
+
+ if ( $aggregate_tag['AggregateTo'] == '#PARENT#' ) {
+ $aggregate_tag['AggregateTo'] = $this->getParentPrefix();
+ }
+ }
+
+ $aggregate_tag['LocalPrefix'] = $this->_prefix;
+ $this->Application->delayUnitProcessing('registerAggregateTag', Array ($aggregate_tag));
+ }
+ }
+
+ public function validate()
+ {
+ global $debugger;
+
+ $table_name = $this->getTableName();
+ $float_types = Array ('float', 'double', 'numeric');
+
+ $table_found = $this->Conn->Query('SHOW TABLES LIKE "' . $table_name . '"');
+
+ if ( !$table_found ) {
+ // config present, but table missing, strange
+ kUtil::safeDefine('DBG_RAISE_ON_WARNINGS', 1);
+ $debugger->appendHTML("Config Warning: Table $table_name missing, but prefix " . $this->_prefix . " requires it!");
+ $debugger->WarningCount++;
+
+ return;
+ }
+
+ $res = $this->Conn->Query('DESCRIBE ' . $table_name);
+ $config_link = $debugger->getFileLink(FULL_PATH . $this->_filename, 1, $this->_prefix);
+
+ $error_messages = Array (
+ 'field_not_found' => 'Field %s exists in the database, but is not defined in config',
+ 'default_missing' => 'Default value for field %s not set in config',
+ 'not_null_error1' => 'Field %s is NOT NULL in the database, but is not configured as not_null', // or required',
+ 'not_null_error2' => 'Field %s is described as NOT NULL in config, but does not have DEFAULT value',
+ 'not_null_error3' => 'Field %s is described as NOT NULL in config, but is NULL in db',
+ 'invalid_default' => 'Default value for field %s%s not sync. to db (in config = %s, in db = %s)',
+ 'date_column_not_null_error' => 'Field %s must be NULL in config and database, since it contains date',
+ 'user_column_default_error' => 'Field %s must be have NULL as default value, since it holds user id',
+ 'type_missing' => 'Type definition for field %s missing in config',
+ 'virtual_type_missing' => 'Type definition for virtual field %s missing in config',
+ 'virtual_default_missing' => 'Default value for virtual field %s not set in config',
+ 'virtual_not_null_error' => 'Virtual field %s cannot be not null, since it doesn\'t exist in database',
+ 'invalid_calculated_field' => 'Calculated field %s is missing corresponding virtual field',
+ );
+
+ $config_errors = Array ();
+ $fields = $this->getFields();
+ $table_name = preg_replace('/^' . preg_quote(TABLE_PREFIX, '/') . '(.*)/', '\\1', $table_name); // remove table prefix
+
+ if ( $fields ) {
+ // validate unit config field declaration in relation to database table structure
+ foreach ($res as $field) {
+ $f_name = $field['Field'];
+
+ if ( preg_match('/l[\d]+_[\w]/', $f_name) ) {
+ // skip multilingual fields
+ continue;
+ }
+
+ if ( !array_key_exists($f_name, $fields) ) {
+ $config_errors[] = sprintf($error_messages['field_not_found'], $f_name);
+ }
+ else {
+ $db_default = $field['Default'];
+
+ if ( is_numeric($db_default) ) {
+ $db_default = preg_match('/[\.,]/', $db_default) ? (float)$db_default : (int)$db_default;
+ }
+
+ $default_missing = false;
+ $options = $fields[$f_name];
+ $not_null = isset($options['not_null']) && $options['not_null'];
+ $formatter = array_key_exists('formatter', $options) ? $options['formatter'] : false;
+
+ if ( !array_key_exists('default', $options) ) {
+ $config_errors[] = sprintf($error_messages['default_missing'], $f_name);
+ $default_missing = true;
+ }
+
+ if ( $field['Null'] != 'YES' ) {
+ // field is NOT NULL in database (MySQL5 for null returns "NO", but MySQL4 returns "")
+ if ( $f_name != $this->getIDField() && !isset($options['not_null']) /*&& !isset($options['required'])*/ ) {
+ $config_errors[] = sprintf($error_messages['not_null_error1'], $f_name);
+ }
+ if ( $not_null && !isset($options['default']) ) {
+ $config_errors[] = sprintf($error_messages['not_null_error2'], $f_name);
+ }
+ }
+ elseif ( $not_null ) {
+ $config_errors[] = sprintf($error_messages['not_null_error3'], $f_name);
+ }
+
+ if ( ($formatter == 'kDateFormatter') && $not_null ) {
+ $config_errors[] = sprintf($error_messages['date_column_not_null_error'], $f_name);
+ }
+
+ // columns, holding userid should have NULL as default value
+ if ( array_key_exists('type', $options) && !$default_missing ) {
+ // both type and default value set
+
+ if ( preg_match('/ById$/', $f_name) && $options['default'] !== null ) {
+ $config_errors[] = sprintf($error_messages['user_column_default_error'], $f_name);
+ }
+ }
+
+ if ( !array_key_exists('type', $options) ) {
+ $config_errors[] = sprintf($error_messages['type_missing'], $f_name);
+ }
+
+ if ( !$default_missing && ($field['Type'] != 'text') ) {
+ if ( is_null($db_default) && $not_null ) {
+ $db_default = $options['type'] == 'string' ? '' : 0;
+ }
+
+ if ( $f_name == $this->getIDField() && $options['type'] != 'string' && $options['default'] !== 0 ) {
+ $config_errors[] = sprintf($error_messages['invalid_default'], 'IDField ', $f_name, $this->_varDump($options['default']), $this->_varDump($field['Default']));
+ }
+ else if ( ((string)$options['default'] != '#NOW#') && ($db_default !== $options['default']) && !in_array($options['type'], $float_types) ) {
+ $config_errors[] = sprintf($error_messages['invalid_default'], '', $f_name, $this->_varDump($options['default']), $this->_varDump($db_default));
+ }
+ }
+ }
+ }
+ }
+
+ // validate virtual fields
+ $virtual_fields = $this->getVirtualFields();
+
+ if ( $virtual_fields ) {
+ foreach ($virtual_fields as $f_name => $options) {
+ if ( !array_key_exists('type', $options) ) {
+ $config_errors[] = sprintf($error_messages['virtual_type_missing'], $f_name);
+ }
+
+ if ( array_key_exists('not_null', $options) ) {
+ $config_errors[] = sprintf($error_messages['virtual_not_null_error'], $f_name);
+ }
+
+ if ( !array_key_exists('default', $options) ) {
+ $config_errors[] = sprintf($error_messages['virtual_default_missing'], $f_name);
+ }
+ }
+ }
+
+ // validate calculated fields
+ if ( $this->getCalculatedFieldSpecials() ) {
+ foreach ($this->getCalculatedFieldSpecials() as $special) {
+ foreach ($this->getCalculatedFieldsBySpecial($special) as $calculated_field => $calculated_field_expr) {
+ if ( !isset($virtual_fields[$calculated_field]) ) {
+ $config_errors[] = sprintf($error_messages['invalid_calculated_field'], $calculated_field);
+ }
+ }
+ }
+
+ $config_errors = array_unique($config_errors);
+ }
+
+ if ( $config_errors ) {
+ $error_prefix = 'Config Error' . (count($config_errors) > 1 ? 's' : '') . ': for prefix ' . $config_link . ' (' . $table_name . ') in unit config:
';
+ $config_errors = $error_prefix . ' ' . implode('
', $config_errors);
+
+ kUtil::safeDefine('DBG_RAISE_ON_WARNINGS', 1);
+ $debugger->appendHTML($config_errors);
+ $debugger->WarningCount++;
+ }
+ }
+
+ protected function _varDump($value)
+ {
+ return '' . var_export($value, true) . ' of ' . gettype($value);
+ }
}
Index: branches/5.3.x/core/kernel/utility/unit_config_reader.php
===================================================================
diff -u -r15698 -r15732
--- branches/5.3.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 15698)
+++ branches/5.3.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 15732)
@@ -1,6 +1,6 @@
parseConfig($prefix);
+ $config->parse();
}
foreach ($this->configData as $prefix => $config) {
@@ -249,8 +249,9 @@
// 2. process prioritized configs
asort($prioritized_configs);
+
foreach ($prioritized_configs as $prefix => $priority) {
- $this->parseConfig($prefix);
+ $this->configData[$prefix]->parse();
}
}
@@ -287,7 +288,7 @@
continue;
}
- $this->ValidateConfig($prefix);
+ $config->validate();
}
}
}
@@ -403,292 +404,6 @@
}
}
- /**
- * Register nessasary classes
- * This method should only process the data which is cached!
- *
- * @param string $prefix
- * @access private
- */
- function parseConfig($prefix)
- {
- $this->parseClasses($prefix);
- $this->parseScheduledTasks($prefix);
- $this->parseHooks($prefix);
- $this->parseAggregatedTags($prefix);
- }
-
- protected function parseClasses($prefix)
- {
- $config = $this->configData[$prefix];
- $register_classes = $this->getClasses($prefix);
-
- foreach ($register_classes as $class_info) {
- $this->Application->registerClass(
- $class_info['class'],
- $config->getBasePath() . DIRECTORY_SEPARATOR . $class_info['file'],
- $class_info['pseudo']
- );
-
- if ( isset($class_info['build_event']) && $class_info['build_event'] ) {
- $this->Application->delayUnitProcessing('registerBuildEvent', Array ($class_info['pseudo'], $class_info['build_event']));
- }
- }
- }
-
- protected function parseScheduledTasks($prefix)
- {
- $config = $this->configData[$prefix];
-
- if ( !$config->getScheduledTasks() ) {
- return ;
- }
-
- $scheduled_tasks = $config->getScheduledTasks();
-
- foreach ($scheduled_tasks as $short_name => $scheduled_task_info) {
- $event_status = array_key_exists('Status', $scheduled_task_info) ? $scheduled_task_info['Status'] : STATUS_ACTIVE;
- $this->Application->delayUnitProcessing('registerScheduledTask', Array ( $short_name, $config->getPrefix() . ':' . $scheduled_task_info['EventName'], $scheduled_task_info['RunSchedule'], $event_status ));
- }
- }
-
- protected function parseHooks($prefix)
- {
- $config = $this->configData[$prefix];
-
- if ( !$config->getHooks() ) {
- return;
- }
-
- $hooks = $config->getHooks();
-
- foreach ($hooks as $hook) {
- if ( $config->getParentPrefix() && ($hook['HookToPrefix'] == $config->getParentPrefix()) ) {
- trigger_error('Deprecated Hook Usage [prefix: ' . $config->getPrefix() . '; do_prefix: ' . $hook['DoPrefix'] . '] use #PARENT# as HookToPrefix value, where HookToPrefix is same as ParentPrefix', defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_NOTICE);
- }
-
- if ( $hook['HookToPrefix'] == '' ) {
- // new: set hooktoprefix to current prefix if not set
- $hook['HookToPrefix'] = $config->getPrefix();
- }
-
- if ( $config->getParentPrefix() ) {
- // new: allow to set hook to parent prefix what ever it is
- if ( $hook['HookToPrefix'] == '#PARENT#' ) {
- $hook['HookToPrefix'] = $config->getParentPrefix();
- }
-
- if ( $hook['DoPrefix'] == '#PARENT#' ) {
- $hook['DoPrefix'] = $config->getParentPrefix();
- }
- }
- elseif ( $hook['HookToPrefix'] == '#PARENT#' || $hook['DoPrefix'] == '#PARENT#' ) {
- // we need parent prefix but it's not set !
- continue;
- }
-
- $hook_events = (array)$hook['HookToEvent'];
- $do_prefix = $hook['DoPrefix'] == '' ? $config->getPrefix() : $hook['DoPrefix'];
-
- foreach ($hook_events as $hook_event) {
- $hook_event = $hook['HookToPrefix'] . '.' . $hook['HookToSpecial'] . ':' . $hook_event;
- $do_event = $do_prefix . '.' . $hook['DoSpecial'] . ':' . $hook['DoEvent'];
-
- $this->Application->delayUnitProcessing('registerHook', Array ($hook_event, $do_event, $hook['Mode'], $hook['Conditional']));
- }
- }
- }
-
- protected function parseAggregatedTags($prefix)
- {
- $config = $this->configData[$prefix];
- $aggregated_tags = $config->getAggregateTags();
-
- if ( !$aggregated_tags ) {
- return;
- }
-
- foreach ($aggregated_tags as $aggregate_tag) {
- if ( $config->getParentPrefix() ) {
- if ( $aggregate_tag['AggregateTo'] == $config->getParentPrefix() ) {
- trigger_error('Deprecated Aggregate Tag Usage [prefix: ' . $config->getPrefix() . '; AggregateTo: ' . $aggregate_tag['AggregateTo'] . '] use #PARENT# as AggregateTo value, where AggregateTo is same as ParentPrefix', defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_NOTICE);
- }
-
- if ( $aggregate_tag['AggregateTo'] == '#PARENT#' ) {
- $aggregate_tag['AggregateTo'] = $config->getParentPrefix();
- }
- }
-
- $aggregate_tag['LocalPrefix'] = $config->getPrefix();
- $this->Application->delayUnitProcessing('registerAggregateTag', Array ($aggregate_tag));
- }
- }
-
- function ValidateConfig($prefix)
- {
- global $debugger;
-
- $config = $this->configData[$prefix];
-
- $table_name = $config->getTableName();
- $float_types = Array ('float', 'double', 'numeric');
-
- $table_found = $this->Conn->Query('SHOW TABLES LIKE "' . $table_name . '"');
- if ( !$table_found ) {
- // config present, but table missing, strange
- kUtil::safeDefine('DBG_RAISE_ON_WARNINGS', 1);
- $debugger->appendHTML("Config Warning: Table $table_name missing, but prefix " . $prefix . " requires it!");
- $debugger->WarningCount++;
-
- return;
- }
-
- $res = $this->Conn->Query('DESCRIBE ' . $table_name);
- $config_link = $debugger->getFileLink(FULL_PATH . $this->prefixFiles[$prefix], 1, $prefix);
-
- $error_messages = Array (
- 'field_not_found' => 'Field %s exists in the database, but is not defined in config',
- 'default_missing' => 'Default value for field %s not set in config',
- 'not_null_error1' => 'Field %s is NOT NULL in the database, but is not configured as not_null', // or required',
- 'not_null_error2' => 'Field %s is described as NOT NULL in config, but does not have DEFAULT value',
- 'not_null_error3' => 'Field %s is described as NOT NULL in config, but is NULL in db',
- 'invalid_default' => 'Default value for field %s%s not sync. to db (in config = %s, in db = %s)',
- 'date_column_not_null_error' => 'Field %s must be NULL in config and database, since it contains date',
- 'user_column_default_error' => 'Field %s must be have NULL as default value, since it holds user id',
- 'type_missing' => 'Type definition for field %s missing in config',
- 'virtual_type_missing' => 'Type definition for virtual field %s missing in config',
- 'virtual_default_missing' => 'Default value for virtual field %s not set in config',
- 'virtual_not_null_error' => 'Virtual field %s cannot be not null, since it doesn\'t exist in database',
- 'invalid_calculated_field' => 'Calculated field %s is missing corresponding virtual field',
- );
-
- $config_errors = Array ();
- $fields = $config->getFields();
- $table_name = preg_replace('/^' . preg_quote(TABLE_PREFIX, '/') . '(.*)/', '\\1', $table_name); // remove table prefix
-
- if ( $fields ) {
- // validate unit config field declaration in relation to database table structure
- foreach ($res as $field) {
- $f_name = $field['Field'];
-
- if ( preg_match('/l[\d]+_[\w]/', $f_name) ) {
- // skip multilingual fields
- continue;
- }
-
- if ( !array_key_exists($f_name, $fields) ) {
- $config_errors[] = sprintf($error_messages['field_not_found'], $f_name);
- }
- else {
- $db_default = $field['Default'];
-
- if ( is_numeric($db_default) ) {
- $db_default = preg_match('/[\.,]/', $db_default) ? (float)$db_default : (int)$db_default;
- }
-
- $default_missing = false;
- $options = $fields[$f_name];
- $not_null = isset($options['not_null']) && $options['not_null'];
- $formatter = array_key_exists('formatter', $options) ? $options['formatter'] : false;
-
- if ( !array_key_exists('default', $options) ) {
- $config_errors[] = sprintf($error_messages['default_missing'], $f_name);
- $default_missing = true;
- }
-
- if ( $field['Null'] != 'YES' ) {
- // field is NOT NULL in database (MySQL5 for null returns "NO", but MySQL4 returns "")
- if ( $f_name != $config->getIDField() && !isset($options['not_null']) /*&& !isset($options['required'])*/ ) {
- $config_errors[] = sprintf($error_messages['not_null_error1'], $f_name);
- }
- if ( $not_null && !isset($options['default']) ) {
- $config_errors[] = sprintf($error_messages['not_null_error2'], $f_name);
- }
- }
- elseif ( $not_null ) {
- $config_errors[] = sprintf($error_messages['not_null_error3'], $f_name);
- }
-
- if ( ($formatter == 'kDateFormatter') && $not_null ) {
- $config_errors[] = sprintf($error_messages['date_column_not_null_error'], $f_name);
- }
-
- // columns, holding userid should have NULL as default value
- if ( array_key_exists('type', $options) && !$default_missing ) {
- // both type and default value set
-
- if ( preg_match('/ById$/', $f_name) && $options['default'] !== null ) {
- $config_errors[] = sprintf($error_messages['user_column_default_error'], $f_name);
- }
- }
-
- if ( !array_key_exists('type', $options) ) {
- $config_errors[] = sprintf($error_messages['type_missing'], $f_name);
- }
-
- if ( !$default_missing && ($field['Type'] != 'text') ) {
- if ( is_null($db_default) && $not_null ) {
- $db_default = $options['type'] == 'string' ? '' : 0;
- }
-
- if ( $f_name == $config->getIDField() && $options['type'] != 'string' && $options['default'] !== 0 ) {
- $config_errors[] = sprintf($error_messages['invalid_default'], 'IDField ', $f_name, $this->varDump($options['default']), $this->varDump($field['Default']));
- }
- else if ( ((string)$options['default'] != '#NOW#') && ($db_default !== $options['default']) && !in_array($options['type'], $float_types) ) {
- $config_errors[] = sprintf($error_messages['invalid_default'], '', $f_name, $this->varDump($options['default']), $this->varDump($db_default));
- }
- }
- }
- }
- }
-
- // validate virtual fields
- if ( $config->getVirtualFields() ) {
- foreach ($config->getVirtualFields() as $f_name => $options) {
- if ( !array_key_exists('type', $options) ) {
- $config_errors[] = sprintf($error_messages['virtual_type_missing'], $f_name);
- }
-
- if ( array_key_exists('not_null', $options) ) {
- $config_errors[] = sprintf($error_messages['virtual_not_null_error'], $f_name);
- }
-
- if ( !array_key_exists('default', $options) ) {
- $config_errors[] = sprintf($error_messages['virtual_default_missing'], $f_name);
- }
- }
- }
-
- // validate calculated fields
- if ( $config->getCalculatedFieldSpecials() ) {
- $virtual_fields = $config->getVirtualFields();
-
- foreach ($config->getCalculatedFieldSpecials() as $special) {
- foreach ($config->getCalculatedFieldsBySpecial($special) as $calculated_field => $calculated_field_expr) {
- if ( !isset($virtual_fields[$calculated_field]) ) {
- $config_errors[] = sprintf($error_messages['invalid_calculated_field'], $calculated_field);
- }
- }
- }
-
- $config_errors = array_unique($config_errors);
- }
-
- if ( $config_errors ) {
- $error_prefix = 'Config Error' . (count($config_errors) > 1 ? 's' : '') . ': for prefix ' . $config_link . ' (' . $table_name . ') in unit config:
';
- $config_errors = $error_prefix . ' ' . implode('
', $config_errors);
-
- kUtil::safeDefine('DBG_RAISE_ON_WARNINGS', 1);
- $debugger->appendHTML($config_errors);
- $debugger->WarningCount++;
- }
- }
-
- function varDump($value)
- {
- return ''.var_export($value, true).' of '.gettype($value);
- }
-
function postProcessConfig($prefix, $config_key, $dst_prefix_var)
{
$main_config = $this->configData[$prefix];
@@ -728,7 +443,7 @@
$processed = array_merge($this->postProcessConfig($sub_prefix, 'Clones', 'prefix'), $processed);
}
elseif ( $this->ProcessAllConfigs ) {
- $this->parseConfig($sub_prefix);
+ $this->configData[$sub_prefix]->parse();
}
array_push($processed, $sub_prefix);
@@ -783,6 +498,7 @@
preg_match($this->_moduleFolderRegExp, $filename, $regs);
$config->setModuleFolder(str_replace(DIRECTORY_SEPARATOR, '/', $regs[1]));
$config->setBasePath(dirname(FULL_PATH . $filename));
+ $config->setFilename($filename);
if ( $config->getAdminTemplatePath() !== false ) {
// append template base folder for admin templates path of this prefix
@@ -831,7 +547,7 @@
if ($this->FinalStage) {
// run prefix OnAfterConfigRead so all
- // hooks to it can define their clonses
+ // hooks to it can define their clones
$this->runAfterConfigRead($prefix);
}
@@ -888,40 +604,6 @@
return array_keys($this->configData);
}
- protected function getClasses($prefix)
- {
- $config = $this->configData[$prefix];
- $class_params = Array ('ItemClass', 'ListClass', 'EventHandlerClass', 'TagProcessorClass');
- $register_classes = $config->getRegisterClasses();
-
- foreach ($class_params as $param_name) {
- $value = $config->getSetting($param_name);
-
- if ( !$value ) {
- continue;
- }
-
- $value['pseudo'] = $this->getPseudoByOptionName($param_name, $prefix);
- $config->setSetting($param_name, $value);
-
- $register_classes[] = $value;
- }
-
- return $register_classes;
- }
-
- protected function getPseudoByOptionName($option_name, $prefix)
- {
- $pseudo_class_map = Array (
- 'ItemClass' => '%s',
- 'ListClass' => '%s_List',
- 'EventHandlerClass' => '%s_EventHandler',
- 'TagProcessorClass' => '%s_TagProcessor'
- );
-
- return sprintf($pseudo_class_map[$option_name], $prefix);
- }
-
/**
* Get's config file name based
* on folder name supplied