Skip to content

Commit

Permalink
[Compatible-246] - remove extractBody (Zend_Http)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuccv committed Apr 5, 2023
1 parent 8dc3da5 commit 7061b92
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Model/Activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
namespace Mageplaza\Core\Model;

use Exception;
use Laminas\Http\Request;
use Magento\Framework\DataObject;
use Magento\Framework\HTTP\Adapter\CurlFactory;
use Mageplaza\Core\Helper\AbstractData;
use Zend_Http_Client;
use Zend_Http_Response;

/**
* Class Activate
Expand All @@ -36,7 +35,7 @@ class Activate extends DataObject
{
/**
* Localhost maybe not active via https
* @inheritdoc
*
*/
const MAGEPLAZA_ACTIVE_URL = 'https://dashboard.mageplaza.com/license/index/activate/?isAjax=true';

Expand Down Expand Up @@ -71,7 +70,7 @@ public function activate($params = [])

$curl = $this->curlFactory->create();
$curl->write(
Zend_Http_Client::POST,
Request::METHOD_POST,
self::MAGEPLAZA_ACTIVE_URL,
'1.1',
[],
Expand All @@ -83,8 +82,8 @@ public function activate($params = [])
if (empty($resultCurl)) {
$result['message'] = __('Cannot connect to server. Please try again later.');
} else {
$responseBody = Zend_Http_Response::extractBody($resultCurl);
$result += AbstractData::jsonDecode($responseBody);
$responseBody = $this->extractBody($resultCurl);
$result += AbstractData::jsonDecode($responseBody);
if (isset($result['status']) && in_array($result['status'], [200, 201])) {
$result['success'] = true;
}
Expand All @@ -97,4 +96,21 @@ public function activate($params = [])

return $result;
}

/**
* Extract the body from a response string
*
* @param string $response_str
*
* @return string
*/
public static function extractBody(string $response_str): string
{
$parts = preg_split('|(?:\r\n){2}|m', $response_str, 2);
if (isset($parts[1])) {
return $parts[1];
}

return '';
}
}

0 comments on commit 7061b92

Please sign in to comment.