darsyn/class-finder
最新稳定版本:3.0.2
Composer 安装命令:
composer require darsyn/class-finder
包简介
Class Finder by Darsyn for searching for end-user PHP classes.
README 文档
README
A library for searching for classes in a specific root directory and namespace. Originally intended for searching for classes in all registered Symfony bundles (similar to finding bundle commands), it can find classes that stick to a standard without having to manually register each of those classes. Various filters can be specified, such as:
- In a sub-directory/namespace.
- Have a specific file extension.
- End with custom suffix.
- Implement or extend a parent class or interface.
Usually an array containing fully-qualified class names (as strings) is returned, but passing true as the fourth
parameter to the findClasses() method will return an array of ReflectionClass instances instead. Very useful in
certain situations.
License
This project is licensed under MIT.
Dependencies
This project uses Symfony's Finder component to search for classes, and PHP's Reflection extension to process class definitions. It also assumes you are using Composer or a similar autoloader.
If you plan to use this library with the Symfony framework, it also utilises the HTTP Kernel component; this will already be a dependency of your project however.
Example
<?php use Darsyn\ClassFinder\ClassFinder; $finder = new ClassFinder; $finder->setRootDirectory(__DIR__); $subDir = 'Models'; $suffix = 'Entity'; $parent = 'Framework\\ActiveRecordEntity'; $classes = $finder->findClasses($subDir, $suffix, $parent); foreach ($classes as $class) { echo $class . "\n"; } /** * Example Output: * * Models\UserEntity * Models\GroupEntity * Models\CustomerEntity */
Symfony Integration
<?php use Darsyn\ClassFinder\BundleClassFinder; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends Controller { public function indexAction() { $kernel = $this->container->get('kernel'); $finder = new BundleClassFinder($kernel); // Find all container-aware commands across all bundles: $containerAwareCommands = $finder->findClasses( 'Command', 'Command', 'Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand' ); } }
You may also register this library as a service. To do so, add the following to app/config/services.yml (or in the
bundle that uses this library in your preferred configuration format):
services: darsyn.class_finder: class: Darsyn\ClassFinder\BundleClassFinder arguments: [ @kernel ]
Note: Remember that the kernel service is synthetic, and cannot be used until Symfony injects the correct kernel
instance into the container.
Authors and Contributing
Current authors include:
All contributions are welcome, don't forget to add your name here in the pull request!
darsyn/class-finder 适用场景与选型建议
darsyn/class-finder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 204 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 05 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 darsyn/class-finder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 darsyn/class-finder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 204
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-20