Skip to content

Commit

Permalink
Fixed PHP 7.3 compatibility issue of error Serialization of Closure i…
Browse files Browse the repository at this point in the history
…s not allowed
  • Loading branch information
litespeedtech committed Jul 1, 2019
1 parent 447e10f commit 4b283a8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
3 changes: 1 addition & 2 deletions Controller/Block/CustomVary.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public function execute()
{
$ajaxReload = false;
if ($this->litemageCache->moduleEnabled()) {
$rawvarydata = '';
$ajaxReload = $this->litemageCache->checkCacheVary($rawvarydata);
$ajaxReload = $this->litemageCache->checkCacheVary();
}
$result = $this->jsonFactory->create();
return $result->setData(['success' => true, 'ajaxReload' => $ajaxReload]);
Expand Down
18 changes: 10 additions & 8 deletions Model/CacheControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class CacheControl

protected $helper;

protected $rawVaryString; // for debug only

/**
* constructor
*
Expand Down Expand Up @@ -288,8 +290,7 @@ public function setCacheControlHeaders($response)
{
$cacheControlHeader = '';
$lstags = '';
$rawvarydata = '';
$changed = $this->checkCacheVary($rawvarydata);
$changed = $this->checkCacheVary();

$responsecode = $response->getHttpResponseCode();
if (( $responsecode == 200 || $responsecode == 404) && ($this->_isCacheable == 1)
Expand Down Expand Up @@ -321,7 +322,7 @@ public function setCacheControlHeaders($response)
$response->setHeader(self::LSHEADER_DEBUG_CC, $cacheControlHeader);
$response->setHeader(self::LSHEADER_DEBUG_Tag, $lstags);
$response->setHeader(self::LSHEADER_DEBUG_INFO, substr(htmlspecialchars(str_replace("\n", ' ', $this->_nocacheReason)), 0, 256));
$response->setHeader(self::LSHEADER_DEBUG_VARY, $rawvarydata);
$response->setHeader(self::LSHEADER_DEBUG_VARY, $this->rawVaryString);
}
}

Expand All @@ -339,9 +340,10 @@ protected function _setCacheTagHeader($response)
return $lstags;
}

public function checkCacheVary(&$rawdata)
public function checkCacheVary()
{
// check custvary first
$rawdata = $varyString = '';
$varymode = $this->config->getCustomVaryMode();
if ($varymode == 2) {
$this->httpContext->setValue('litemage_custvary_enforce', $varymode, 0);
Expand All @@ -355,7 +357,6 @@ public function checkCacheVary(&$rawdata)
}
}

$varyString = null;
$data = $this->httpContext->getData();

// always check store & currency again. some bad plugins will update store without updating context
Expand All @@ -376,12 +377,12 @@ public function checkCacheVary(&$rawdata)
$data = array_filter($data, function($k) {
return (!in_array($k, $this->_bypassedContext));
}, ARRAY_FILTER_USE_KEY);
}
}

if (!empty($data)) {
ksort($data);
$rawdata = http_build_query($data);
$varyString = sha1(serialize($data));
$varyString = sha1(json_encode($data));
}

$changed = false;
Expand All @@ -404,6 +405,7 @@ public function checkCacheVary(&$rawdata)
if ($this->_debug && $rawdata) {
$this->debugLog("EnvVary: $rawdata");
}
$this->rawVaryString = $rawdata;
return $changed;
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"magento/framework": "*"
},
"type": "magento2-module",
"version": "2.1.1",
"version": "2.1.2",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Litespeed_Litemage" setup_version="2.1.1">
<module name="Litespeed_Litemage" setup_version="2.1.2">
<sequence>
<module name="Magento_PageCache"/>
</sequence>
Expand Down

0 comments on commit 4b283a8

Please sign in to comment.