我正在编写一个使用GuzzleHttp
的库。该库位于composer软件包中:
composer.json
"require": {
// ...
"adz/test": "^1.0@dev",
// ...
}
./ vendor / adz / test / composer.json
"require": {
"php": "~5.6|~7.0",
"guzzlehttp/guzzle": "^6.3"
},
库控制器
namespace adz\test;
use GuzzleHttp\Client;
class User
{
static $client;
public function __construct()
{
self::$client = new \GuzzleHttp\Client();
}
public static function getAll()
{
$res = self::$client->request('GET', 'https://jsonplaceholder.typicode.com/users');
return $res->getBody();
}
}
前端控制器
use adz\test\User;
class UserController extends Controller
{
var $user, $allUsers;
public function __construct()
{
$this->user = new User();
}
public function getAll()
{
$allUsers = $this->user::getAll();
echo $allUsers;
}
}
在运行时,应用程序报告:
找不到类'GuzzleHttp \ Client'。
如果我
composer require guzzlehttp/guzzle
在我的composer.json
前面,然后Guzzle
正常工作。但是我不想将Guzzle
加载到前面的composer.json
中。
我只想将Guzzle
加载到库composer.json
文件中。
我该怎么办?
编辑:(./vendor/adz/test/composer.json
)-完整版;
{
"name": "adz/test",
"type": "library",
"description": "desc",
"keywords": [
"adz",
"test"
],
"homepage": "https://github.com/adz/test",
"license": "MIT",
"authors": [
{
"name": "Andy",
"email": "andy@gmail.com",
"homepage": "https://github.com/1cookie",
"role": "Developer"
}
],
"require": {
"php": "~5.6|~7.0",
"guzzlehttp/guzzle": "^6.3"
},
"require-dev": {
"phpunit/phpunit" : ">=5.4.3",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
"adz\\test\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"adz\\test\\": "tests"
}
},
"scripts": {
"test": "phpunit",
"check-style": "phpcs src tests",
"fix-style": "phpcbf src tests"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"sort-packages": true
}
}