php - 带有 Composer 的交互式 PHP 脚本

标签 php symfony composer-php symfony4 post-install

我想在 composer updatecomposer install 之后自动从 composer.json 文件运行一个交互式 PHP 脚本,例如:

"scripts": {
    "raven-cmd": [
        "php bin/console kolesar:boilerplate:setup"
    ],
    "auto-scripts": {
        "cache:clear": "symfony-cmd",
        "assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd",
        "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
        "@auto-scripts",
        "@kolesar-cmd"
    ],
    "post-update-cmd": [
        "@auto-scripts",
        "@kolesar-cmd"
    ]
},

Symfony 命令 php bin/console kolesar:boilerplate:setup 是交互式脚本,需要一些用户输入,但这不起作用。确切地说,交互模式不起作用。

任何提示,如何解决这个问题?或者在 composer update/install 之后有另一个强制设置的想法?

最佳答案

您可以在脚本调用之后简单地放置“< /dev/tty”。

https://pantheon.io/blog/writing-composer-scripts :

There is another difference that may affect some commands, and that is that standard input will be attached to a TTY when the script is ran directly from the shell, but will be a redirected input stream when run through Composer. This can have various effects; for example, Symfony Console will not call the interact() method if there is no attached TTY. This could get in your way if, for example, you were trying to write functional tests that test interaction, as the consolidation/annotated-command project does. There are a couple of options for fixing this situation. The first is to explicitly specify that standard input should come from a TTY when running the command

This effectively gets Symfony Console to call the interact() method again; however, the down-side to this option is that it is not as portable

我刚刚试了一下,它按预期工作。

请注意,链接的文章还提供了一个更便携的版本,以备不时之需。

关于php - 带有 Composer 的交互式 PHP 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52698229/

相关文章:

php - mysqli_fetch_assoc()需要参数/调用成员函数bind_param()错误。如何获取并修复实际的mysql错误?

php - 支付成功后paypal,如何将用户重定向到新页面

symfony - 在捆绑配置中定义角色

Symfony2 更新 bootstrap.php.cache

php - autoload.php 是否应该包含在类文件中

php - 查找并替换两个可变长度整数之间的连字符 (-)

php - 在 CakePHP3 中显示一列 Join

php - Symfony 查询错误 : Expected Literal, 得到 '"'

php - 如何将 composer 包安装到/src 目录中?

php - Composer 更新 : Trying to access array offset on value of type null