typo3/class-alias-loader
Composer 安装命令:
composer require typo3/class-alias-loader
包简介
Amends the composer class loader to support class aliases to provide backwards compatibility for packages
README 文档
README
Introduction
The idea behind this composer package is, to provide backwards compatibility for libraries that want to rename classes but still want to stay compatible for a certain amount of time with consumer packages of these libraries.
What it does?
It provides an additional class loader which amends the composer class loader by rewriting the vendor/autoload.php
file when composer dumps the autoload information. This is only done if any of the packages that are installed by composer
provide a class alias map file, which is configured in the respective composer.json.
How does it work?
If a package provides a mapping file which holds the mapping from old to new class name, the class loader registers itself
and transparently calls class_alias() for classes with an alias. If an old class name is requested, the original class
is loaded and the alias is established, so that third party packages can use old class names transparently.
Configuration in composer.json
You can define multiple class alias map files in the extra section of the composer.json like this:
"extra": {
"typo3/class-alias-loader": {
"class-alias-maps": [
"Migrations/Code/ClassAliasMap.php"
]
}
},
Currently these files must be PHP files which return an associative array, where the keys are the old class names and the values the new class names. Such a mapping file can look like this:
<?php
return array(
'Tx_About_Controller_AboutController' => \TYPO3\CMS\About\Controller\AboutController::class,
'Tx_About_Domain_Model_Extension' => \TYPO3\CMS\About\Domain\Model\Extension::class,
'Tx_About_Domain_Repository_ExtensionRepository' => \TYPO3\CMS\About\Domain\Repository\ExtensionRepository::class,
'Tx_Aboutmodules_Controller_ModulesController' => \TYPO3\CMS\Aboutmodules\Controller\ModulesController::class,
);
If no alias mapping is found then by default this package does nothing. It means no additional class loading information is dumped
and the vendor/autoload.php is not changed. This enables library vendors to deliver compatibility packages which provide such aliases
for backwards compatibility, but keep the library clean (and faster) for new users.
In case you want your application to add alias maps during runtime, it may be useful however if the alias loader is always initialized.
Therefore it is possible to set the following option in your root composer.json:
"extra": {
"typo3/class-alias-loader": {
"always-add-alias-loader": true
}
},
Using the API
The public API is pretty simple and consists of only one class with only three static methods, TYPO3\ClassAliasLoader\ClassAliasMap::getClassNameForAlias
being the most important one.
You can use this class method if you have places in your application that deals with class names in strings and want to provide backwards compatibility there.
The API returns the original (new) class name if there is one, or the class name given if no alias is found.
The remaining methods, deal with adding alias maps during runtime, which generally is not recommended to do.
Feedback appreciated
I'm happy for feedback, be it feature requests or bug reports.
Contribute
If you feel like contributing, please do a regular pull request. The package is pretty small. The only thing to respect is to follow PSR-2 coding standard and to add some tests for functionality you add or change.
typo3/class-alias-loader 适用场景与选型建议
typo3/class-alias-loader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.47M 次下载、GitHub Stars 达 44, 最近一次更新时间为 2015 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「autoloader」 「composer」 「classloader」 「alias」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 typo3/class-alias-loader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 typo3/class-alias-loader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 typo3/class-alias-loader 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Amends the composer class loader to support class aliases to provide backwards compatibility for packages
An package to make it easy to autoload code.
Tune your autoloader
Light PSR-0 compliant autoloader for PHP5.3+ namespaces and older PEAR-style classes.
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
统计信息
- 总下载量: 14.47M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 44
- 点击次数: 30
- 依赖项目数: 17
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-05