Project

General

Profile

« Previous | Next » 

Revision 2120

Added by darkviper about 9 years ago

  1. framework/WbAdaptor some litte fixes
    + framework/WbDatabaseHelper contains now all maintenance methods from WbDatabase
    ! framework/WbDatabase all maintenance methods has been moved to framework/WbDatabaseHelper

View differences:

WbAdaptor.php
22 22
 *
23 23
 * @category     Core
24 24
 * @package      Core_package
25
 * @author       Werner v.d.Decken <wkl@isteam.de>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
25
 * @author       Manuela v.d.Decken <manuela@isteam.de>
26
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
27 27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28 28
 * @version      0.0.1
29 29
 * @revision     $Revision$
......
35 35
class WbAdaptor {
36 36

  
37 37
/** active instance */	
38
	protected static $_oInstance = null;
38
	protected static $oInstance = null;
39 39
/** array hold settings */	
40
	protected $_aSys = array();
40
	protected $aProperties = array();
41
/**  */
42
    protected $aObjects = array('Db' => null, 'Trans' => null, 'App' => null);
43
/** vars which             */
44
    protected $aReservedVars = array('Db', 'Trans', 'App');
41 45
/** constructor */
42 46
	protected function __construct() 
43 47
	{
44
		$this->_aSys = array('System' => array(), 'Request' => array());
48
		$this->aProperties = array('System' => array(), 'Request' => array());
45 49
	}
46 50
/**
47 51
 * Get active instance 
......
49 53
 */
50 54
	public static function getInstance()
51 55
	{
52
		if(self::$_oInstance == null) {
56
		if(self::$oInstance == null) {
53 57
			$c = __CLASS__;
54
			self::$_oInstance = new $c();
58
			self::$oInstance = new $c();
55 59
			
56 60
		}
57
		return self::$_oInstance;
61
		return self::$oInstance;
58 62
	}
59 63
/**
64
 * set the global database object
65
 * @param WbDatabase $oDb
66
 */
67
    public function setDatabase(WbDatabase $oDb)
68
    {
69
        $this->aObjects['Db'] = $oDb;
70
        return true;
71
    }
72
/**
73
 * set the global translation object
74
 * @param Translate $oTrans
75
 */
76
    public function setTranslate(Translate $oTrans)
77
    {
78
        $this->aObjects['Trans'] = $oTrans;
79
        return true;
80
    }
81
/**
82
 * set the global application object
83
 * @param wb $oApp
84
 */
85
    public function setApplication(wb $oApp)
86
    {
87
        $this->aObjects['App'] = $oApp;
88
    }
89
/**
60 90
 * handle unknown properties
61 91
 * @param string name of the property
62 92
 * @param mixed value to set
......
64 94
 */	
65 95
	public function __set($name, $value) 
66 96
	{
67
		throw new InvalidArgumentException('tried to set readonly or nonexisting property [ '.$name.' }!! ');
97
        if (array_key_exists($name, $this->aProperties['System'])) {
98
            throw new InvalidArgumentException('tried to set readonly or nonexisting property [ '.$name.' }!! ');
99
        } else {
100
            $this->aProperties['Request'][$name] = $value;
101
        }
68 102
	}
69 103
/**
70 104
 * Get value of a variable
......
73 107
 */	
74 108
	public function __get($sVarname)
75 109
	{
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;
110
        if (isset($this->aObjects[$sVarname]) && !is_null($this->aObjects[$sVarname])) {
111
            return $this->aObjects[$sVarname];
112
        }
113
        if (isset($this->aProperties['System'][$sVarname])) {
114
            return $this->aProperties['System'][$sVarname];
115
        } elseif ( isset($this->aProperties['Request'][$sVarname])) {
116
            return $this->aProperties['Request'][$sVarname];
117
        } else {
118
            return null;
84 119
		}
85 120
	}
86 121
/**
......
90 125
 */	
91 126
	public function __isset($sVarname)
92 127
	{
93
		$bRetval = (isset($this->_aSys['Request'][$sVarname]) ||
94
		            isset($this->_aSys['System'][$sVarname]) ||
95
		            isset($this->_aSys[$sVarname]));
128
        if (isset($this->aObjects[$sVarname]) && !is_null($this->aObjects[$sVarname])) {
129
            return true;
130
        }
131
		$bRetval = (isset($this->aProperties['System'][$sVarname]) ||
132
		            isset($this->aProperties['Request'][$sVarname]));
96 133
		return $bRetval;
97 134
	}
98 135
/**
......
100 137
 */	
101 138
	public function getWbConstants()
102 139
	{
103
		$this->_aSys = array('System' => array(), 'Request' => array());
140
    // first reinitialize arrays
141
		$this->aProperties = array(
142
            'System' => array(),
143
            'Request' => array()
144
        );
145
    // get all defined constants
104 146
		$aConsts = get_defined_constants(true);
105
		foreach($aConsts['user'] as $sKey=>$sVal)
106
		{
147
    // iterate all user defined constants
148
		foreach ($aConsts['user'] as $sKey=>$sVal) {
149
            if (in_array($sKey, $this->aReservedVars)) { continue; }
107 150
		// skip possible existing database constants
108 151
			if (preg_match('/^db_|^TABLE_PREFIX$/i', $sKey)) { continue; }
109
		// change all path items to trailing slash scheme
152
		// change all path items to trailing slash scheme and assign the new naming syntax
110 153
			switch($sKey):
154
                case 'DEBUG':
155
                    $this->aProperties['System']['Debug'] = intval($sVal);
156
                    $this->aProperties['System']['DebugLevel'] = intval($sVal);
157
                    break;
111 158
				case 'WB_URL': 
112 159
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
113 160
					$sKey = 'AppUrl';
114
					$this->_aSys['System'][$sKey] = $sVal; 
161
					$this->aProperties['System'][$sKey] = $sVal;
115 162
					break;
116 163
				case 'WB_REL':
117 164
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
118 165
					$sKey = 'AppRel';
119
					$this->_aSys['System'][$sKey] = $sVal; 
166
					$this->aProperties['System'][$sKey] = $sVal;
120 167
					break;
121 168
				case 'WB_PATH':
122 169
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
123 170
					$sKey = 'AppPath';
124
					$this->_aSys['System'][$sKey] = $sVal; 
171
					$this->aProperties['System'][$sKey] = $sVal;
125 172
					break;
126 173
				case 'ADMIN_URL':
127 174
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
128 175
					$sKey = 'AcpUrl';
129
					$this->_aSys['System'][$sKey] = $sVal; 
176
					$this->aProperties['System'][$sKey] = $sVal;
130 177
					break;
131 178
				case 'ADMIN_REL':
132 179
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
133 180
					$sKey = 'AcpRel';
134
					$this->_aSys['System'][$sKey] = $sVal; 
181
					$this->aProperties['System'][$sKey] = $sVal;
135 182
					break;
136 183
				case 'ADMIN_PATH':
137 184
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
138 185
					$sKey = 'AcpPath';
139
					$this->_aSys['System'][$sKey] = $sVal; 
186
					$this->aProperties['System'][$sKey] = $sVal;
140 187
					break;
141 188
				case 'THEME_URL':
142 189
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
143 190
					$sKey = 'ThemeUrl';
144
					$this->_aSys['Request'][$sKey] = $sVal; 
191
					$this->aProperties['Request'][$sKey] = $sVal;
145 192
					break;
146 193
				case 'THEME_REL':
147 194
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
148 195
					$sKey = 'ThemeRel';
149
					$this->_aSys['Request'][$sKey] = $sVal; 
196
					$this->aProperties['Request'][$sKey] = $sVal;
150 197
					break;
151 198
				case 'THEME_PATH':
152 199
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
153 200
					$sKey = 'ThemePath';
154
					$this->_aSys['Request'][$sKey] = $sVal; 
201
					$this->aProperties['Request'][$sKey] = $sVal;
155 202
					break;
156 203
				case 'TMP_PATH':
157 204
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
158 205
					$sKey = 'TempPath';
159
					$this->_aSys['System'][$sKey] = $sVal; 
206
					$this->aProperties['System'][$sKey] = $sVal;
160 207
					break;
161 208
				case 'ADMIN_DIRECTORY':
162 209
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
163 210
					$sKey = 'AcpDir';
164
					$this->_aSys['System'][$sKey] = $sVal; 
211
					$this->aProperties['System'][$sKey] = $sVal;
165 212
					break;
166 213
				case 'DOCUMENT_ROOT':
167 214
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
168 215
					$sKey = 'DocumentRoot';
169
					$this->_aSys['System'][$sKey] = $sVal; 
216
					$this->aProperties['System'][$sKey] = $sVal;
170 217
					break;
171 218
				case 'PAGES_DIRECTORY':
172 219
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
173 220
					$sVal = $sVal=='/' ? '' : $sVal;
174 221
					$sKey = 'PagesDir';
175
					$this->_aSys['System'][$sKey] = $sVal; 
222
					$this->aProperties['System'][$sKey] = $sVal;
176 223
					break;
177 224
				case 'MEDIA_DIRECTORY':
178 225
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
179 226
					$sKey = 'MediaDir';
180
					$this->_aSys['System'][$sKey] = $sVal; 
227
					$this->aProperties['System'][$sKey] = $sVal;
181 228
					break;
182 229
				case 'DEFAULT_TEMPLATE':
183
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
230
					$sVal = trim(str_replace('\\', '/', $sVal), '/');
184 231
					$sKey = 'DefaultTemplate';
185
					$this->_aSys['Request'][$sKey] = $sVal; 
232
					$this->aProperties['System'][$sKey] = $sVal;
186 233
					break;
187 234
				case 'TEMPLATE':
188
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
235
					$sVal = trim(str_replace('\\', '/', $sVal), '/');
189 236
					$sKey = 'Template';
190
					$this->_aSys['Request'][$sKey] = $sVal;
237
					$this->aProperties['Request'][$sKey] = $sVal;
191 238
					break;
192 239
				case 'DEFAULT_THEME':
193
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
240
					$sVal = trim(str_replace('\\', '/', $sVal), '/');
194 241
					$sKey = 'DefaultTheme';
195
					$this->_aSys['Request'][$sKey] = $sVal; 
242
					$this->aProperties['System'][$sKey] = $sVal;
243
					$this->aProperties['Request']['Theme'] = trim($sVal, '/');
196 244
					break;
197 245
				case 'OCTAL_FILE_MODE':
198 246
					$sVal = ((intval($sVal) & ~0111)|0600); // o-x/g-x/u-x/o+rw
199 247
					$sKey = 'OctalFileMode';
200
					$this->_aSys['Request'][$sKey] = $sVal; 
248
					$this->aProperties['System']['OctalFileMode'] = $sVal;
249
					$this->aProperties['System']['FileModeOctal'] = $sVal;
201 250
					break;
202 251
				case 'OCTAL_DIR_MODE':
203 252
					$sVal = (intval($sVal) |0711); // o+rwx/g+x/u+x
204 253
					$sKey = 'OctalDirMode';
205
					$this->_aSys['Request'][$sKey] = $sVal; 
254
					$this->aProperties['System']['OctalDirMode'] = $sVal;
255
					$this->aProperties['System']['DirModeOctal'] = $sVal;
206 256
					break;
207 257
				case 'WB_VERSION':
208 258
					$sKey = 'AppVersion';
209
					$this->_aSys['System'][$sKey] = $sVal; 
259
					$this->aProperties['System'][$sKey] = $sVal;
210 260
					break;
211 261
				case 'WB_REVISION':
212 262
					$sKey = 'AppRevision';
213
					$this->_aSys['System'][$sKey] = $sVal; 
263
					$this->aProperties['System'][$sKey] = $sVal;
214 264
					break;
215 265
				case 'WB_SP':
216 266
					$sKey = 'AppServicePack';
217
					$this->_aSys['System'][$sKey] = $sVal; 
267
					$this->aProperties['System'][$sKey] = $sVal;
218 268
					break;
219 269
                case 'PAGE_ICON_DIR':
220 270
                    $sKey = 'PageIconDir';
221 271
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
222
                    if (!isset($this->_aSys['Request']['Template'])) {
223
                        $this->_aSys['Request']['Template'] = $this->_aSys['Request']['DefaultTemplate'];
224
                    }
225
                    $sVal = str_replace('/*/', '/'.$this->_aSys['Request']['Template'], $sVal);
226
					$this->_aSys['System'][$sKey] = $sVal;
272
					$this->aProperties['Request'][$sKey] = $sVal;
227 273
                    break;
274
                case 'TEMPLATE_DIR':
275
                    break;
228 276
				default:
277
                    $aSysList = array(
278
                    // list of values which should be placed in ['System']
279
                        'DefaultCharset','DefaultDateFormat','DefaultLanguage','DefaultTimeFormat',
280
                        'DefaultTimezone','DevInfos'
281
                    );
282
                    // convert 'true' or 'false' strings into boolean
229 283
					$sVal = ($sVal == 'true' ? true : ($sVal == 'false' ? false : $sVal));
284
                    // reformatting constant names
230 285
					$sKey = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($sKey))));
231
					$this->_aSys['Request'][$sKey] = $sVal; 
286
                    if (in_array($sKey, $aSysList)) {
287
    					$this->aProperties['System'][$sKey] = $sVal;
288
                    } else {
289
                        $this->aProperties['Request'][$sKey] = $sVal;
290
                    }
232 291
					break;
233 292
			endswitch;
234
			$this->_aSys[$sKey] = $sVal;
235 293
		}
236
		$this->_aSys['AppName'] = 'WebsiteBaker';
237
		$this->_aSys['System']['AppName'] = 'WebsiteBaker';
238
		$this->_aSys['Request']['AppName'] = 'WebsiteBaker';
294
/* now set values which needs dependencies */
295
        if (!isset($this->aProperties['Request']['Template']) || $this->aProperties['Request']['Template'] == '') {
296
            $this->aProperties['Request']['Template'] = $this->DefaultTemplate;
297
        }
298
		$this->aProperties['System']['AppName'] = 'WebsiteBaker';
299
        if (isset($this->Template)) {
300
            $this->aProperties['Request']['TemplateDir']  = 'templates/'.$this->Template.'/';
301
            $this->aProperties['Request']['TemplateUrl']  = $this->AppUrl.'templates/'.$this->Template.'/';
302
            $this->aProperties['Request']['TemplatePath'] = $this->AppPath.'templates/'.$this->Template.'/';
303
        }
304
/* correct PageIconDir if necessary */
305
        $this->aProperties['Request']['PageIconDir'] = str_replace('/*/', '/'.$this->Template, $this->PageIconDir);
306

  
307
/* cleanup arrays */
308
        $this->aProperties['Request'] = array_diff_key(
309
            $this->aProperties['Request'],
310
            $this->aProperties['System']
311
        );
312

  
239 313
	}
314
// temporary method for testing purposes only
315
    public function showAll()
316
    {
317
        ksort($this->_aSys['System']);
318
        ksort($this->_aSys['Request']);
319
        return $this->_aSys;
320
    }
240 321

  
241 322
} // end of class WbAdaptor
242 323

  

Also available in: Unified diff