-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasshole
41 lines (41 loc) · 1.18 KB
/
asshole
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
<?php
require(__DIR__ . '/vendor/autoload.php');
$params = $argv;
//TODO递归遍历算法类文件
$files=array();
$dirList=scandir(__DIR__.'/src');
if(empty($dirList)){
return null;
}
foreach($dirList as $file){
if($file!='..' && $file!='.'){
if(is_dir(__DIR__.'/src'.'/'.$file)){
$files[]=scanDir($dirList.'/'.$file);
}else{
if(preg_match("/\.(php)$/i",$file)){
$files[]=basename($file,'.php');
}
}
}
}
//列出可执行的算法及其注释
if (!isset($params[1])) {
print_r('可选算法如下:'.PHP_EOL);
foreach ($files as $file) {
$className='jiawei\algorithm'.'\\'.$file;
$class=new ReflectionClass($className);
$methods=$class->getMethods();
foreach($methods as $method){
$methodComment=$class->getMethod($method->name)->getDocComment();
print_r($file.'/'.$method->name.PHP_EOL.str_replace('/','',str_replace('*','',preg_replace('/\s+/u','',$methodComment))).PHP_EOL);
}
}
exit(1);
}
//通过命令行传入的参数执行指定的方法
$console = explode('/',$params[1]);
$className = 'jiawei\algorithm'.'\\'.$console[0];
$obj = new $className();
$methodName = $console[1];
//TODO怎么把方法的参数提示到命令行?
var_dump($obj->$methodName());