gpt4 book ai didi

php - 如何修复 composer post-install-cmd 脚本的错误?

转载 作者:可可西里 更新时间:2023-11-01 12:17:55 25 4
gpt4 key购买 nike

我想使用 composer 脚本做一些后期安装,例如将文件从 bootstrap vendor 文件夹复制到我的 web 应用程序公共(public)文件夹。我对 PHP 世界和 Web 应用程序开发有初步的了解。

我正在尝试通过关注 this tutorial学习这样做

这是我的目录结构* enter image description here

这是我的 composer.json

{
"name": "Composer Script",
"description": "An example to demonstrate the use of Composer scripts",
"version": "1.0.0",
"require": {
"twitter/bootstrap": ">=3.0"
},

"scripts": {
"post-install-cmd": [
"ComposerScript\\Installer::postInstall"
],
"post-package-install": [
"/var/www/test/composer-script/install.sh"
]
}
}

这是 ComposerScript\Installer.php

class Installer

{
public static function postInstall(Event $event)
{
$composer = $event->getComposer();
// do stuff
}

public static function postPackageInstall(Event $event)
{
$installedPackage = $event->getOperation()->getPackage();
// do stuff
}

public static function warmCache(Event $event)
{
// make cache toasty
}
}

执行 composer install 后我得到这个错误 enter image description here

此时install.sh是空的

如何修复此错误,尤其是什么是自动加载?,我不知道要搜索什么关键字请建议我阅读。

最佳答案

以防万一有人再次遇到这个问题。这是一个勺子喂食示例。 :)

在这样的给定场景中

enter image description here

我们必须将我们的 composer.json 设置为 ff。设置

"autoload": {
"psr-0": {
"ComposerScript\\Installer" : ""
}
},

"scripts": {
"post-package-update": [
"ComposerScript\\Installer::postPackageUpdate"
]
}

那么Installer.php的内容就是

namespace ComposerScript;

use Composer\Script\Event;

class Installer
{
public static function postUpdate(Event $event)
{
$composer = $event->getComposer();
// do stuff
}

public static function postPackageUpdate(Event $event)
{
$packageName = $event->getOperation()
->getPackage()
->getName();
echo "$packageName\n";
// do stuff
}

public static function warmCache(Event $event)
{
// make cache toasty
}
}

然后执行 php composer.phar update 将在没有警告的情况下工作。

关于php - 如何修复 composer post-install-cmd 脚本的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19133518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com