且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何在Laravel项目中使用供应商文件夹中的类

更新时间:2023-11-19 17:34:40

简短版本:您正在尝试实例化一个不存在的类.实例化正确的类,您便会准备就绪.

Short Version: You're trying to instantiate a class that doesn't exist. Instantiate the right class and you'll be all set.

长版:您无需对composer.json做任何花哨的操作即可使Guzzle正常工作.Guzzle遵循自动加载的PSR标准,这意味着只要通过作曲家将Guzzle插入,您就可以实例化Guzzle类,而不必担心自动加载.

Long Version: You shouldn't need to do anything fancy with your composer.json to get Guzzle working. Guzzle adheres to a the PSR standard for autoloading, which means so long as Guzzle's pulled in via composer, you can instantiate Guzzle classes without worrying about autoloading.

根据您提到的文件路径,听起来像您正在使用Guzzle 3,/a>.专门查看您要包含的类

Based on the file path you mentioned, it sounds like you're using Guzzle 3. Looking specifically at the class you're trying to include

namespace Guzzle\Http;
/*...*/
class Client extends AbstractHasDispatcher implements ClientInterface
{
        /*...*/
}

Guzzle 3中的guzzle客户端类不是 GuzzleHttp \ Client .它的名称是 Guzzle \ Http \ Client .所以尝试

The guzzle client class in Guzzle 3 is not GuzzleHttp\Client. Its name is Guzzle\Http\Client. So try either

$client = new \Guzzle\Http\Client;

use Guzzle\Http\Client;
$client = new Client;

,您应该已经准备就绪.

and you should be all set.