├── .DS_Store ├── .gitignore ├── composer.json ├── config └── config.php ├── src ├── reflection │ ├── DoComment.php │ └── ReflectionClass.php ├── Files.php ├── Directory.php ├── ClassInfo.php └── NotesPHP.php ├── test └── config.php └── composer.lock /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctfang/NotesPHP/master/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /public/storage 3 | /storage/*.key 4 | /vendor 5 | /.idea 6 | Homestead.json 7 | Homestead.yaml 8 | .env 9 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "selden1992/NotesPHP", 3 | "description": "php-注释和类", 4 | "authors": [ 5 | { 6 | "name": "cyz", 7 | "email": "2206582181@qq.com" 8 | } 9 | ], 10 | "license": "Apache-2.0", 11 | "require": { 12 | "php": ">=5.4.0" 13 | }, 14 | "autoload": { 15 | "psr-4": { 16 | "NotesPHP\\": "src/" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | dirname(__DIR__), 11 | // 结果保持目录 12 | 'save_path'=>dirname(__DIR__).'/runtime/class.json', 13 | // 搜索文件的扩展名 14 | 'extension'=>'php', 15 | // 保持的格式 16 | 'save_type'=>'array' 17 | ]; -------------------------------------------------------------------------------- /src/reflection/DoComment.php: -------------------------------------------------------------------------------- 1 | docomment = $string; 23 | } 24 | } -------------------------------------------------------------------------------- /test/config.php: -------------------------------------------------------------------------------- 1 | "; 7 | foreach ($data as $value){ 8 | print_r($value); 9 | } 10 | echo ""; 11 | } 12 | \NotesPHP\NotesPHP::setConfig([ 13 | 'base_path'=>dirname(__DIR__), 14 | 'save_path'=>dirname(__DIR__).'/runtime/class.php', 15 | 'extension'=>'php', 16 | 'save_type'=>'array', 17 | ]); 18 | 19 | \NotesPHP\NotesPHP::build(); 20 | 21 | p(\NotesPHP\NotesPHP::getConfig()); 22 | 23 | p($str = include '../runtime/class.php'); 24 | 25 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "4421dd55f0d932e43a05aed8d41c795d", 8 | "packages": [], 9 | "packages-dev": [], 10 | "aliases": [], 11 | "minimum-stability": "stable", 12 | "stability-flags": [], 13 | "prefer-stable": false, 14 | "prefer-lowest": false, 15 | "platform": { 16 | "php": ">=5.4.0" 17 | }, 18 | "platform-dev": [] 19 | } 20 | -------------------------------------------------------------------------------- /src/Files.php: -------------------------------------------------------------------------------- 1 | [],'file_list'=>[]]; 24 | $dir = $files = []; 25 | $ext = NotesPHP::getConfig('extension'); 26 | $extCt = strlen($ext); 27 | foreach ($lists as $key => $name) { 28 | if (in_array($name, ['.', '..']) ) { 29 | unset($lists[$key]); 30 | } elseif( is_dir($dirPath = $path . '/' . $name) ) { 31 | $dir[] = $dirPath; 32 | }elseif( substr($dirPath,-$extCt)==$ext ){ 33 | $files[] = $dirPath; 34 | } 35 | } 36 | return ['dir_list'=>$dir,'file_list'=>$files]; 37 | } 38 | 39 | /** 40 | * 获取目录树 41 | * 42 | * @param $path 43 | * @return array 44 | */ 45 | public static function tree($path) 46 | { 47 | $list = []; 48 | 49 | if (is_dir($path)) { 50 | $temp = self::dirList($path); 51 | $list['dir_path'] = $path; 52 | $list['file_list'] = $temp['file_list']; 53 | $list['dir_child'] = []; 54 | foreach ($temp['dir_list'] as $item) { 55 | $list['dir_child'][] = self::tree($item); 56 | } 57 | } 58 | return $list; 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /src/reflection/ReflectionClass.php: -------------------------------------------------------------------------------- 1 | reflection = new \ReflectionClass($className); 28 | } 29 | 30 | /** 31 | * 获取文档注释 32 | * 33 | * @return string 34 | */ 35 | public function getDocComment() 36 | { 37 | return $this->reflection->getDocComment(); 38 | } 39 | 40 | /** 41 | * 获取类数组 42 | * 43 | * @return \ReflectionMethod[] 44 | */ 45 | public function getMethods() 46 | { 47 | return $this->reflection->getMethods(); 48 | } 49 | 50 | /** 51 | * 获取方法反射对象 52 | * 53 | * @param $name 54 | * @return \ReflectionMethod 55 | */ 56 | public function getMethod($name) 57 | { 58 | return $this->reflection->getMethod($name); 59 | } 60 | 61 | /** 62 | * 获取类型 63 | * 64 | * @param $class 65 | * @return string 66 | */ 67 | public function getProperty($class) 68 | { 69 | return !$class->isPublic() ? !$class->isPrivate() ? $class->isProtected() ?: 'protected' : 'private' : 'public'; 70 | } 71 | 72 | /** 73 | * 获取函数参数 74 | * 75 | * @param $class 76 | * @return array 77 | */ 78 | public function getParameters($class) 79 | { 80 | $parameter_temp = $class->getParameters(); 81 | if ($parameter_temp) { 82 | foreach ($parameter_temp as $parameter) { 83 | $fucntion[] = $parameter->name; 84 | } 85 | } else { 86 | $fucntion = []; 87 | } 88 | return $fucntion; 89 | } 90 | } -------------------------------------------------------------------------------- /src/ClassInfo.php: -------------------------------------------------------------------------------- 1 | getMethods(); 38 | $arrClass['name'] = $nameSpace . '\\' . $arrPath['filename']; 39 | $arrClass['doccomment'] = $refle->getDocComment(); 40 | foreach ($arr as $item) { 41 | $funReflection = $refle->getMethod($item->name); 42 | $fucntion['name'] = $item->name; 43 | $fucntion['property'] = $refle->getProperty($funReflection); 44 | $fucntion['parameters'] = $refle->getParameters($funReflection); 45 | $fucntion['doccomment'] = $funReflection->getDocComment(); 46 | $arrClass['function'][] = $fucntion; 47 | } 48 | return $arrClass; 49 | } 50 | return false; 51 | } 52 | 53 | 54 | /** 55 | * 获取目录命名空间 56 | * 57 | * @param $dir 58 | * @param $fileName 59 | */ 60 | private static function getNameSpace($dir, $fileName) 61 | { 62 | if (!isset(self::$_namespace[$dir])) { 63 | $string = file_get_contents($fileName); 64 | $string = substr($string, 0, strpos($string, ';')); 65 | $string = '\\' . end(explode(' ', $string)); 66 | self::$_namespace[$dir] = $string; 67 | } 68 | return self::$_namespace[$dir]; 69 | } 70 | } -------------------------------------------------------------------------------- /src/NotesPHP.php: -------------------------------------------------------------------------------- 1 |