-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.php
More file actions
128 lines (107 loc) · 4.09 KB
/
Configuration.php
File metadata and controls
128 lines (107 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
* @(#)Configuration.php 0.00 Dec 30, 2009
* Author: Jim Steinberger
*
* Copyright (c) 2009 University of Michigan
* Ann Arbor, MI, 48109, USA
* All Rights Reserved.
*
* This software is the proprietary information of the University of Michigan
* ("Proprietary Information"). You shall use it only in accordance with the
* terms of the license agreement you entered into with the University of
* Michigan.
*/
/**
* Contains the Configuration class
* @package ModelDoc
*/
namespace ModelDoc;
use ModelDoc\Util;
use ModelDoc\Database;
require_once( __DIR__ . '/MediaWiki.php' );
require_once( __DIR__ . '/mediawiki/Snoopy.class.php' );
require_once( __DIR__ . '/datasource/Postgres.php' );
/**
* This class encompasses the configuration of ModelDoc
*/
class Configuration {
// Constants
const MEDIAWIKI_USERNAME = 'username';
const MEDIAWIKI_PASSWORD = 'password';
const MEDIAWIKI_URL = 'url';
/** The type of the data source */
const DATASOURCE_TYPE = 'type';
/** @var string Used for database-backed data sources */
const DATASOURCE_HOST = 'host';
/** @var string The abstract name of the data source */
const DATASOURCE_NAME = 'name';
/** @var string Used for database-backed data sources */
const DATASOURCE_USERNAME = 'username';
/** @var string Used for database-backed data sources */
const DATASOURCE_PASSWORD = 'password';
/** @var string The name of the database; for database-backed data sources */
const DATASOURCE_DATABASE = 'database';
private $configFilePath;
public $mediaWikiUsername;
public $mediaWikiPassword;
public $mediaWikiURL;
public $databases;
public $snoopy;
/**
* The constructor
* @param $configFilePath
*/
public function __construct($configFilePath) {
$this->configFilePath = $configFilePath;
$this->snoopy = new \Snoopy();
$xml = simplexml_load_file( $this->configFilePath );
$this->mediaWikiUsername = (string) $xml->mediawiki[self::MEDIAWIKI_USERNAME];
$this->mediaWikiPassword = (string) $xml->mediawiki[self::MEDIAWIKI_PASSWORD];
$this->mediaWikiURL = (string) $xml->mediawiki[self::MEDIAWIKI_URL];
}
public function loadDatasourcesFromWiki() {
$configXML = simplexml_load_string(MediaWiki::getPageText(
self::getConfigPageName()));
\ModelDoc\Util\Log::logString("Reading in: " . self::getConfigPageName());
\ModelDoc\Util\Log::logString("The xml: " . (string) $configXML);
$dataSourceConfig = simplexml_load_string($configXML->page->revision->text);
\ModelDoc\Util\Log::logString($dataSourceConfig);
$this->databases = array();
foreach ($dataSourceConfig->dataSources->dataSource as $dataSource) {
Util\Log::logString("Adding data source " . (string) $dataSource[self::DATASOURCE_NAME]);
switch ($dataSource[self::DATASOURCE_TYPE]) {
case "postgres":
$this->databases[ (string) $dataSource[self::DATASOURCE_NAME] ]
= new Datasource\Postgres(
(string) $dataSource[self::DATASOURCE_HOST],
(string) $dataSource[self::DATASOURCE_USERNAME],
(string) $dataSource[self::DATASOURCE_PASSWORD],
(string) $dataSource[self::DATASOURCE_DATABASE]
);
break;
}
}
}
public static function LINK($page, $label = NULL) {
if (is_null($label)) {
$label = $page;
}
return "[[$page|$label]]";
}
public static function getConfigPageName() {
return "ModelDoc::Configuration";
}
public static function getEntityInfoPageName($dataSourceName, $entityName) {
return "ModelDoc::DataSource(\"$dataSourceName\")::Entity(\"$entityName\")";
}
public static function getEntityHistoryPageName($dataSourceName, $entityName) {
return "ModelDoc::DataSource(\"$dataSourceName\")::Entity(\"$entityName\")::HISTORY";
}
public static function getDataSourceInfoPageName($dataSourceName) {
return "ModelDoc::DataSource(\"$dataSourceName\")";
}
public static function getDataSourceHistoryPageName($dataSourceName) {
return "ModelDoc::DataSource(\"$dataSourceName\")::HISTORY";
}
}