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: 1982 $
30
 * @lastmodified $Date: 2013-10-17 03:07:12 +0200 (Thu, 17 Oct 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('System' => array(), 'Request' => 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
 * handle unknown properties
61
 * @param string name of the property
62
 * @param mixed value to set
63
 * @throws InvalidArgumentException
64
 */	
65
	public function __set($name, $value) 
66
	{
67
		throw new InvalidArgumentException('tried to set readonly or nonexisting property [ '.$name.' }!! ');
68
	}
69
/**
70
 * Get value of a variable
71
 * @param string name of the variable
72
 * @return mixed
73
 */	
74
	public function __get($sVarname)
75
	{
76
		if( isset($this->_aSys['Request'][$sVarname])) {
77
			return $this->_aSys['Request'][$sVarname];
78
		}elseif( isset($this->_aSys['System'][$sVarname])) {
79
			return $this->_aSys['System'][$sVarname];
80
		}elseif( isset($this->_aSys[$sVarname])) {
81
			return $this->_aSys[$sVarname];
82
		}else {
83
			return null;
84
		}
85
	}
86
/**
87
 * Check if var is set
88
 * @param string name of the variable
89
 * @return bool
90
 */	
91
	public function __isset($sVarname)
92
	{
93
		$bRetval = (isset($this->_aSys['Request'][$sVarname]) ||
94
		            isset($this->_aSys['System'][$sVarname]) ||
95
		            isset($this->_aSys[$sVarname]));
96
		return $bRetval;
97
	}
98
/**
99
 * Import WB-Constants
100
 */	
101
	public function getWbConstants()
102
	{
103
		$this->_aSys = array('System' => array(), 'Request' => array());
104
		$aConsts = get_defined_constants(true);
105
		foreach($aConsts['user'] as $sKey=>$sVal)
106
		{
107
			// change all path items to trailing slash scheme
108
			switch($sKey):
109
				case 'WB_URL': 
110
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
111
					$sKey = 'AppUrl';
112
					$this->_aSys['System'][$sKey] = $sVal; 
113
					break;
114
				case 'WB_REL':
115
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
116
					$sKey = 'AppRel';
117
					$this->_aSys['System'][$sKey] = $sVal; 
118
					break;
119
				case 'WB_PATH':
120
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
121
					$sKey = 'AppPath';
122
					$this->_aSys['System'][$sKey] = $sVal; 
123
					break;
124
				case 'ADMIN_URL':
125
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
126
					$sKey = 'AcpUrl';
127
					$this->_aSys['System'][$sKey] = $sVal; 
128
					break;
129
				case 'ADMIN_REL':
130
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
131
					$sKey = 'AcpRel';
132
					$this->_aSys['System'][$sKey] = $sVal; 
133
					break;
134
				case 'ADMIN_PATH':
135
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
136
					$sKey = 'AcpPath';
137
					$this->_aSys['System'][$sKey] = $sVal; 
138
					break;
139
				case 'THEME_URL':
140
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
141
					$sKey = 'ThemeUrl';
142
					$this->_aSys['Request'][$sKey] = $sVal; 
143
					break;
144
				case 'THEME_REL':
145
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
146
					$sKey = 'ThemeRel';
147
					$this->_aSys['Request'][$sKey] = $sVal; 
148
					break;
149
				case 'THEME_PATH':
150
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
151
					$sKey = 'ThemePath';
152
					$this->_aSys['Request'][$sKey] = $sVal; 
153
					break;
154
				case 'TMP_PATH':
155
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
156
					$sKey = 'TempPath';
157
					$this->_aSys['System'][$sKey] = $sVal; 
158
					break;
159
				case 'ADMIN_DIRECTORY':
160
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
161
					$sKey = 'AcpDir';
162
					$this->_aSys['System'][$sKey] = $sVal; 
163
					break;
164
				case 'DOCUMENT_ROOT':
165
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
166
					$sKey = 'DocumentRoot';
167
					$this->_aSys['System'][$sKey] = $sVal; 
168
					break;
169
				case 'PAGES_DIRECTORY':
170
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
171
					$sVal = $sVal=='/' ? '' : $sVal;
172
					$sKey = 'PagesDir';
173
					$this->_aSys['System'][$sKey] = $sVal; 
174
					break;
175
				case 'MEDIA_DIRECTORY':
176
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
177
					$sKey = 'MediaDir';
178
					$this->_aSys['System'][$sKey] = $sVal; 
179
					break;
180
				case 'DEFAULT_TEMPLATE':
181
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
182
					$sKey = 'DefaultTemplate';
183
					$this->_aSys['Request'][$sKey] = $sVal; 
184
					break;
185
				case 'DEFAULT_THEME':
186
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
187
					$sKey = 'DefaultTheme';
188
					$this->_aSys['Request'][$sKey] = $sVal; 
189
					break;
190
				case 'TABLE_PREFIX':
191
					$sKey = 'TablePrefix';
192
					$this->_aSys['System'][$sKey] = $sVal; 
193
					break;
194
				case 'OCTAL_FILE_MODE':
195
					$sVal = ((intval($sVal) & ~0111)|0600); // o-x/g-x/u-x/o+rw
196
					$sKey = 'OctalFileMode';
197
					$this->_aSys['Request'][$sKey] = $sVal; 
198
					break;
199
				case 'OCTAL_DIR_MODE':
200
					$sVal = (intval($sVal) |0711); // o+rwx/g+x/u+x
201
					$sKey = 'OctalDirMode';
202
					$this->_aSys['Request'][$sKey] = $sVal; 
203
					break;
204
				case 'WB_VERSION':
205
					$sKey = 'AppVersion';
206
					$this->_aSys['System'][$sKey] = $sVal; 
207
					break;
208
				case 'WB_REVISION':
209
					$sKey = 'AppRevision';
210
					$this->_aSys['System'][$sKey] = $sVal; 
211
					break;
212
				case 'WB_SP':
213
					$sKey = 'AppServicePack';
214
					$this->_aSys['System'][$sKey] = $sVal; 
215
					break;
216
				default:
217
					$sVal = ($sVal == 'true' ? true : ($sVal == 'false' ? false : $sVal));
218
					$sKey = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($sKey))));
219
					$this->_aSys['Request'][$sKey] = $sVal; 
220
					break;
221
			endswitch;
222
			$this->_aSys[$sKey] = $sVal;
223
		}
224
		$this->_aSys['AppName'] = 'WebsiteBaker';
225
		$this->_aSys['System']['AppName'] = 'WebsiteBaker';
226
		$this->_aSys['Request']['AppName'] = 'WebsiteBaker';
227
	}
228

    
229
} // end of class WbAdaptor
230

    
(15-15/34)