Takes Guzzle's client as constructor argument

771 views Asked by At

I create a Client class which implement interface. I need takes Guzzle's client as constructor argument, but i can't do that.

<?php

namespace Payum\Core\Bridge\Psr\Http;

use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;

class Client implements ClientInterface
{
    $client = new \GuzzleHttp\Client(); // there is error 'Unexpected'

    public function  __construct($client)
    {

    }
    public function responeInterface()
    {

    }
}
1

There are 1 answers

0
Bizmate On BEST ANSWER

Your Client class has a client property that needs to be initilised in the constructor, not in its declaration.

Also I do not see where your ClientInterface is coming from? Should you have a use statement that imports the interface???

Let me know if this code helps

<?php

namespace Payum\Core\Bridge\Psr\Http;

use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;

class Client implements ClientInterface
    {
        $client; 

    public function  __construct(Client $client)
    {
        $this->client = $client;
    }
    public function responeInterface()
    {

    }
}

Then you need to instantiate your client class by passing an instance of Guzzle to the constructor. i.e.

$guzzle = new \GuzzleHttp\Client();
$myClient = new Client($guzzle); // this is an instance of your class