coenjacobs/mozart
Composer 安装命令:
composer require coenjacobs/mozart
包简介
Composes all dependencies as a package inside a WordPress plugin
README 文档
README
Composes all dependencies as a package inside a WordPress plugin. Load packages through Composer and have them wrapped inside your own namespace. Gone are the days when plugins could load conflicting versions of the same package, resulting in hard to reproduce bugs.
This package requires PHP 8.2 or higher in order to run the tool. You can use the resulting files as a bundle, requiring any PHP version you like, even PHP 5.2.
How it works
Mozart takes your Composer dependencies, copies them into your plugin, and rewrites their namespaces and class names so they can't conflict with other plugins loading the same packages.
For namespaced packages, Mozart prefixes the namespace and updates all references:
-namespace Pimple; +namespace CoenJacobs\TestProject\Dependencies\Pimple; -use Psr\Container\ContainerInterface; +use CoenJacobs\TestProject\Dependencies\Psr\Container\ContainerInterface; class Container implements ContainerInterface
For packages using global-scope classes, Mozart adds a prefix to class names:
-class Container { +class CJTP_Container { // ... } -$container = new Container(); +$container = new CJTP_Container();
This happens across the full dependency tree — namespace declarations, use statements, type hints, string references in class_exists() calls, and more. The result is a self-contained copy of your dependencies that won't collide with any other plugin's versions.
Installation
Mozart brings its own dependencies to the table and that potentially introduces its own problems (yes, I realise how meta that is, for a package like this). That's why installing Mozart in isolation, either through the Docker container, the available PHAR file or installing Mozart as a global dependency with Composer is preferred.
docker run --rm -it -v ${PWD}:/project/ coenjacobs/mozart /mozart/bin/mozart compose
See docs/installation.md for all installation methods (Docker, PHAR, Composer).
Configuration
Mozart potentially requires zero configuration. When your project has a PSR-4 autoload entry or a package name in composer.json, Mozart infers everything it needs: the dependency namespace, target directories, classmap prefix, and the generated dependency autoloader. In the default setup, run mozart compose and then include the generated dep_directory/autoload.php from your plugin bootstrap.
If you want to customize the behavior, add an extra.mozart block to your composer.json. Even an empty block is valid — Mozart fills in every setting it can infer:
"extra": { "mozart": {} }
You can verify the resolved configuration with mozart config.
For full control, you can set every option explicitly:
"extra": { "mozart": { "dep_namespace": "CoenJacobs\\TestProject\\Dependencies\\", "dep_directory": "/src/Dependencies/", "classmap_directory": "/classes/dependencies/", "classmap_prefix": "CJTP_", "constant_prefix": "CJTP_", "functions_prefix": "cjtp_", "generate_autoloader": true, "packages": [ "pimple/pimple" ], "excluded_packages": [ "psr/container" ], "override_autoload": { "google/apiclient": { "classmap": [ "src/" ] } }, "delete_vendor_directories": true } },
The core settings and their defaults:
dep_namespace— root namespace for bundled packages. Default: inferred from your PSR-4 autoload namespace +\Dependencies, or from the package name.dep_directory— target directory for namespaced package files. Default:vendor-prefixed/.classmap_directory— target directory for classmap package files. Default: same asdep_directory.classmap_prefix— prefix applied to classmap class names. Default: derived fromdep_namespacewith\replaced by_.constant_prefix— prefix for global-scope constants. Default: derived fromclassmap_prefixby uppercasing it.functions_prefix— prefix for global-scope functions. Default: derived fromclassmap_prefixby lowercasing it.generate_autoloader— generate a Composer-compatible autoloader for prefixed dependencies. Default:true.
See docs/configuration.md for the full configuration reference with defaults and inference logic.
Supported versions
| Version | Documentation | Latest release |
|---|---|---|
| 1.3 | README.md | (in development) |
| 1.2 | README.md | 1.2.3 |
| 1.1 | README.md | 1.1.6 |
No longer supported
| Version | Documentation | Latest release |
|---|---|---|
| 1.0 | README.md | 1.0.10 |
| 0.7 | README.md | 0.7.1 |
| 0.6 | README.md | 0.6.0 |
Further reading
| Document | Description |
|---|---|
| docs/installation.md | All installation methods: Docker, PHAR, Composer |
| docs/configuration.md | Full configuration reference with defaults and inference |
| docs/usage.md | Automating Mozart with Composer scripts and using the generated autoloader |
| docs/docker.md | Docker registries, tag strategy, multi-architecture support |
| docs/background.md | Why Mozart was created and how it compares to PHP-Scoper |
coenjacobs/mozart 适用场景与选型建议
coenjacobs/mozart 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.01M 次下载、GitHub Stars 达 474, 最近一次更新时间为 2017 年 03 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 coenjacobs/mozart 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 coenjacobs/mozart 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.01M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 478
- 点击次数: 14
- 依赖项目数: 15
- 推荐数: 5
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-06