Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
3 lars 1
<?php
2
/* $Id: Functions.class.php 10 2007-05-02 12:47:02Z tiefland $ */
3
 
4
/**
5
 * Functions handling class, for modules.
6
 *
7
 * This class handles the loading of any function needed by
8
 * a module e.g. Shop or any else. You easy could instance
9
 * this in the main Class of the module.
10
 * @see Shop()
11
 *
12
 * PHP versions 4 and 5
13
 *
14
 * LICENSE: This source file is subject to version 3.0 of the PHP license
15
 * that is available through the world-wide-web at the following URI:
16
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
17
 * the PHP License and are unable to obtain it through the web, please
18
 * send a note to license@php.net so we can mail you a copy immediately.
19
 *
20
 * @category   CMS
21
 * @package    Functions
22
 * @author     Markus Niewerth <markus@weban.de>
23
 * @copyright  1997-2005 The PHP Group
24
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
25
 * @since      File available since Release 1.0.1
26
 */
27
 
28
 
29
// {{{ constants
30
 
31
	 // -------------------
32
	 // IF any put in here!
33
	 // -------------------
34
 
35
// }}}
36
// {{{ GLOBALS
37
 
38
	 // -------------------
39
	 // IF any put in here!
40
	 // -------------------
41
 
42
// }}}
43
// {{{ Functions
44
 
45
/**
46
 * Funktions Verwaltungs Modul
47
 *
48
 * This class handles the loading of any function needed by
49
 * a module e.g. Shop or any else. You easy could instance
50
 * this in the main Class of the module.
51
 * @see Shop()
52
 *
53
 * Diese Klasse behandelt das laden von Funktionen, die mit hilfe
54
 * von listFiles aufgelistet werden, oder durch �bergabe von
55
 * parametern, geladen werden k�nnen.
56
 *
57
 * @category   CMS
58
 * @package    Weban_Shop
59
 * @author     Markus Niewerth 	<markus@weban.de>
60
 * @author     Lars Tiefland 	<tiefland@weban.de>
61
 * @copyright  1997-2007 Webagentur Niewerth
62
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
63
 * @link       http://server2/intranet/3_0.txt
64
 * @see        Functions
65
 * @since      Class available since Release 1.1
66
 */
67
 
68
 
69
class Functions  {
70
 
71
	// {{{ properties
72
 
73
	/**
74
	 * Holds all file/function names.
75
	 *
76
	 * @var array
77
     */
78
	var $functions;
79
 
80
	/**
81
	 * The Shops ID number.
82
	 *
83
	 * Its a very important ID, cause the
84
	 * ID is saved in any userdefined data-
85
	 * base entry like articles a.s.o.
86
	 *
87
	 * @var int
88
     */
89
	var $shopsId;
90
 
91
	/**
92
	 * The Shop language.
93
	 *
94
	 * The Base language is DE. Note that this
95
	 * value could be mixed! But stadard is DE
96
	 *
97
	 * @var 	array
98
     */
99
	var $language;
100
 
101
	/**
102
	 * Wich function is really defined after loading?
103
	 *
104
	 * Sometimes its possible that there are
105
	 * more then one function defined in a file.
106
	 * So we have to check wich functions are
107
	 * temporary loaded while executed the factory.
108
	 *
109
	 * @var array
110
     */
111
	var $defined;
112
 
113
	/**
114
	 * Extensions to load.
115
	 *
116
	 * This parameter is needed in the file loader/includer.
117
	 *
118
	 * @var string
119
	 * @access private
120
     */
121
	var $_ext;
122
 
123
	/**
124
	 * Server OS for call_user_method.
125
	 *
126
	 * @var string
127
	 * @access private
128
     */
129
	var $_os;
130
 
131
	/**
132
	 * Helper array for defined and loaded functions.
133
	 *
134
	 * @var array
135
	 * @access private
136
     */
137
	var $_defined;
138
 
139
	/**
140
	 * Load indexer.
141
	 *
142
	 * Need in the context of navigating through the
143
	 * functions array. Helps to get the primary and
144
	 * last array key of the _defined array
145
	 * {@see $_defined}
146
	 *
147
	 * @param 	int
148
	 * @access private
149
     */
150
	var $_indexer;
151
 
152
	// }}}
153
	// {{{ Functions()
154
 
155
	function Functions ($shopsId=1, $language = __BASELANGUAGE__)
156
	{
157
		// Init needed Parameters.
158
		$this->shopsId 		= $shopsId;
159
		$this->language 	= $language;
160
		$this->_os 			= substr(PHP_OS, 0, 3);
161
		$this->functions 	= array();
162
		$this->_ext			= "php";
163
		$this->_defined		= array();
164
		$this->defined		= array();
165
		$this->_indexer 	= 0;
166
	}
167
	// }}}
168
	// {{{ factory()
169
 
170
	function factory ($_option='load')
171
	{
172
		if( strlen($_option) < 3 ) {
173
			return false;
174
		} elseif($_option == 'load') {
175
			foreach
176
					(
177
						call_user_method
178
							(
179
								"listFiles" . $this->_os ,
180
								$this,
181
								$_SESSION['INI']['systemPath'],
182
								$this->_ext
183
							)
184
						as $file
185
					)
186
			{
187
				$this->_engine ($_option, $file);
188
			}
189
			// Den Funktions- Ueberpruefungsindex resetten
190
			$this->_defined = array();
191
			return true;
192
		} else {
193
			return false;
194
		}
195
	}
196
	// }}}
197
	// {{{ _engine()
198
 
199
	function _engine ($_type, $_file)
200
	{
201
		switch ($_type) {
202
			case 'load':
203
				$this->functions[] = $_file;
204
				return $this->_load ($_file);
205
				break;
206
 
207
			case 'remove':
208
				return false;
209
				break;
210
 
211
		}
212
		return true;
213
	}
214
	// }}}
215
	// {{{ _load()
216
	function _load ($_function)
217
	{
218
		$_fname = basename ($_function,".php");
219
 
220
		if (function_exists($_fname))
221
			return false;
222
 
223
		$this->_indexer = sizeof($this->_defined) + 1;
224
		$_last = $this->_indexer - 1;
225
		$_next = $this->_indexer + 1;
226
 
227
		$tmp = get_defined_functions();
228
		$this->_defined[$this->_indexer] = $tmp['user'];
229
 
230
		require_once($_function);
231
 
232
		// Den Funktionsindex auf dem Laufenden halten...
233
		// Alle Funktionen die �ber diese Factory geladen werden,
234
		// werden in einem Array gespeichert.
235
		// FixMe: Letze geladene Funktion kann so nicht erfasst werden.
236
		// Und sollte require_once vor get_defined_functions gesetzt werden,
237
		// wird die erste Funktion nicht erfasst. L�sung: Es m�ssen zwei Arrays
238
		// nebeneinander existieren die sich durcheinander abgleichen.
239
 
240
		if (is_array($this->_defined[$_last])) {
241
			foreach(array_keys($this->_defined[$this->_indexer]) AS $elem) {
242
				if ($this->_defined[$_last][$elem] != $this->_defined[$this->_indexer][$elem]) {
243
					$this->defined[] = $this->_defined[$this->_indexer][$elem];
244
				}
245
			}
246
		}
247
		return true;
248
	}
249
	// }}}
250
	// {{{ _remove()
251
 
252
	function _remove ()
253
	{
254
		return 0;
255
	}
256
	// }}}
257
	// {{{ _add()
258
 
259
	function _add ()
260
	{
261
		return 1;
262
	}
263
	// }}}
264
	// {{{ listFilesLin()
265
 
266
	// Linux behavior
267
	function listFilesLin ($_dir, $_ext="php")
268
	{
269
		$files=array();
270
		exec("find $_dir -type f -name '*.$_ext'", $files);
271
		return $files;
272
	}
273
	// }}}
274
	// {{{ listFilesWin()
275
 
276
	// Windows behavior
277
	function listFilesWin ($_dir, $_ext=".php")
278
	{
279
		$files=array();
280
		$dir = dir($_dir);
281
		while (false !== ($fEntry = $dir->read())) {
282
		   if(ereg($_ext,$fEntry))
283
		   	$files[] = $_dir.$fEntry;
284
		}
285
		$dir->close();
286
		return $files;
287
	}
288
}
289
// }}}
290
 
291
/*
292
 * Local variables:
293
 * tab-width: 4
294
 * c-basic-offset: 4
295
 * c-hanging-comment-ender-p: nil
296
 * End:
297
 */
298
?>