/** * 获取当前文件include的所有文件的summary * @param FileSummary $fileSummary * @return array(fileSummarys) */ public static function getIncludeFilesDataFlows($fileSummary) { if (!is_object($fileSummary)) { return; } //1.得到include files $includeFiles = $fileSummary->getIncludeMap(); $currentFilePath = $fileSummary->getPath(); //2.foreach() files $retFileSummary = array(); foreach ($includeFiles as $rpath) { $absPath = FileUtils::getAbsPath($currentFilePath, $rpath); if (!$absPath) { continue; } // 查看是否在fileSummaryContext中 // 得到DataFlows $fileSummaryContext = FileSummaryContext::getInstance(); $ret = $fileSummaryContext->findSummaryByPath($absPath); if (is_object($ret)) { //查看此文件是否有include文件 $pRetFiles = self::getIncludeFilesDataFlows($ret); $retFileSummary = array_merge($pRetFiles, $retFileSummary); $retFileSummary = array_merge(array($ret), $retFileSummary); } else { $includeFileSummary = self::getFileSummary($absPath); if (is_object($includeFileSummary)) { $pRetFiles = self::getIncludeFilesDataFlows($includeFileSummary); $retFileSummary = array_merge($pRetFiles, $retFileSummary); $retFileSummary = array_merge(array($includeFileSummary), $retFileSummary); } } } //return all files summary //include在前的,在数组前面 return $retFileSummary; }
/** * @param 当前文件路径 $path * @param 当前文件包含文件路径集合 $require_array * @return 返回当前文件包含文件的函数集合 */ public function getRequireFileFuncs($path, $require_array) { $tempRequireFile = array(); //将文件自身添加 array_push($tempRequireFile, $path); //补全路径 $currentDir = dirname($path); global $project_path; foreach ($require_array as $filepath) { $absPath = FileUtils::getAbsPath($path, $filepath); if ($absPath) { array_push($tempRequireFile, $absPath); } } $records = array(); //不能定义同名类和函数,不同类方法可以相同 //寻找相应的method foreach ($this->records as $record) { if (in_array($record->path, $tempRequireFile)) { array_push($records, $record); } } return $records; }