horde/autoloader
Composer 安装命令:
composer require horde/autoloader
包简介
Autoloader library
README 文档
README
PSR-0 and PSR-4 compliant autoloader for PHP 8.0+
Why Horde Autoloader?
Horde Autoloader predates PSR-0 and is mostly maintained for legacy and educational purposes. Horde itself primarily uses composer autoloader as does everybody else. Remaining calls into Horde Autoloader from the Horde Framework are going to be removed step by step.
If you need a config-is-code, self-contained, PSR-0 capable autoloader and composer autoloader is not an option, give it a try. Your reasons are yours.
Features
- PSR-4 Support - Autoloading with namespaces
- PSR-0 Support - PEAR-style autoloading without namespaces, underscores as subdir separators.
- Classpath Mappers - Application, Prefix, PrefixString patterns
- PHP 8.0+ - Full type safety and modern features
- LIFO Ordering - Last-added mapper searched first
- Callback Support - Execute code after class loads
- No Dependencies - Self-contained library
Quick Start
Modern (PSR-4 with PSR-0 support)
// Autoloader bootstraps itself - require files explicitly require_once __DIR__ . '/vendor/horde/autoloader/src/Autoloader.php'; require_once __DIR__ . '/vendor/horde/autoloader/src/ClassPathMapper/Psr4.php'; use Horde\Autoloader\Autoloader; use Horde\Autoloader\ClassPathMapper\Psr4; $autoloader = new Autoloader(); $psr4 = new Psr4(enablePsr0Fallback: false); $psr4->addNamespace('Acme\Log', __DIR__ . '/vendor/acme/log/src'); $autoloader->addClassPathMapper($psr4); $autoloader->registerAutoloader();
Legacy (PSR-0 based PSR-0)
// Autoloader bootstraps itself - require files explicitly require_once __DIR__ . '/vendor/horde/autoloader/lib/Horde/Autoloader.php'; $autoloader = new Horde_Autoloader(); $autoloader->addClassPathMapper( new Horde_Autoloader_ClassPathMapper_Default(__DIR__ . '/lib') ); $autoloader->registerAutoloader();
Installation
composer require horde/autoloader
Documentation
- Examples (Legacy PSR-0) - PSR-0 usage examples
- Examples (Modern) - PSR-4 and modern features
- Upgrading Guide - Migration from PSR-0 to PSR-4
- Changelog - Version history
Requirements
- PHP 8.0 or higher
Key Differences: PSR-0 vs PSR-4
| Feature | PSR-0 | PSR-4 |
|---|---|---|
| Underscores | Converted to / |
Preserved as-is |
| Namespace mapping | Simple path | Prefix → base directory |
| Top-level classes | Allowed | Rejected (requires namespace) |
| Multiple base dirs | No | Yes |
PSR-0 Example
// Class: Vendor_Package_Class_Name // Maps to: vendor/Vendor/Package/Class/Name.php
PSR-4 Example
// Prefix: Vendor\Package → /vendor/package/src // Class: \Vendor\Package\Class_Name // Maps to: /vendor/package/src/Class_Name.php (underscore preserved!)
Available Mappers
Modern (src/)
Psr4- PSR-4 compliant autoloader with namespace prefix mappingDefaultMapper- PSR-0 compliant mapper (underscores → directories)Application- Application-specific MVC pattern mapperPrefix- Regex-based prefix matchingPrefixString- Fast case-insensitive string prefix matching
Legacy (lib/)
Horde_Autoloader_ClassPathMapper_Default- PSR-0 mapperHorde_Autoloader_ClassPathMapper_Application- Application mapperHorde_Autoloader_ClassPathMapper_Prefix- Regex prefixHorde_Autoloader_ClassPathMapper_PrefixString- String prefix
Testing
# Run all tests phpunit # Run specific test suites phpunit --testsuite unit # Legacy PSR-0 tests phpunit --testsuite modern # Modern PSR-4 tests phpunit --testsuite integration # Real file loading tests
License
LGPL-2.1-only
Links
- Homepage: https://www.horde.org/libraries/Horde_Autoloader
- Repository: https://github.com/horde/Autoloader
- PSR-4 Specification: https://www.php-fig.org/psr/psr-4/
- PSR-0 Specification: https://www.php-fig.org/psr/psr-0/
Credits
- Authors: Bob Mckee, Chuck Hagenbuch
- Maintainers: Jan Schneider, Ralf Lang
horde/autoloader 适用场景与选型建议
horde/autoloader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.62k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 11 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 horde/autoloader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 horde/autoloader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 19
- 推荐数: 2
其他信息
- 授权协议: LGPL-2.1-only
- 更新时间: 2022-11-10