Created
May 27, 2020 11:04
-
-
Save portapipe/ef9340b00555932fdd37cc1e41aad554 to your computer and use it in GitHub Desktop.
Function to create list of class and functions of a list of given files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is an example for Codeigniter (v3 at the moment but it should work with any version)! | |
//Just copy and paste the code below into a controller you have | |
//Do some fine-tuning and choose the files you want to scan! | |
//... | |
//Here the class you want to put the function in | |
public function docs(){ | |
echo '<h2>DOCS</h2>'; | |
$files = array( | |
"Controllers"=>"application/controllers", | |
"Models"=>"application/models", | |
"Libraries"=>"application/libraries", | |
"Third Party"=>"application/third_party" | |
); | |
foreach($files as $tipo=>$dir){ | |
try{ | |
echo "<hr/><h3>Analisi $tipo</h3><hr/>"; | |
$class_files = scandir($dir); | |
unset($class_files[0]); | |
unset($class_files[1]); | |
echo '<p><b>Linea '.__LINE__.'</b></p><pre>';print_r($class_files);echo '</pre><p><i>File: '.__FILE__.'</i></p>'; | |
foreach($class_files as $file_og){ | |
$file = explode(".", $file_og); | |
if(@$file[1]!="php") continue; | |
require_once "./$dir/$file_og"; | |
echo "<h4>Class $file[0]</h4><ul>"; | |
foreach($this->get_this_class_methods($file[0]) as $v){ | |
echo "<li>$v ( "; | |
$r = new ReflectionMethod($file[0], $v); | |
$params = $r->getParameters(); | |
$parametri = []; | |
foreach ($params as $param) { | |
//$param is an instance of ReflectionParameter | |
try{ | |
$default = $param->getDefaultValue(); | |
}catch(Exception $e){ | |
$default = '""'; | |
} | |
$type = gettype($default); | |
if($type=="NULL") | |
$type = ""; | |
if(is_string($default)){ | |
$default = "'$default'"; | |
}else if(is_array($default)){ | |
$default = json_encode($default); | |
}else if(is_object($default)){ | |
$default = json_encode($default); | |
}else if(is_bool($default)){ | |
$default = ($default===true?"true":"false"); | |
} | |
$parametri[] = "<b>$".$param->getName()."</b><i>".($param->isOptional()?"=($type)<b>".$default."</b>":"")."</i>"; | |
} | |
echo implode(" , ", $parametri); | |
echo " )</li>"; | |
} | |
echo "</ul>"; | |
} | |
}catch(Exception $e){ | |
echo "<h4>Problema con file $file_og</h4>"; | |
} | |
} | |
} | |
function get_this_class_methods($class){ | |
try{ | |
$array1 = get_class_methods($class); | |
if($parent_class = get_parent_class($class)){ | |
$array2 = get_class_methods($parent_class); | |
$array3 = array_diff($array1, $array2); | |
}else{ | |
$array3 = $array1; | |
} | |
return($array3); | |
}catch(Exception $e){ | |
} | |
} | |
//Here the rest of the file | |
//... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment