当前位置: 首页 > 知识库问答 >
问题:

编写器自动加载程序未加载GuzzleHttp\ClientInterface

萧宏远
2023-03-14

我试图使用高斯,但我得到以下致命错误:

致命错误:类GuzzleHttp\ClientInterface在第13行的 /var/www/myapp/vendor/guzzlehttp/guzzle/src/functions.php中找不到

我正在使用composer autoloader自动加载:

require 'vendor/autoload.php';

use Guzzle\Http\Client;

$client = new Client();

$requests = Array(
    $client->createRequest('GET', 'ams1.myapp.com:8080/api/ffmpeg_make_snapshots.php'),
    $client->createRequest('GET', 'ams2.myapp.com:8080/api/ffmpeg_make_snapshots.php'),
    $client->createRequest('GET', 'ams3.myapp.com:8080/api/ffmpeg_make_snapshots.php')
);

$client->sendAll($requests);

发生了什么事?

编辑

我的composer.json:

{
    "require": {
        "guzzlehttp/guzzle": "~4"
    }
}

编辑2

我的作曲家。锁


{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
    ],
    "hash": "33c003b6e3e2dc0144146f9b652a6719",
    "packages": [
        {
            "name": "guzzlehttp/guzzle",
            "version": "4.0.0",
            "source": {
                "type": "git",
                "url": "https://github.com/guzzle/guzzle.git",
                "reference": "4063f08ca434efac12bf7a3db0d370b1c451345b"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/guzzle/guzzle/zipball/4063f08ca434efac12bf7a3db0d370b1c451345b",
                "reference": "4063f08ca434efac12bf7a3db0d370b1c451345b",
                "shasum": ""
            },
            "require": {
                "guzzlehttp/streams": "1.*",
                "php": ">=5.4.0"
            },
            "require-dev": {
                "ext-curl": "*",
                "phpunit/phpunit": "4.*",
                "psr/log": "~1"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "4.0.x-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "GuzzleHttp\\": "src/"
                },
                "files": [
                    "src/functions.php"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Michael Dowling",
                    "email": "mtdowling@gmail.com",
                    "homepage": "https://github.com/mtdowling"
                }
            ],
            "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
            "homepage": "http://guzzlephp.org/",
            "keywords": [
                "client",
                "curl",
                "framework",
                "http",
                "http client",
                "rest",
                "web service"
            ],
            "time": "2014-03-29 23:11:36"
        },
        {
            "name": "guzzlehttp/streams",
            "version": "1.4.0",
            "source": {
                "type": "git",
                "url": "https://github.com/guzzle/streams.git",
                "reference": "3b761a328e5ed6ed519e960aded95d7acbe77894"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/guzzle/streams/zipball/3b761a328e5ed6ed519e960aded95d7acbe77894",
                "reference": "3b761a328e5ed6ed519e960aded95d7acbe77894",
                "shasum": ""
            },
            "require": {
                "php": ">=5.4.0"
            },
            "require-dev": {
                "phpunit/phpunit": "~4.0"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.4.x-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "GuzzleHttp\\Stream\\": "src/"
                },
                "files": [
                    "src/functions.php"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Michael Dowling",
                    "email": "mtdowling@gmail.com",
                    "homepage": "https://github.com/mtdowling"
                }
            ],
            "description": "Provides a simple abstraction over streams of data (Guzzle 4+)",
            "homepage": "http://guzzlephp.org/",
            "keywords": [
                "Guzzle",
                "stream"
            ],
            "time": "2014-07-19 18:43:42"
        }
    ],
    "packages-dev": [],
    "aliases": [],
    "minimum-stability": "stable",
    "stability-flags": [],
    "platform": [],
    "platform-dev": []
}

编辑3

编写器配置-l输出:


[repositories.packagist.type] composer
[repositories.packagist.url] https?://packagist.org
[repositories.packagist.allow_ssl_downgrade] true
[process-timeout] 300
[use-include-path] false
[preferred-install] auto
[notify-on-install] true
[github-protocols] [git, https]
[vendor-dir] vendor
[bin-dir] {$vendor-dir}/bin (vendor/bin)
[cache-dir] C:/Users/User/AppData/Local/Composer
[cache-files-dir] {$cache-dir}/files (C:/Users/User/AppData/Local/Composer/files)
[cache-repo-dir] {$cache-dir}/repo (C:/Users/User/AppData/Local/Composer/repo)
[cache-vcs-dir] {$cache-dir}/vcs (C:/Users/User/AppData/Local/Composer/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[discard-changes] false
[prepend-autoloader] true
[github-domains] [github.com]
[home] C:/Users/User/AppData/Roaming/Compose

共有1个答案

蒋健
2023-03-14

guzzle 4的名称空间是guzzle http在guzzle 3中,名称空间只是guzzle

一个composer.json的:

{
    "require": {
        "guzzlehttp/guzzle": "~4"
    }
}

应允许您运行以下php脚本

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();

$requests = Array(
    $client->createRequest('GET', 'ams1.myapp.com:8080/api/ffmpeg_make_snapshots.php'),
    $client->createRequest('GET', 'ams2.myapp.com:8080/api/ffmpeg_make_snapshots.php'),
    $client->createRequest('GET', 'ams3.myapp.com:8080/api/ffmpeg_make_snapshots.php'),
);

$client->sendAll($requests);

如果更改名称空间后自动加载程序仍然失败,则可能是您的composer版本已过期,无法识别PSR4自动加载。如果vendor/composer/autoload\u psr4中没有文件。php尝试执行编写器自我更新,然后执行编写器转储自动加载,以查看问题是否得到解决。

 类似资料:
  • 我刚刚开始使用composer进行依赖关系管理,我很难弄清楚我是如何不遵守psr-4进行自动加载的,所以我来这里寻求建议。我有一个生成随机值的类,它已经在packagist上了。项目结构如下(我已将composer.json文件标记为A和B): 项目总监 composer.jsonA composer.jsonB 最后是RlandValue.php文件,它声明了ejFrancis命名空间 当我运行

  • 我不熟悉使用composer和psr-0。我尝试了一个使用composer和psr-0的小应用程序。我已经使用名称空间加载了一个特定的类。当我使用composer vendor/autoload调用一个类时,我得到了“未找到类”错误。 我的composer.json文件:/var/www/html/silexapp/composer.json 我的作曲家供应商自动加载文件:/var/www/htm

  • 我已经设置了两个项目,一个“init”和一个库,这是init所需要的。它们都设置了PSR-0自动加载,但是库中的自动加载值不会添加到初始化项目中的供应商/作曲家/autoload_namespaces.php中。 示例作曲家。来自库的json: 示例作曲家。来自需要该库的项目的json: 该库包含文件src/LXP/library/Something中的类LXP\library\Something

  • 我正试图用PhpUnit和Composer。为此,我做了: 1添加phpUnit到req作曲家部分: 2.根据需要安装: php编写器。phar安装--dev 手术成功结束。 安装phpunit/phpunit(3.7.6)下载:100% 不幸的是,当我想做测试时,我得到了 ./vendor/bin/phpunit PHP致命错误:对/home/serek/PHP/project/tests/bo

  • 我遇到了使用作曲家psr-4自动加载功能和PHPUnit的问题。问题发生在我的本地机器以及TravisCI版本上。单元测试无法找到我的类,而普通脚本可以找到。 当然,任何配置都有问题,但我无法找出我做错了什么。提前感谢你的帮助。 这是我的项目文件结构: 公共/ src/ http/ urlhelper。php 小黑 超文本传输协议/ urlhelper.test.php 这是我的作曲家的作品。js

  • 我正在开发一个使用Monolog的项目,需要Psr/log。当我通过自动加载使用Monolog时,它会抱怨缺少Psr\Log\LoggerInterface。所以我查看作曲家生成的autoload_namespaces.php,我找不到注册的Psr。 这是我的供应商/autoload_namespaces.php的内容 作曲家是否应该为composer.json文件中定义了{autoload}的所