empaphy/composer-yaml
Composer 安装命令:
composer require empaphy/composer-yaml
包简介
composer.yaml support for Composer
README 文档
README
This Composer plugin will make your composer project use composer.yaml as it's
Composer config instead of composer.json. It does so fully transparently
without the need to run additional commands.
composer.json is still required, (to bootstrap this plugin, among other
things) however it is now generated automatically when a change in
composer.yaml is detected. Think of this similarly to how composer.lock
is generated.
Installation
composer require "empaphy/composer-yaml:^1.0"
Usage
Just use composer as you usually would! The first time you run any Composer CLI command after installing this plugin, it will generate a composer.yaml based on your existing composer.json.
Just remember to modify composer.yaml from now on, and to not modify composer.json, since any changes in that file will be overridden.
Why YAML? What's wrong with JSON?
JSON was never designed to be a human-readable format. It's intended use is for computers to exchange information with one another. Hence, it misses essential features which one would need from a file that is manipulated by humans, like comments.
YAML allows for comments and a lot more, making expressive Composer configuration possible.
- Comments allow you to clarify your configuration.
- Quotes are not required, which makes the file much more readable.
- No trailing commas are required, which reduces the risk of syntax errors.
- Support for multiline strings allows you to split string over multiple rows. YAML allows you to fold or retain newlines in multiline strings.
- YAML anchors let you reference and use the same data multiple times.
YAML vs JSON
For example, if you take a typical composer.json like this:
{
"name": "empaphy/foo",
"description": "Foo library for PHP",
"license": "MIT",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=7.4",
"symfony/config": "~5.4.0",
"symfony/console": "~5.4.0",
"symfony/filesystem": "~5.4.0",
"symfony/process": "~5.4.0",
"symfony/yaml": "~5.4.0",
"yogarine/composer-yaml": "~5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phploc/phploc": "^7.0",
"phpstan/phpstan": "^1.0"
},
"autoload": {
"psr-4": { "Empaphy\\Foo\\": "src/" }
},
"config": {
"platform": {
"php": "8.0.20"
}
},
"scripts": {
"pre-install-cmd": [
"if [ -d .git -o -f .git -a -d ../.git ]; then git submodule update; fi"
]
}
}
You can turn it into something like this:
## # Example Composer configuration for the Foo package. # # Use composer to install dependencies for this package: # # composer install --no-dev --optimize-autoloader # name: empaphy/foo # The name of the package. description: Foo library for PHP # A short description of the package. license: MIT # The license of the package. # This defines the default behavior for filtering packages by stability. minimum-stability: stable # Prefer more stable packages over unstable ones when finding compatible stable # packages is possible. # # If you require a dev version or only alphas are available for a package, those # will still be selected granted that the minimum-stability allows for it. prefer-stable: true # Map of packages required by this package. # # The package will not be installed unless those requirements can be met. require: php: '>=7.4' # We depend on property types. # Symfony dependencies: symfony/config: &symfony-version '~5.4.0' symfony/console: *symfony-version symfony/filesystem: *symfony-version symfony/process: *symfony-version symfony/yaml: *symfony-version yogarine/composer-yaml: 'dev-main' # Adds support for this file. :-) require-dev: phpunit/phpunit: '^9.0' phploc/phploc: '^7.0' phpstan/phpstan: '^1.0' autoload: psr-4: [ Empaphy\Foo: src/ ] config: platform: php: '8.0.20' # We currently run 8.0.20 on all our production servers, # so ensure we're forward-compatible with PHP 8. allow-plugins: yogarine/composer-yaml: true # Required to for composer.yaml support. scripts: # Occurs before the `install` command is executed with a lock file present. pre-install-cmd: - | # Ensure submodules are updated. if [ -d .git -o -f .git -a -d ../.git ]; then git submodule update fi
Known Issues / Roadmap
-
Using Composer CLI commands that would previously modify the composer.json will still work and properly modify the
composer.yaml, but they will remove any custom formatting changes and comments you have made to yourcomposer.yamlfile.I plan to fix this in a future version, but it involves writing a custom YAML Manipulator, so it might take a while. For now, just refrain from using the CLI commands to modify the composer config. I mean, why even would you, when you can now use fancy YAML markup to pimp up your composer.yaml? ;-)
-
Handle first-time install of a composer.yaml project properly. Especially in the edge case where composer.yaml was modified, but composer-yaml has not yet been installed.
-
Warn about changes made to composer.json
-
Add config option to choose default behaviours, for example for overwriting an existing YAML file.
empaphy/composer-yaml 适用场景与选型建议
empaphy/composer-yaml 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 95 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 07 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yaml」 「plugin」 「composer」 「composer.yaml」 「composer.yml」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 empaphy/composer-yaml 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 empaphy/composer-yaml 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 empaphy/composer-yaml 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
SUML for PHP
SUML support for Symfony
provides an facade for php-yaml, syck and symphony/yaml so switching in between is easier
统计信息
- 总下载量: 95
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-17