-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace spec\Nixilla\Api\LoggerBundle\Proxy\Twilio; | ||
|
||
use Nixilla\Api\LoggerBundle\Proxy\Twilio\CurlClient; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class CurlClientSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(CurlClient::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Nixilla\Api\LoggerBundle\Proxy\Twilio; | ||
|
||
use Nixilla\Api\LoggerBundle\Traits\Log; | ||
use Twilio\Http\CurlClient as BaseClient; | ||
use Twilio\Http\Response; | ||
|
||
class CurlClient extends BaseClient | ||
{ | ||
use Log; | ||
|
||
public function request( | ||
$method, | ||
$url, | ||
$params = [], | ||
$data = [], | ||
$headers = [], | ||
$user = null, | ||
$password = null, | ||
$timeout = null | ||
) | ||
{ | ||
$start = microtime(true); | ||
|
||
/** @var Response $result */ | ||
$result = parent::request($method, $url, $params, $data, $headers, $user, $password, $timeout); | ||
|
||
if($this->hasLogger()) | ||
{ | ||
$time = microtime(true) - $start; | ||
|
||
$this->getLogger()->logCall( | ||
$url, | ||
'', | ||
$method, | ||
$time, | ||
$this->fixHeaders($headers), | ||
$data, | ||
$result->getHeaders(), | ||
json_encode($result->getContent()) | ||
); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
private function fixHeaders($headers) | ||
{ | ||
$fixed = []; | ||
|
||
foreach ($headers as $name => $value) | ||
{ | ||
$fixed[] = sprintf('%s: %s', $name, $value); | ||
} | ||
|
||
return $fixed; | ||
} | ||
} |