小编fun*_*ein的帖子

尝试将 Guzzle Curl 客户端绑定到 Laravel 的服务容器——然后在尝试 __construct() 时键入提示客户端失败

所以我想我会尝试在 Laravel 中实际使用这个花哨的 IoC 容器。我从 Guzzle 开始,但我无法让它工作。也许我的理解有差距。我真的很感谢这里的任何帮助。

所以我有一个用于连接到 RESTful Api 的类。这是其中的一个示例:

    use GuzzleHttp\Exception\BadResponseException;
    use GuzzleHttp\Client;
    use GuzzleHttp\Subscriber\Oauth\Oauth1;

class EtApi {
    //you can pass in the model if you wanna
    //protected $model;

    //client Id
    protected $clientId;

    //client secret
    protected $clientSecret;

    //base_uri
    protected $getTokenUri;

    protected $client;

    //build
    function __construct(Client $client)
    {
        $this->client = $client;
        $this->clientId = 's0m3R4nd0mStr1nG';
        $this->clientSecret = 's0m3R4nd0mStr1nG';
        $this->getTokenUri = 'https://rest.api/requestToken';
        $this->accessToken = $this->getToken($this->clientId, $this->clientSecret, $this->getTokenUri);
    }
Run Code Online (Sandbox Code Playgroud)

}

我已经成功安装并使用了 Guzzle,方法是在 $client = new Client(); 之类的方法中手动更新它。但这不是很干,也不是正确的做事方式。所以我在 app\Providers\GuzzleProvider.php 创建了一个 ServiceProvider。我确保这是在 app/config/app.php 下注册的 …

php ioc-container type-hinting laravel laravel-5

5
推荐指数
1
解决办法
5844
查看次数

标签 统计

ioc-container ×1

laravel ×1

laravel-5 ×1

php ×1

type-hinting ×1