���� JFIF �� � ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /var/www/html/trader/vendor/zaloplatform/zalo-php-sdk/src/ |
<?php /** * Zalo © 2019 * */ namespace Zalo; use Zalo\Exceptions\ZaloResponseException; use Zalo\Exceptions\ZaloSDKException; /** * Class ZaloResponse * * @package Zalo */ class ZaloResponse { /** * @var int The HTTP status code response from Graph. */ protected $httpStatusCode; /** * @var array The headers returned from Graph. */ protected $headers; /** * @var string The raw body of the response from Graph. */ protected $body; /** * @var array The decoded body of the Graph response. */ protected $decodedBody = []; /** * @var ZaloRequest The original request that returned this response. */ protected $request; /** * @var ZaloSDKException The exception thrown by this request. */ protected $thrownException; /** * Creates a new Response entity. * * @param ZaloRequest $request * @param string|null $body * @param int|null $httpStatusCode * @param array|null $headers */ public function __construct(ZaloRequest $request, $body = null, $httpStatusCode = null, array $headers = []) { $this->request = $request; $this->body = $body; $this->httpStatusCode = $httpStatusCode; $this->headers = $headers; $this->decodeBody(); } /** * Return the original request that returned this response. * * @return ZaloRequest */ public function getRequest() { return $this->request; } /** * Return the ZaloApp entity used for this response. * * @return ZaloApp */ public function getApp() { return $this->request->getApp(); } /** * Return the access token that was used for this response. * * @return string|null */ public function getAccessToken() { return $this->request->getAccessToken(); } /** * Return the HTTP status code for this response. * * @return int */ public function getHttpStatusCode() { return $this->httpStatusCode; } /** * Return the HTTP headers for this response. * * @return array */ public function getHeaders() { return $this->headers; } /** * Return the raw body response. * * @return string */ public function getBody() { return $this->body; } /** * Return the decoded body response. * * @return array */ public function getDecodedBody() { return $this->decodedBody; } /** * Get the ETag associated with the response. * * @return string|null */ public function getETag() { return isset($this->headers['ETag']) ? $this->headers['ETag'] : null; } /** * Returns true if Graph returned an error message. * * @return boolean */ public function isError() { return isset($this->decodedBody['error']) && $this->decodedBody['error'] < 0; } /** * Throws the exception. * * @throws ZaloSDKException */ public function throwException() { throw $this->thrownException; } /** * Instantiates an exception to be thrown later. */ public function makeException() { $this->thrownException = ZaloResponseException::create($this); } /** * Returns the exception that was thrown for this request. * * @return ZaloResponseException|null */ public function getThrownException() { return $this->thrownException; } /** * Convert the raw response into an array if possible. * * Graph will return 2 types of responses: * - JSON(P) * Most responses from Graph are JSON(P) * - application/x-www-form-urlencoded key/value pairs * Happens on the `/oauth/access_token` endpoint when exchanging * a short-lived access token for a long-lived access token * - And sometimes nothing :/ but that'd be a bug. */ public function decodeBody() { $this->decodedBody = json_decode($this->body, true); if ($this->decodedBody === null) { $this->decodedBody = []; } elseif (is_bool($this->decodedBody)) { // Backwards compatibility for Graph < 2.1. // Mimics 2.1 responses. // @TODO Remove this after Graph 2.0 is no longer supported $this->decodedBody = ['success' => $this->decodedBody]; } elseif (is_numeric($this->decodedBody)) { $this->decodedBody = ['id' => $this->decodedBody]; } if (!is_array($this->decodedBody)) { $this->decodedBody = []; } if ($this->isError()) { $this->makeException(); } } }