ock/class-files-iterator
Composer 安装命令:
composer require ock/class-files-iterator
包简介
README 文档
README
This package provides IteratorAggregate implementations to iterate through class files.
Main concepts:
ClassFilesIA*:
IteratorAggregate that lists class names keyed by their file names.NamespaceDirectory:
Main implementation representing a PSR-4 class files directory.
It provides additional methods to navigate to parent or child directories.
ClassNamesIA*
IteratorAggregate that lists class names by numeric keys.
This can be used if the file path is not relevant.
Benefits
There are other packages which attempt to solve the same problem in different ways.
The benefits of this package are:
- Predictable (alphabetic) order of class files.
This is thanks to internal usage ofscandir()with sort flag, instead of directory iterators. - The "iterators" are stateless/immutable, and can be passed around as value objects.
This is thanks to them extendingIteratorAggregateinstead ofIterator. - Code that needs a list of classes or class files can simply depend on the interfaces, and does not need to deal with directories.
Limitations
Iterators for reflection classes are not part of this package.
Usage
use Ock\ClassFilesIterator\ClassFilesIA\ClassFilesIAInterface; use Ock\ClassFilesIterator\ClassNamesIA\ClassNamesIAInterface; use Ock\ClassFilesIterator\NamespaceDirectory; use Ock\ClassFilesIterator\Tests\Fixtures\Acme\Plant\VenusFlyTrap; // Basic creation for a PSR-4 directory. $basic_namespace_dir = NamespaceDirectory::create($basedir . '/src', 'Acme\\Foo'); // Convenient creation with a "seed" class. // The directory is determined automatically with ReflectionClass::getFileName(). $namespace_dir = NamespaceDirectory::fromClass(VenusFlyTrap::class); // Iterate class names by integer key. function foo(ClassNamesIAInterface $classNamesIA): void { foreach ($classNamesIA as $class) { assert(class_exists($class)); } } // Iterate class names with file path as key. function foo(ClassFilesIAInterface $classNamesIA): void { foreach ($classNamesIA as $file => $class) { assert(file_exists($file)); assert(class_exists($class)); } } // Get reflection classes. function foo(ClassFilesIAInterface $classFilesIA): void { foreach ($classFilesIA as $file => $class) { try { $rc = new \ReflectionClass($class); } catch (\ReflectionException|\Error) { // Skip non-existing classes / interfaces / traits. // Skip if a base class or interface is missing. // Unfortunately, missing traits still cause fatal error. continue; } // Ignore if the class is defined elsewhere. if ($rc->getFileName() !== $file && realpath($rc->getFileName()) !== realpath($file)) { continue; } do_something($rc); } }
ock/class-files-iterator 适用场景与选型建议
ock/class-files-iterator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 94 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ock/class-files-iterator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ock/class-files-iterator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 94
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-26