Skip to content

Commit

Permalink
init schema using share-dir from config-file (if possible). Closes gh-8
Browse files Browse the repository at this point in the history
  • Loading branch information
indeyets committed Jun 16, 2010
1 parent b2a3089 commit 16814d1
Show file tree
Hide file tree
Showing 34 changed files with 61 additions and 74 deletions.
69 changes: 61 additions & 8 deletions midgard.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,61 @@ static zend_bool php_midgard_initialize_configs(TSRMLS_D)
return TRUE;
}

static void php_midgard_initialize_schema(TSRMLS_D)
{
if (midgard_global_schema != NULL) {
return;
}

const char *conf_file = MGDG(midgard_configuration_file);
const char *conf_name = MGDG(midgard_configuration);

zend_bool initialized = FALSE;
const char *share_dir = NULL;

// trying midgard.configuration_file
if (conf_file && conf_file[0] != '\0') {
MidgardConfig *config = midgard_config_new();
if (midgard_config_read_file_at_path(config, conf_file, NULL)) {
share_dir = g_strdup(config->sharedir);

if (share_dir) {
initialized = TRUE;
}
}
g_object_unref(config);
}

// trying midgard.configuration
if (initialized == FALSE && conf_name && conf_name[0] != '\0') {
MidgardConfig *config = midgard_config_new();
if (midgard_config_read_file(config, conf_name, FALSE, NULL)) {
share_dir = g_strdup(config->sharedir);

if (share_dir) {
initialized = TRUE;
}
}
g_object_unref(config);
}

if (initialized == FALSE) {
// init from core-defaults
midgard_global_schema = g_object_new(MIDGARD_TYPE_SCHEMA, NULL);
midgard_schema_init(midgard_global_schema, NULL);
midgard_schema_read_dir(midgard_global_schema, NULL);
} else {
gchar *path = g_build_path(G_DIR_SEPARATOR_S, share_dir, "MidgardObjects.xml", NULL);

midgard_global_schema = g_object_new(MIDGARD_TYPE_SCHEMA, NULL);
midgard_schema_init(midgard_global_schema, path);
zend_bool success = midgard_schema_read_dir(midgard_global_schema, share_dir);

g_free(share_dir);
g_free(path);
}
}

PHP_MINIT_FUNCTION(midgard2)
{
if (zend_get_extension("midgard") != NULL) {
Expand Down Expand Up @@ -262,12 +317,10 @@ PHP_MINIT_FUNCTION(midgard2)

midgard_init();

REGISTER_INI_ENTRIES();

/* register Gtype types from schemas */
if (midgard_global_schema == NULL) {
midgard_global_schema = g_object_new(MIDGARD_TYPE_SCHEMA, NULL);
midgard_schema_init((MidgardSchema *) midgard_global_schema, NULL);
midgard_schema_read_dir((MidgardSchema *) midgard_global_schema, NULL);
}
php_midgard_initialize_schema(TSRMLS_C);

/* Initialize handlers */
memcpy(&php_midgard_gobject_handlers, zend_get_std_object_handlers(),
Expand Down Expand Up @@ -367,8 +420,6 @@ PHP_MINIT_FUNCTION(midgard2)

#undef MGD_PHP_REGISTER_CONSTANT

REGISTER_INI_ENTRIES();

if (MGDG(superglobals_compat)) {
php_error(E_DEPRECATED, "midgard.superglobals_compat option is deprecated and might be removed in next release");

Expand Down Expand Up @@ -433,8 +484,10 @@ PHP_MSHUTDOWN_FUNCTION(midgard2)
return SUCCESS;

/* Free schema */
if (midgard_global_schema != NULL)
if (midgard_global_schema != NULL) {
g_object_unref(midgard_global_schema);
midgard_global_schema = NULL;
}

/* Free connections */
php_midgard_handle_holder_free(&MGDG(midgard_global_holder));
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/007-midgard_dbobject.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file = [[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$obj = new atype();
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/009-midgard_blob.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[PATH]]/test.cfg
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$cfg = new midgard_config();
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/010-query_builder.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$query = new midgard_query_builder('atype');
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/011-midgard_user.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file = [[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$user1 = new midgard_user();
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/012a-querybuilder-signals.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file = [[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$signals = array('update' => false,
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/012b-inherited_querybuilder-signals.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file = [[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
class extend_atype extends atype
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/014-signals.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file = [[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/015-query_builder_result.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
// =========================================================================================
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/016-query_builder_views.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$obj1 = new atype();
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/017-midgard_reflection_property.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
// testing direct instantiation
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/018-midgard_object_class-errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
var_dump(midgard_object_class::factory('non_existant_class') === NULL);
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/018-midgard_object_class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$obj = midgard_object_class::factory('atype');
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/019-midgard_collector.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$obj = new atype();
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/020-query_builder-autoload.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
function __autoload($classname)
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/022-bug1460.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$login = 'bug1460';
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/023-bug1478.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$login = 'bug1478';
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/024-bug1484.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$a = new atype();
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/025-bug1492.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=doesnotexist
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$mgd = midgard_connection::get_instance();
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/026-is_in_parent_tree.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/027-is_in_tree.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/028-stream_wrapper.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$obj = new midgard_snippetdir();
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/029-parent.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/030-setguid.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/031-emit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/032-approve.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/033-lock.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/036-replicator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/037-bug1763.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ midgard.memory_debug = Off
midgard.configuration=
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
class company_person extends midgard_person
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/038-escaping.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/039-midgard_query_storage.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
try {
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/040-midgard_query_holder.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php

Expand Down
2 changes: 0 additions & 2 deletions tests_templates/041-midgard_query_constraint.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$storage = new midgard_query_storage('atype');
Expand Down
2 changes: 0 additions & 2 deletions tests_templates/042-midgard_query_select.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$storage = new midgard_query_storage('atype');
Expand Down

0 comments on commit 16814d1

Please sign in to comment.