[英]Is there a way to specify in composer.json that a binary must be available?
I know that when creating the composer.json I can define which php extensions need to be installed to get my application running.我知道在创建 composer.json 时,我可以定义需要安装哪些 php 扩展才能让我的应用程序运行。 Can the same be done for a binary that should be executed via exec() or shell_exec()?
可以对应该通过 exec() 或 shell_exec() 执行的二进制文件执行相同的操作吗?
There seems to be a lengthy discussion about this kind of functionality in the composer repository: https://github.com/composer/composer/issues/9636在作曲家存储库中似乎对这种功能进行了冗长的讨论: https://github.com/composer/composer/issues/9636
And composer plugins that aim to solve this: https://github.com/bamarni/composer-bin-plugin以及旨在解决此问题的作曲家插件: https://github.com/bamarni/composer-bin-plugin
A rather simple solution is to declare a callback script ( https://getcomposer.org/doc/articles/scripts.md ) that checks if the binary can be found.一个相当简单的解决方案是声明一个回调脚本( https://getcomposer.org/doc/articles/scripts.md )来检查是否可以找到二进制文件。 For example a
pre-autoload-dump
script that will be executed everytime the autoload is generated.例如,每次生成自动加载时都会执行的
pre-autoload-dump
脚本。
Eg composer.json
requiring 7zip to be installed:例如
composer.json
需要安装 7zip:
{
"name": "lwohlhart/app-with-7zip-requirement",
"authors": [
{
"name": "Lucas Wohlhart",
"email": "lucas@wohlhart.at"
}
],
"require": {
},
"scripts": {
"pre-autoload-dump": [
"which 7z >> /dev/null; ERROR=$?; if [ $ERROR -ne 0 ]; then echo \"7zip not installed\"; (exit $ERROR); fi"
]
}
}
Or if you don't want a custom error message just:或者,如果您不想要自定义错误消息:
"pre-autoload-dump": [
"which 7z"
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.