Using reflection to extract the prototype of the function and class definition in the project, and comments a few days ago, a friend expected to get all the ThinkPHP function and class definition documents. Manual sorting is indeed very troublesome.
Therefore, a program is written using the php Reflection function.
Welcome!
If (isset ($ _ GET ['FN ']) new appdoc ($ _ GET ['FN']); else {$ path = 'thinkphp '; // $ path = 'phpcms'; // $ path = 'wordpress'; new appdoc (realpath ($ path);} class appdoc {private $ data = array (); private $ next = array (); function _ construct ($ path = '') {if (is_array ($ path) | is_file ($ path )) return $ this-> analysis ($ path); $ res = glob ($ path. DIRECTORY_SEPARATOR. '*', GLOB_NOSORT); $ next = array (); for ($ I = 0; $ I
Save ($ this-> load ($ fn); if ($ s) $ this-> next [$ s] = $ fn ;}$ this-> checknext (); $ s = join (PHP_EOL.PHP_EOL, $ this-> data); if (mb_check_encoding ($ s, 'utf-8') $ s = iconv ('utf-8 ', 'gbk', $ s); header ("Content-type: text/plain; charset = gbk"); echo $ s, PHP_EOL. PHP_EOL; echo 'File list '. PHP_EOL; echo join (PHP_EOL, $ res); if ($ this-> next) {echo PHP_EOL. PHP_EOL. 'residual '. PHP_EOL; print_r ($ this-> next) ;}} private function lo Ad ($ fn) {$ u = is_array ($ fn )? Http_build_query (array ('FN '=> array_values ($ fn): "fn = $ fn"; $ url = "http: // $ _ SERVER [HTTP_HOST] $ _ SERVER [PHP_SELF]? $ U "; $ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ url); curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, true); return curl_exec ($ curl );} private function checknext () {foreach ($ this-> next as $ s => $ fn) {switch (1) {case is_numeric ($ s): break; case preg_match ("/Class '(\ w +)' not found/", $ s, $ m): $ m = preg_quote ($ m [1]); foreach (preg_grep ("/class $ m/I", $ this-> data) as $ r ){; if (preg_match ('/\ s + (\ S + )/', $ R, $ m) {array_unshift ($ this-> next, $ m [1]); break ;}} $ u = http_build_query (array ('FN '=> array_values ($ this-> next ))); $ s = $ this-> save ($ this-> load ($ this-> next); $ this-> next = array (); if (empty ($ s) unset ($ this-> next [$ s]); else $ this-> next [] = $ s ;} private function save ($ s) {if (empty ($ s) | preg_match ('/~ Runtime. php/I ', $ s) return ''; if (preg_match ('#
Fatal error# ', $ S) return $ s; $ t = array (); $ ar = preg_split ("/[\ r \ n] +/", $ s ); foreach ($ ar as $ I =>$ v) {$ t [] = $ v; if ($ v = '}') {$ t = join (PHP_EOL, $ t); if (! In_array ($ t, $ this-> data) $ this-> data [] = $ t; $ t = array () ;}} return '';} private function import ($ fn) {ob_start (); if (is_array ($ fn) foreach ($ fn as $ f) include_once ($ f ); else include_once ($ fn); ob_end_clean ();} private function analysis ($ fn) {if (! Is_array ($ fn) & preg_match ('/~ Runtime. php $/I ', $ fn) return; $ last = get_defined_constants (); $ this-> import ($ fn); if ($ t = array_diff ($ last, get_defined_constants () {echo 'constants '. join (PHP_EOL. "\ t", $ t ). PHP_EOL. PHP_EOL;} foreach (get_defined_functions () ['user'] as $ name) {$ func = new ReflectionFunction ($ name); Reflection: export ($ func );} foreach (get_declared_classes () as $ name) {if (_ CLASS _ = $ name) continue; $ class = new ReflectionClass ($ name ); if ($ class-> isUserDefined () {Reflection: export ($ class) ;}} foreach (get_declared_interfaces () as $ name) {$ interfaces = new ReflectionClass ($ name); if ($ interfaces-> isUserDefined () {Reflection: export ($ interfaces );}}}}
Reply to discussion (solution)
To be honest, although this method looks like a method, it feels much worse than the manual.
The best thing is to directly look at the source code, look at the comments, parameters and so on is enough, and it is still Chinese.
Like one, bamboo has been idle recently.
Like one.
Reflection mechanisms are still very useful, and the spirit of the moderator is even better.
ThinkPHP Class Library Reference Manual:
Http://doc.thinkphp1.cn/reference.html
It seems very high-end ~
How is it like. net syntax?
I am here to learn!
Learning
Learn, like
Too difficult! I don't understand!
Are all comments found? Strong!
Points.
Strong Post name.
..
The moderator is really powerful ~~~, Take a place to learn.
Tracking and learning
Pass by, like
Points for reading the post!
Thinkphp manual is extremely good. Simple and comprehensive.
High-end.