Thứ Hai, 1 tháng 7, 2013

List Function in file

 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
    input[type="text"]{
        width:400px;
    }
    textarea{
        width:400px;
        height:400px;
    }
</style>
</head>

<body>

<form>
    <div>Url: <input type="text" name="url"  value="<?php echo $_GET["url"] ; ?>"/></div>
    <div>list: <textarea name="list"><?php echo $_GET["list"] ; ?></textarea></div>
    <div><input type="submit" /></div>
</form>
<?php

if($_GET["url"]){
    $string_file=str_replace(" ","",$_GET["url"]);
    echo "<h3>".$string_file."</h3>";  
    $data_f=get_defined_functions_in_file($string_file);
    for($i=0;$i<sizeof($data_f);$i++){
        echo "<div>".$data_f[$i]."</div>";
    }
}
if($_GET["list"]){
    $array_l=explode(",",str_replace(" ","",$_GET["list"]));
    for($j=0;$j<sizeof($array_l);$j++){
        $string_file=$array_l[$j];
        echo "<h3>".$string_file."</h3>";  
        $data_f=get_defined_functions_in_file($string_file);
        for($i=0;$i<sizeof($data_f);$i++){
            echo "<div>".$data_f[$i]."</div>";
        }
    }
}
function get_defined_functions_in_file($file) {
    $source = file_get_contents($file);
    $tokens = token_get_all($source);

    $functions = array();
    $nextStringIsFunc = false;
    $inClass = false;
    $bracesCount = 0;

    foreach($tokens as $token) {
        switch($token[0]) {
            case T_CLASS:
                $inClass = true;
                break;
            case T_FUNCTION:
                if(!$inClass) $nextStringIsFunc = true;
                break;

            case T_STRING:
                if($nextStringIsFunc) {
                    $nextStringIsFunc = false;
                    $functions[] = $token[1];
                }
                break;

            // Anonymous functions
            case '(':
            case ';':
                $nextStringIsFunc = false;
                break;

            // Exclude Classes
            case '{':
                if($inClass) $bracesCount++;
                break;

            case '}':
                if($inClass) {
                    $bracesCount--;
                    if($bracesCount === 0) $inClass = false;
                }
                break;
        }
    }

    return $functions;
}
 ?>
</body>
</html>

Không có nhận xét nào: