Project

General

Profile

1
<?php
2

    
3
/**
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

    
20
/**
21
 * WbAdaptor.php
22
 *
23
 * @category     Core
24
 * @package      Core_package
25
 * @author       Werner v.d.Decken <wkl@isteam.de>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28
 * @version      0.0.1
29
 * @revision     $Revision: 1861 $
30
 * @lastmodified $Date: 2013-02-18 00:55:02 +0100 (Mon, 18 Feb 2013) $
31
 * @since        File available since 18.01.2013
32
 * @deprecated   This class will be removed if Registry comes activated
33
 * @description  This adaptor is a temporary replacement for the future registry class
34
 */
35
class WbAdaptor {
36

    
37
/** active instance */	
38
	private static $_oInstance = null;
39
/** array hold settings */	
40
	private $_aSys = array();
41
/** constructor */
42
	protected function __construct() 
43
	{
44
		$this->_aSys = array('Sys' => array(), 'Req' => array());
45
	}
46
/**
47
 * Get active instance 
48
 * @return WbAdaptor
49
 */
50
	public static function getInstance()
51
	{
52
		if(self::$_oInstance === null) {
53
			$c = __CLASS__;
54
			self::$_oInstance = new $c();
55
			
56
		}
57
		return self::$_oInstance;
58
	}
59
/**
60
 * Get value of a variable
61
 * @param string name of the variable
62
 * @return mixed
63
 */	
64
	public function __get($sVarname)
65
	{
66
		if( isset($this->_aSys['Request'][$sVarname])) {
67
			return $this->_aSys['Request'][$sVarname];
68
		}elseif( isset($this->_aSys['System'][$sVarname])) {
69
			return $this->_aSys['System'][$sVarname];
70
		}elseif( isset($this->_aSys[$sVarname])) {
71
			return $this->_aSys[$sVarname];
72
		}else {
73
			return null;
74
		}
75
	}
76
/**
77
 * Check if var is set
78
 * @param string name of the variable
79
 * @return bool
80
 */	
81
	public function __isset($sVarname)
82
	{
83
		$bRetval = (isset($this->_aSys['Request'][$sVarname]) ||
84
		            isset($this->_aSys['System'][$sVarname]) ||
85
		            isset($this->_aSys[$sVarname]));
86
		return $bRetval;
87
	}
88
/**
89
 * Import WB-Constants
90
 */	
91
	public function getWbConstants()
92
	{
93
		$this->_aSys = array('Sys' => array(), 'Req' => array());
94
		$aConsts = get_defined_constants(true);
95
		foreach($aConsts['user'] as $sKey=>$sVal)
96
		{
97
			// change all path items to trailing slash scheme
98
			switch($sKey):
99
				case 'WB_URL': 
100
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
101
					$sKey = 'AppUrl';
102
					$this->_aSys['System'][$sKey] = $sVal; 
103
					break;
104
				case 'WB_REL':
105
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
106
					$sKey = 'AppRel';
107
					$this->_aSys['System'][$sKey] = $sVal; 
108
					break;
109
				case 'WB_PATH':
110
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
111
					$sKey = 'AppPath';
112
					$this->_aSys['System'][$sKey] = $sVal; 
113
					break;
114
				case 'ADMIN_URL':
115
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
116
					$sKey = 'AcpUrl';
117
					$this->_aSys['System'][$sKey] = $sVal; 
118
					break;
119
				case 'ADMIN_REL':
120
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
121
					$sKey = 'AcpRel';
122
					$this->_aSys['System'][$sKey] = $sVal; 
123
					break;
124
				case 'ADMIN_PATH':
125
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
126
					$sKey = 'AcpPath';
127
					$this->_aSys['System'][$sKey] = $sVal; 
128
					break;
129
				case 'THEME_URL':
130
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
131
					$sKey = 'ThemeUrl';
132
					$this->_aSys['Request'][$sKey] = $sVal; 
133
					break;
134
				case 'THEME_REL':
135
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
136
					$sKey = 'ThemeRel';
137
					$this->_aSys['Request'][$sKey] = $sVal; 
138
					break;
139
				case 'THEME_PATH':
140
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
141
					$sKey = 'ThemePath';
142
					$this->_aSys['Request'][$sKey] = $sVal; 
143
					break;
144
				case 'TMP_PATH':
145
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
146
					$sKey = 'TempPath';
147
					$this->_aSys['System'][$sKey] = $sVal; 
148
					break;
149
				case 'ADMIN_DIRECTORY':
150
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
151
					$sKey = 'AcpDir';
152
					$this->_aSys['System'][$sKey] = $sVal; 
153
					break;
154
				case 'DOCUMENT_ROOT':
155
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
156
					$sKey = 'DocumentRoot';
157
					$this->_aSys['System'][$sKey] = $sVal; 
158
					break;
159
				case 'PAGES_DIRECTORY':
160
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
161
					$sKey = 'PagesDir';
162
					$this->_aSys['System'][$sKey] = $sVal; 
163
					break;
164
				case 'MEDIA_DIRECTORY':
165
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
166
					$sKey = 'MediaDir';
167
					$this->_aSys['System'][$sKey] = $sVal; 
168
					break;
169
				case 'DEFAULT_TEMPLATE':
170
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
171
					$sKey = 'DefaultTemplate';
172
					$this->_aSys['Request'][$sKey] = $sVal; 
173
					break;
174
				case 'DEFAULT_THEME':
175
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
176
					$sKey = 'DefaultTheme';
177
					$this->_aSys['Request'][$sKey] = $sVal; 
178
					break;
179
				case 'TABLE_PREFIX':
180
					$sKey = 'TablePrefix';
181
					$this->_aSys['System'][$sKey] = $sVal; 
182
					break;
183
				case 'OCTAL_FILE_MODE':
184
					$sVal = ((intval($sVal) & ~0111)|0600); // o-x/g-x/u-x/o+rw
185
					$sKey = 'OctalFileMode';
186
					$this->_aSys['Request'][$sKey] = $sVal; 
187
					break;
188
				case 'OCTAL_DIR_MODE':
189
					$sVal = (intval($sVal) |0711); // o+rwx/g+x/u+x
190
					$sKey = 'OctalDirMode';
191
					$this->_aSys['Request'][$sKey] = $sVal; 
192
					break;
193
				case 'WB_VERSION':
194
					$sKey = 'AppVersion';
195
					$this->_aSys['System'][$sKey] = $sVal; 
196
					break;
197
				case 'WB_REVISION':
198
					$sKey = 'AppRevision';
199
					$this->_aSys['System'][$sKey] = $sVal; 
200
					break;
201
				case 'WB_SP':
202
					$sKey = 'AppServicePack';
203
					$this->_aSys['System'][$sKey] = $sVal; 
204
					break;
205
				default:
206
					$sVal = ($sVal == 'true' ? true : ($sVal == 'false' ? false : $sVal));
207
					$sKey = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($sKey))));
208
					$this->_aSys['Request'][$sKey] = $sVal; 
209
					break;
210
			endswitch;
211
			$this->_aSys[$sKey] = $sVal;
212
		}
213
		$this->_aSys['AppName'] = 'WebsiteBaker';
214
		$this->_aSys['System']['AppName'] = 'WebsiteBaker';
215
	}
216

    
217
} // end of class WbAdaptor
218

    
(10-10/29)