Skip to content

Commit

Permalink
changed logic for client handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkoo committed Jul 23, 2020
1 parent e65967a commit 8329deb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 41 deletions.
41 changes: 1 addition & 40 deletions src/ActiveHttpClient.php
Original file line number Diff line number Diff line change
@@ -1,54 +1,16 @@
<?php
namespace p4it\rest\client;

use yii\base\Component;
use yii\base\InvalidConfigException;
use yii\httpclient\Client;
use yii\httpclient\Request;

/**
* User: papppeter
* Date: 13/09/2019
* Time: 15:36
*/
class ActiveHttpClient extends Component
class ActiveHttpClient extends Client
{

/**
* @var Client
*/
public $client;

/**
* @return Request
* @throws InvalidConfigException
*/
public function createRequest()
{
return $this->getClientImmutable()->createRequest();
}

/**
* @return Client
* @throws InvalidConfigException
*/
public function getClientImmutable()
{
return clone $this->getClient();
}

/**
* @return Client
* @throws InvalidConfigException
*/
public function getClient()
{
if(!is_object($this->client)) {
$this->client = \Yii::createObject($this->client);
}
return $this->client;
}

public function buildUrl(ActiveResourceQuery $resourceQuery)
{
$resourceQuery->prepare();
Expand Down Expand Up @@ -110,5 +72,4 @@ public function buildInsertUrl(ActiveResourceQuery $resourceQuery)

return $url;
}

}
3 changes: 2 additions & 1 deletion src/ActiveResourceQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ReflectionMethod;
use yii\base\InvalidConfigException;
use yii\db\Connection;
use yii\helpers\VarDumper;
use yii\httpclient\Client;
use yii\httpclient\Exception;
use yii\httpclient\Request;
Expand Down Expand Up @@ -375,7 +376,7 @@ private function getItems(Request $request): Generator
$response = $request->send();
if (!$response->isOk) {
\Yii::error($response->getContent());
throw new BadResponseException($response, $response->getContent(), $response->getStatusCode());
throw new BadResponseException($response, $response->toString(), $response->getStatusCode());
}
/** @var ActiveResponse $data */
$data = $response->getData();
Expand Down

0 comments on commit 8329deb

Please sign in to comment.