hackpack/hack-class-scanner
最新稳定版本:2.0.1
Composer 安装命令:
composer require hackpack/hack-class-scanner
包简介
Recursively scan a directory for hack classes and/or interfaces
README 文档
README
A class that recursively scans a directory for Hack definitions of:
- Classes
- Interfaces
- Traits
- Enums
- Type definitions
- NewType definitions
- Functions
- Constants
Installation
Install Composer then use the following in your project directory:
composer require hackpack/hack-class-scanner
Use
To use the class, simply instantiate it with a set of files/base directories to scan and a set of files/directories to ignore.
use HackPack\Scanner\ClassScanner; use HackPack\Scanner\NameType; $scanner = new ClassScanner( Set{‘directory/to/scan’, ‘other/directory’, ‘file/to/scan.txt’}, Set{‘other/directory/to/ignore’, ‘other/directory/file_to_ignore.txt’} ); $classes = $scanner->getNameToFileMap(NameType::className); $interfaces = $scanner->getNameToFileMap(NameType::interfaceName); $traits = $scanner->getNameToFileMap(NameType::traitName); $enums = $scanner->getNameToFileMap(NameType::enumName); $types = $scanner->getNameToFileMap(NameType::typeName); $newtypes = $scanner->getNameToFileMap(NameType::newtypeName); $functions = $scanner->getNameToFileMap(NameType::functionName); $constants = $scanner->getNameToFileMap(NameType::constantName);
The getNameToFileMap method takes one parameter specifying the type of the definition desired. getNameToFileMap will return a Map<string,string> where the keys are the names of the classes, interfaces, traits, etc...
including the full name space and the values are the full path to the file in which the definition resides.
Please note that ALL files will be scanned by default (not just .php and/or .hh files). If you wish to only scan files with a particular extension, see the file name filter section below.
Filters
You can filter the results based on the name of the definition and/or the name of the file. Each filter must be a closure with a signature of function(string) : bool.
File Name Filters
To register a file name filter, call ClassScanner->addFileNameFilter() with the filter callback (see example below).
The input for a file name filter is the full path to the file (via realpath). If all registered filter functions return true for a particular file name, the file will be scanned.
If at least one registered file filter returns false, the file will not be read (via file_get_contents).
Definition Name Filters
To register a name filter, call ClassScanner->addNameFilter() with the name type and the filter callback (see example below).
The input for a name filter is the name of the class, interface, trait, etc... including the full namespace. If at least one registered filter function returns false for a particular name, that name
is guaranteed to not appear in the results. Note that the file in which a filtered definition appears may still be in the list if other non-filtered definitions are also in said file.
If you would like to guarantee a file to be skipped, define a file name filter.
Example Filters
In this example, a simple regular expression is used to filter both file names and class names.
use HackPack\Scanner\ClassScanner; use HackPack\Scanner\NameType; $includes = Set{...}; $excludes = Set{...}; $scanner = new ClassScanner($includes, $excludes); // Define the filter callbacks $classFilter = $className ==> preg_match(‘/pattern/’, $className); $fileFilter = $fileName ==> preg_match(‘/pattern/’, $fileName); // Attach the filters $scanner->addDefinitionNameFilter(NameType::className, $classFilter); $scanner->addFileNameFilter($fileFilter); // Retreive the class definitions $classMap = $scanner->mapDefinitionToFile(NameType::className);
In this example, we are specifically looking for XHP classes, using the assumption that all XHP classes are defined in .xhp files.
use HackPack\Scanner\ClassScanner; use HackPack\Scanner\NameType; $includes = Set{...}; $excludes = Set{...}; $scanner = new ClassScanner($includes, $excludes); // Define the filters $classFilter = $className ==> substr($className, 0, 4) === 'xhp_'; $fileFilter = $fileName ==> substr($fileName, -4) === '.xhp'; // Attach the filters $scanner->addNameFilter(NameType::className, $classFilter); $scanner->addFileNameFilter($fileFilter); // Retreive the class definitions $xhpClasses = $scanner->mapClassToFile();
Thanks
The file parsing algorithm and the majority of the tests were authored by Fred Emmott in fredemmott/definitions-finder
hackpack/hack-class-scanner 适用场景与选型建议
hackpack/hack-class-scanner 是一款 基于 Hack 开发的 Composer 扩展包,目前已累计 150 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「autoload」 「hack」 「scan」 「hhvm」 「ClassScanner」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hackpack/hack-class-scanner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hackpack/hack-class-scanner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hackpack/hack-class-scanner 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Environment processor and contexts autoloader
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
Hack Logging Package
Dependency Injection Container For HHVM/Hack
Middleware Dispatcher For Hack
Allows installation of Laravel where the PHP Mcrypt extension is not available. Provides encryption using OpenSSL, or by disabling encryption entierly.
统计信息
- 总下载量: 150
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 35
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-25