uzbek/classtools
Composer 安装命令:
composer require uzbek/classtools
包简介
Find, extract and process classes from file system
README 文档
README
Forked from https://github.com/hanneskod/classtools
Find, extract and process classes from the file system.
Installation
Install using composer. Exists as uzbek/classtools in the packagist repository. From the command line use:
composer require uzbek/classtools
Using the iterator
ClassIterator consumes a symfony finder and scans files for php classes, interfaces and traits.
Access the class map
getClassMap() returns a map of class names to
SplFileInfo
objects.
$finder = new Symfony\Component\Finder\Finder; $iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src')); // Print the file names of classes, interfaces and traits in 'src' foreach ($iter->getClassMap() as $classname => $splFileInfo) { echo $classname.': '.$splFileInfo->getRealPath(); }
Find syntax errors
Source files containing syntax errors can not be parsed and hence no information
on contained classes can be retrieved. Use getErrors() to read the list of
encountered errors.
$finder = new Symfony\Component\Finder\Finder; $iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src')); print_r($iter->getErrors());
Iterate over ReflectionClass objects
ClassIterator is also a Traversable, that on iteration yields class names as keys and ReflectionClass objects as values.
Note that to use reflection the classes found in filesystem must be included in the environment. Enable autoloading to dynamically load classes from a ClassIterator.
$finder = new Symfony\Component\Finder\Finder(); $iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src')); // Enable reflection by autoloading found classes $iter->enableAutoloading(); // Print all classes, interfaces and traits in 'src' foreach ($iter as $class) { echo $class->getName(); }
Filter based on class properties
ClassIterator is filterable and filters are chainable.
$finder = new Symfony\Component\Finder\Finder(); $iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src')); $iter->enableAutoloading(); // Print all Filter types (including the interface itself) foreach ($iter->type('uzbek\ClassTools\Iterator\Filter') as $class) { echo $class->getName(); } // Print definitions in the Iterator namespace whose name contains 'Class' foreach ($iter->inNamespace('uzbek\ClassTools\Iterator\Filter')->name('/type/i') as $class) { echo $class->getName(); } // Print implementations of the Filter interface foreach ($iter->type('uzbek\ClassTools\Iterator\Filter')->where('isInstantiable') as $class) { echo $class->getName(); }
Negate filters
Filters can also be negated by wrapping them in not() method calls.
$finder = new Symfony\Component\Finder\Finder(); $iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src')); $iter->enableAutoloading(); // Print all classes, interfaces and traits NOT instantiable foreach ($iter->not($iter->where('isInstantiable')) as $class) { echo $class->getName(); }
Transforming classes
Found class, interface and trait definitions can be transformed and written to a single file.
$finder = new Symfony\Component\Finder\Finder(); $iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src')); $iter->enableAutoloading(); // Print all found definitions in one snippet echo $iter->minimize(); // The same can be done using echo $iter->transform(new Uzbek\ClassTools\Transformer\MinimizingWriter);
Using the transformer
Wrap code in namespace
$reader = new Reader("<?php class Bar {}"); $writer = new Writer; $writer->apply(new Action\NamespaceWrapper('Foo')); // Outputs class Bar wrapped in namespace Foo echo $writer->write($reader->read('Bar'));
uzbek/classtools 适用场景与选型建议
uzbek/classtools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 267 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「code generator」 「metaprogramming」 「class finder」 「minimizer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 uzbek/classtools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 uzbek/classtools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 uzbek/classtools 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Find, extract and process classes from file system
Memio's PrettyPrinter, used to generate PHP code from given Model
Promotional Codes Generator for Laravel 5.1
Find, extract and process classes from file system
Zend Captcha bundle
Base Skeleton for Laravel Application
统计信息
- 总下载量: 267
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: WTFPL
- 更新时间: 2022-08-19