-
Notifications
You must be signed in to change notification settings - Fork 1
/
Y2J.php
135 lines (133 loc) · 2.73 KB
/
Y2J.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
<?php
$yaf=[
'Application',
'Bootstrap_Abstract',
'Dispatcher',
'Loader',
'Request_Abstract',
'Request_Http',
'Request_Simple',
'Response_Abstract',
'Response_Http',
'Response_Cli',
'Controller_Abstract',
'Action_Abstract',
'Config_Abstract',
'Config_Ini',
'Config_Simple',
'View_Simple',
'Router',
'Route_Static',
'Route_Simple',
'Route_Supervar',
'Route_Rewrite',
'Route_Regex',
'Route_Map',
'Plugin_Abstract',
'Registry',
'Session',
'Exception',
'Exception_StartupError',
'Exception_RouterFailed',
'Exception_DispatchFailed',
'Exception_LoadFailed',
'Exception_LoadFailed_Module',
'Exception_LoadFailed_Controller',
'Exception_LoadFailed_Action',
'Exception_LoadFailed_View',
'Exception_TypeError',
];
$jaf=[];
foreach($yaf as $cs){
$mc=new ReflectionClass('Yaf_'.$cs);
$jaf[$cs]=[];
$class=($mc->isFinal()?'final ':'').($mc->isAbstract()?'abstract ':''). 'class ';
$p=str_replace('Yaf_','',$mc->getParentClass()?$mc->getParentClass()->name:'');
$jaf[$cs]['extends']=$p;
$p=($p?' extends '.$p:'');
$if=[];
foreach($mc->getInterfaces() as $i){
$if[]=$i->name;
}
$if=implode(',',$if);
$if=$if?' implements '.$if:'';
$jaf[$cs]['class']=$class.str_replace('Yaf_','',$cs) . $p . $if;
pre($jaf[$cs]['class'].' {');
$as=$mc->getProperties();
foreach ($as as $a){
$str=ReflectionProperty::export($a->class,$a->name,1);
$str="\t".trim(fixProperty($str));
$jaf[$cs][]=$str;
pre($str);
}
$as=$mc->getMethods();
foreach ($as as $a){
$str=ReflectionMethod::export($a->class,$a->name,1);
$str="\t".trim(fixMethod($str));
$jaf[$cs][]=$str;
pre($str);
}
pre('}');
}
echo '=================';
foreach($jaf as $c=>&$v){
$ex=$v['extends'];
$p=$jaf;
while($ex){
//method_exists
if(isset($jaf[$ex]) and $jaf[$ex]['extends']!=$ex) {
$p=$jaf[$ex];
$ex=$p['extends'];
$v=array_diff($v,$p);
}else{
foreach ($v as $k=>$mn){
if($k!='class' and $k!='extends' and method_exists($ex,$mn))
unset($v[$k]);
}
break;
}
}
if($v['extends']){
//$v=array_diff($v,$jaf[$v['extends']]);
}
pre($v['class']." {\n".implode("\n",array_slice($v,2))."\n}\n");
}
function fixProperty($str){
return preg_replace(array('#<.+>#','#.*\[(.*)\]#'),array('','$1;'),$str);
}
function fixMethod($str){
return preg_replace(
array(
'#(<.+>)#',
'#Method \[(.*)\] \{([^\{]*\{)?\n#m',
'|Parameter #.+\[.*(\$\S*)(\s*\]\n)|',
'|\}\s*}|',
'|(,\s+\))|',
'|(\S+)\s+|',
'|(, \$\.\.\.)|',
'|\(\}|','| method |'
),
array(
'',
'$1(',
'$1,',
'){}',
')',
'$1 ',
' /* $1 */',
'(){}',' function '
),$str);
}
/**
* 调试用pre输出
*/
function pre()
{
$args=func_num_args()?func_get_args():array($GLOBALS);
echo '<pre>';
foreach ($args as $value) {
echo PHP_EOL;
echo htmlspecialchars( print_r($value,1) );
}
echo '</pre>';
}