Use reflection to extract functions and classes in a project to define prototypes and annotations

Source: Internet
Author: User
Tags glob
A few days ago a friend wanted to get thinkphp all the functions and class definitions of the document. It's really a lot of trouble to sort it out manually.
To do this, a program is written using the reflection function of PHP.
Welcome to shoot Bricks!
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. ' Remnants '.  Php_eol;print_r ($this->next);} } Private Function Load ($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_ma TCH ("/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 (); The Private Function analysis ($FN) {if (! Is_array ($FN) && preg_match ('/~runtime.php$/i ', $FN)) return; $last = Get_d Efined_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)

Seriously, this way, though, looks like a whole lot of ways, but it feels far worse than the manual.
The best or direct look at the source code, look at the comments, parameters and so on is enough, but also Chinese.

Like one, the owner of the recent very busy AH.

Praise one.

Reflection mechanism is still very useful, the spirit of moderator is better.

thinkphp Class Library Reference manual:
Http://doc.thinkphp.cn/reference.html

It looks like a very high end.

Why is that like. NET syntax

I'm here to study!

Learning

Learn to praise a

It's too hard! I didn't even see it!

The notes are all checked out? Tough!

Take a minute.

Strong stickers.

Well, I mean, I can't read it.

Moderator really powerful, worship in ~ ~ ~, occupy a position to learn.

Track Learning

Pass by, praise a

Take a look at the points!

The thinkphp handbook is extremely good. Simple and comprehensive.

High.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.