get_defined_functions ()
Maar als ik een classe include via een __autoload functie die ik zelf heb geschreven weet ik niet hoe ik nou alle functie's eruit kan halen? Of weet iemand anders daar een slim trucje voor?
BVD,
Marcel
ik ben al een stapje verder uiteindelijk is het mij toch gelukt om alle methoden uit een class the halen, maar nou moet ik de argumenten nog hebben. Iemand idee'en?
Misschien kan je posten wat je tot nu toe hebt. Kan ons ook op ideeën brengen.
Code (php)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php
/********class structure*************************
*
* userclass
* -logincheck
* -loginform
* -logout
* directoryclass
* -rmdir
* -editdir
* -mkdir
* fileclass
* -rmfile
* -editfile
* -mkfile
* builder
* -__construct
* -readclasses
* -stringcheck
* -numbers
* -dir
* -file
*
************************************************/
// change this, if this code isn't "higher" than ALL classfiles
define("CLASS_DIR", dirname(__FILE__));
class builder{
public $error = 0;
public function __construct(){
$this->searchclasses("/classes");
}
/**
* search for clases to load
*
* @uses __autoload
* @uses dir()
* @uses getfunctions()
* @param $sub string
*/
public function searchclasses($sub = "/"){
$classes = array();
$classes = $this->file(CLASS_DIR.$sub);
foreach ( $classes AS $value){
$functions = array();
$class = array();
$this->__autoload($value);
$functions = $this->getfunctions(CLASS_DIR.$sub."/".$value);
foreach ($functions AS $value2){
$class[ $value2 ] = $this->get_method_arg($value, $value2);
var_dump($class);
}
}
}
public function getfunctions($file){
/** class name is name.class.php*/
$arr = file($file);
foreach ($arr as $line)
{
if (ereg ('function ([_A-Za-z0-9]+)', $line, $regs))
$arr_methods[] = $regs[1];
}
return $arr_methods;
}
public function get_method_arg($class, $function){
$exp = explode(".", $class);
return func_num_args( $exp[0]);
}
/**
* autoload classes (no need to include them one by one)
*
* @uses classFolder()
* @param $className string
*/
public function __autoload($className) {
$folder = $this->classFolder($className);
if(file_exists($folder.$className)){
/*MAMP BUG*/
$folder = str_replace("/Applications/MAMP/htdocs/", "", $folder);
$path = $folder.$className;
include($folder.$className);
}
}
/**
* search for folders and subfolders with classes
*
* @param $className string
* @param $sub string[optional]
* @return string
*/
function classFolder($className, $sub = "/") {
$dir = dir(CLASS_DIR.$sub);
if(file_exists(CLASS_DIR.$sub.$className))
return CLASS_DIR.$sub;
while(false !== ($folder = $dir->read())) {
if($folder != "." && $folder != ".." && $folder != ".DS_Store") {
if(is_dir(CLASS_DIR.$sub.$folder)) {
$subFolder = $this->classFolder($className, $sub.$folder."/");
if($subFolder) return $subFolder;
}
}
}
$dir->close();
return false;
}
public function stringcheck(){
}
public function numbers(){
}
public function dir($dir){
/* This function read all dir's */
$array = array();
if($handle = opendir( $dir ) )
{
while ( ( $file = readdir( $handle ) ) !== false)
{
if ( is_dir( $dir.$file ) )
{
array_push( $array, $dir.$file);
}
}
}
else
{
$this->error = 2;
$this->print_error();
}
@closedir( $dir );
return $array;
}
public function file($dir){
if( $handle = opendir ( $dir ) )
{
$files = array();
while ( ( $file = readdir( $handle ) ) !== FALSE )
{
if($file != '..' && $file != "." && $file != ".DS_Store"){
array_push($files, $file);
}
}
}
else
{
$this->error = 3;
$this->print_error();
}
@closedir( $dir );
return $files;
}
public function print_error(){
echo $this->error;
exit();
}
}
$obj = new builder();
?>
/********class structure*************************
*
* userclass
* -logincheck
* -loginform
* -logout
* directoryclass
* -rmdir
* -editdir
* -mkdir
* fileclass
* -rmfile
* -editfile
* -mkfile
* builder
* -__construct
* -readclasses
* -stringcheck
* -numbers
* -dir
* -file
*
************************************************/
// change this, if this code isn't "higher" than ALL classfiles
define("CLASS_DIR", dirname(__FILE__));
class builder{
public $error = 0;
public function __construct(){
$this->searchclasses("/classes");
}
/**
* search for clases to load
*
* @uses __autoload
* @uses dir()
* @uses getfunctions()
* @param $sub string
*/
public function searchclasses($sub = "/"){
$classes = array();
$classes = $this->file(CLASS_DIR.$sub);
foreach ( $classes AS $value){
$functions = array();
$class = array();
$this->__autoload($value);
$functions = $this->getfunctions(CLASS_DIR.$sub."/".$value);
foreach ($functions AS $value2){
$class[ $value2 ] = $this->get_method_arg($value, $value2);
var_dump($class);
}
}
}
public function getfunctions($file){
/** class name is name.class.php*/
$arr = file($file);
foreach ($arr as $line)
{
if (ereg ('function ([_A-Za-z0-9]+)', $line, $regs))
$arr_methods[] = $regs[1];
}
return $arr_methods;
}
public function get_method_arg($class, $function){
$exp = explode(".", $class);
return func_num_args( $exp[0]);
}
/**
* autoload classes (no need to include them one by one)
*
* @uses classFolder()
* @param $className string
*/
public function __autoload($className) {
$folder = $this->classFolder($className);
if(file_exists($folder.$className)){
/*MAMP BUG*/
$folder = str_replace("/Applications/MAMP/htdocs/", "", $folder);
$path = $folder.$className;
include($folder.$className);
}
}
/**
* search for folders and subfolders with classes
*
* @param $className string
* @param $sub string[optional]
* @return string
*/
function classFolder($className, $sub = "/") {
$dir = dir(CLASS_DIR.$sub);
if(file_exists(CLASS_DIR.$sub.$className))
return CLASS_DIR.$sub;
while(false !== ($folder = $dir->read())) {
if($folder != "." && $folder != ".." && $folder != ".DS_Store") {
if(is_dir(CLASS_DIR.$sub.$folder)) {
$subFolder = $this->classFolder($className, $sub.$folder."/");
if($subFolder) return $subFolder;
}
}
}
$dir->close();
return false;
}
public function stringcheck(){
}
public function numbers(){
}
public function dir($dir){
/* This function read all dir's */
$array = array();
if($handle = opendir( $dir ) )
{
while ( ( $file = readdir( $handle ) ) !== false)
{
if ( is_dir( $dir.$file ) )
{
array_push( $array, $dir.$file);
}
}
}
else
{
$this->error = 2;
$this->print_error();
}
@closedir( $dir );
return $array;
}
public function file($dir){
if( $handle = opendir ( $dir ) )
{
$files = array();
while ( ( $file = readdir( $handle ) ) !== FALSE )
{
if($file != '..' && $file != "." && $file != ".DS_Store"){
array_push($files, $file);
}
}
}
else
{
$this->error = 3;
$this->print_error();
}
@closedir( $dir );
return $files;
}
public function print_error(){
echo $this->error;
exit();
}
}
$obj = new builder();
?>
er zitten nog wat var_dump en echo's tussen maar dat is alleen maar voor het debuggen
Edit:
De output is ook wel handig dacht ik zo(A) array(1) { ["rmdir"]=> int(2) } array(2) { ["rmdir"]=> int(2) ["mkdir"]=> int(2) } array(3) { ["rmdir"]=> int(2) ["mkdir"]=> int(2) ["editdir"]=> int(2) } array(1) { ["rmfile"]=> int(2) } array(2) { ["rmfile"]=> int(2) ["mkfile"]=> int(2) } array(3) { ["rmfile"]=> int(2) ["mkfile"]=> int(2) ["editfile"]=> int(2) } array(1) { ["ReadMessage"]=> int(2) } array(2) { ["ReadMessage"]=> int(2) ["EditMessage"]=> int(2) } array(3) { ["ReadMessage"]=> int(2) ["EditMessage"]=> int(2) ["AddMessage"]=> int(2) } array(4) { ["ReadMessage"]=> int(2) ["EditMessage"]=> int(2) ["AddMessage"]=> int(2) ["DeleteMessage"]=> int(2) } array(5) { ["ReadMessage"]=> int(2) ["EditMessage"]=> int(2) ["AddMessage"]=> int(2) ["DeleteMessage"]=> int(2) ["phphighlite_replace"]=> int(2) } array(6) { ["ReadMessage"]=> int(2) ["EditMessage"]=> int(2) ["AddMessage"]=> int(2) ["DeleteMessage"]=> int(2) ["phphighlite_replace"]=> int(2) ["phphighlite"]=> int(2) } array(7) { ["ReadMessage"]=> int(2) ["EditMessage"]=> int(2) ["AddMessage"]=> int(2) ["DeleteMessage"]=> int(2) ["phphighlite_replace"]=> int(2) ["phphighlite"]=> int(2) ["ubb_code"]=> int(2) }
ik heb 3 classes, GuestBook deze heeft functie's zonder argumenten, File deze heeft file handling methoden, en dus ook argumenten, directory class heeft ook argumenten, maar hij weergeeft overal int(2)
ik heb 3 classes, GuestBook deze heeft functie's zonder argumenten, File deze heeft file handling methoden, en dus ook argumenten, directory class heeft ook argumenten, maar hij weergeeft overal int(2)
Gewijzigd op 01/01/1970 01:00:00 door Cyberboy fdsafds
function test($1,$2)
eenphpfunctie(test) die een array returnd met [0]=>$1, [1]=>$2
BVD!
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
<?php
$class = $_POST['class'];
$method = $_POST['method'];
$object = new $class();
if(function_exists(array($object, $method)) {
$object->$method();
}
?>
$class = $_POST['class'];
$method = $_POST['method'];
$object = new $class();
if(function_exists(array($object, $method)) {
$object->$method();
}
?>
En een lijst van alle methods kan je wel via de Reflection API krijgen, of gewoon get_class_methods.
Hij leest keurig alle bestanden uit naar classes en de functie's in de classes.
Dan zou hij moeten kijken of een classe en functie bestaat en dan aanroepen als dat zo is.
En bij het laatst deel blijf ik hangen, ojah en wie heeft er een betere oplossing om naar de functie's te zoeken in de classe dan een reggex?
Zover ben ik tot nu toe:
Code (php)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/********class structure*************************
*
* userclass
* -logincheck
* -loginform
* -logout
* directoryclass
* -rmdir
* -editdir
* -mkdir
* fileclass
* -rmfile
* -editfile
* -mkfile
* builder
* -__construct
* -readclasses
* -stringcheck
* -numbers
* -dir
* -file
*
************************************************/
// change this, if this code isn't "higher" than ALL classfiles
define("CLASS_DIR", dirname(__FILE__));
class builder{
public $error = 0;
public $classfunc = array();
public $rootpath ;
/**
* __construct search classes and call the method if the method is called
* @uses searchclasses
*
*/
public function __construct($rootpath){
$this->rootpath = $rootpath;
$this-> classfunc = $this->searchclasses("/classes");
$class = $_GET['class'];
$function = $_GET['func'];
if(in_array($function, $this->classfunc[$class])){
/*roep de functie aan uit de juiste classe*/
}
}
/**
* search for clases to load
*
* @uses __autoload
* @uses dir()
* @uses getfunctions()
* @param $sub string
*/
public function searchclasses($sub = "/"){
$classes = array();
$classes = $this->file(CLASS_DIR.$sub);
$class = array();
foreach ( $classes AS $value){
$functions = array();
$exp = explode(".", $value);
$this->__autoload($value);
$functions = $this->getfunctions(CLASS_DIR.$sub."/".$value);
$class[$exp[0]]= $functions;
}
return $class;
}
/**
* searching for methods names
*
* @param $file
* @return methods
*/
public function getfunctions($file){
/** class name is name.class.php*/
$arr = file($file);
foreach ($arr as $line)
{
if (ereg ('function ([_A-Za-z0-9]+)', $line, $regs))
$arr_methods[] = $regs[1];
}
return $arr_methods;
}
/**
* autoload classes (no need to include them one by one)
*
* @uses classFolder()
* @param $className string
*/
public function __autoload($className) {
if(file_exists("classes/".$className)){
$path = $this->rootpath."classes/".$className;
include($path);
}
}
/**
* search for folders and subfolders with classes
*
* @param $className string
* @param $sub string[optional]
* @return string
*/
function classFolder($className, $sub = "/") {
$dir = dir(CLASS_DIR.$sub);
if(file_exists(CLASS_DIR.$sub.$className))
return CLASS_DIR.$sub;
while(false !== ($folder = $dir->read())) {
if($folder != "." && $folder != ".." && $folder != ".DS_Store") {
if(is_dir(CLASS_DIR.$sub.$folder)) {
$subFolder = $this->classFolder($className, $sub.$folder."/");
if($subFolder) return $subFolder;
}
}
}
$dir->close();
return false;
}
public function stringcheck(){
}
public function numbers(){
}
/**
* scans the directory for subdirectories
*
* @param $dir
* @return array with directories
*/
public function dir($dir){
/* This function read all dir's */
$array = array();
if($handle = opendir( $dir ) )
{
while ( ( $file = readdir( $handle ) ) !== false)
{
if ( is_dir( $dir.$file ) )
{
array_push( $array, $dir.$file);
}
}
}
else
{
$this->error = 2;
$this->print_error();
}
@closedir( $dir );
return $array;
}
/**
* looking for files in the directory
*
* @param $dir
* @return array with files
*/
public function file($dir){
if( $handle = opendir ( $dir ) )
{
$files = array();
while ( ( $file = readdir( $handle ) ) !== FALSE )
{
if($file != '..' && $file != "." && $file != ".DS_Store"){
array_push($files, $file);
}
}
}
else
{
$this->error = 3;
$this->print_error();
}
@closedir( $dir );
return $files;
}
/**
* prints the error number
*
*/
public function print_error(){
echo $this->error;
exit();
}
}
$obj = new builder('/websitebuilder06/admin/');
?>
/********class structure*************************
*
* userclass
* -logincheck
* -loginform
* -logout
* directoryclass
* -rmdir
* -editdir
* -mkdir
* fileclass
* -rmfile
* -editfile
* -mkfile
* builder
* -__construct
* -readclasses
* -stringcheck
* -numbers
* -dir
* -file
*
************************************************/
// change this, if this code isn't "higher" than ALL classfiles
define("CLASS_DIR", dirname(__FILE__));
class builder{
public $error = 0;
public $classfunc = array();
public $rootpath ;
/**
* __construct search classes and call the method if the method is called
* @uses searchclasses
*
*/
public function __construct($rootpath){
$this->rootpath = $rootpath;
$this-> classfunc = $this->searchclasses("/classes");
$class = $_GET['class'];
$function = $_GET['func'];
if(in_array($function, $this->classfunc[$class])){
/*roep de functie aan uit de juiste classe*/
}
}
/**
* search for clases to load
*
* @uses __autoload
* @uses dir()
* @uses getfunctions()
* @param $sub string
*/
public function searchclasses($sub = "/"){
$classes = array();
$classes = $this->file(CLASS_DIR.$sub);
$class = array();
foreach ( $classes AS $value){
$functions = array();
$exp = explode(".", $value);
$this->__autoload($value);
$functions = $this->getfunctions(CLASS_DIR.$sub."/".$value);
$class[$exp[0]]= $functions;
}
return $class;
}
/**
* searching for methods names
*
* @param $file
* @return methods
*/
public function getfunctions($file){
/** class name is name.class.php*/
$arr = file($file);
foreach ($arr as $line)
{
if (ereg ('function ([_A-Za-z0-9]+)', $line, $regs))
$arr_methods[] = $regs[1];
}
return $arr_methods;
}
/**
* autoload classes (no need to include them one by one)
*
* @uses classFolder()
* @param $className string
*/
public function __autoload($className) {
if(file_exists("classes/".$className)){
$path = $this->rootpath."classes/".$className;
include($path);
}
}
/**
* search for folders and subfolders with classes
*
* @param $className string
* @param $sub string[optional]
* @return string
*/
function classFolder($className, $sub = "/") {
$dir = dir(CLASS_DIR.$sub);
if(file_exists(CLASS_DIR.$sub.$className))
return CLASS_DIR.$sub;
while(false !== ($folder = $dir->read())) {
if($folder != "." && $folder != ".." && $folder != ".DS_Store") {
if(is_dir(CLASS_DIR.$sub.$folder)) {
$subFolder = $this->classFolder($className, $sub.$folder."/");
if($subFolder) return $subFolder;
}
}
}
$dir->close();
return false;
}
public function stringcheck(){
}
public function numbers(){
}
/**
* scans the directory for subdirectories
*
* @param $dir
* @return array with directories
*/
public function dir($dir){
/* This function read all dir's */
$array = array();
if($handle = opendir( $dir ) )
{
while ( ( $file = readdir( $handle ) ) !== false)
{
if ( is_dir( $dir.$file ) )
{
array_push( $array, $dir.$file);
}
}
}
else
{
$this->error = 2;
$this->print_error();
}
@closedir( $dir );
return $array;
}
/**
* looking for files in the directory
*
* @param $dir
* @return array with files
*/
public function file($dir){
if( $handle = opendir ( $dir ) )
{
$files = array();
while ( ( $file = readdir( $handle ) ) !== FALSE )
{
if($file != '..' && $file != "." && $file != ".DS_Store"){
array_push($files, $file);
}
}
}
else
{
$this->error = 3;
$this->print_error();
}
@closedir( $dir );
return $files;
}
/**
* prints the error number
*
*/
public function print_error(){
echo $this->error;
exit();
}
}
$obj = new builder('/websitebuilder06/admin/');
?>