Skip to content

Commit 4fbd604

Browse files
committed
39099: Move constant variable to a new method for extensibility
1 parent f0e97ed commit 4fbd604

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

app/code/Magento/PageCache/Model/App/Request/Http/IdentifierForSave.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\PageCache\Model\App\Request\Http;
99

1010
use Magento\Framework\App\Http\Context;
11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\App\PageCache\Identifier;
1213
use Magento\Framework\App\PageCache\IdentifierInterface;
1314
use Magento\Framework\App\Request\Http;
@@ -23,13 +24,17 @@ class IdentifierForSave implements IdentifierInterface
2324
* @param Context $context
2425
* @param Json $serializer
2526
* @param IdentifierStoreReader $identifierStoreReader
27+
* @param Identifier|null $identifier
2628
*/
2729
public function __construct(
2830
private Http $request,
2931
private Context $context,
3032
private Json $serializer,
3133
private IdentifierStoreReader $identifierStoreReader,
34+
private ?Identifier $identifier = null
3235
) {
36+
$this->identifier = $identifier ?: ObjectManager::getInstance()
37+
->get(Identifier::class);
3338
}
3439

3540
/**
@@ -39,7 +44,7 @@ public function __construct(
3944
*/
4045
public function getValue()
4146
{
42-
$pattern = Identifier::PATTERN_MARKETING_PARAMETERS;
47+
$pattern = $this->identifier->getMarketingParameterPatterns();
4348
$replace = array_fill(0, count($pattern), '');
4449
$data = [
4550
$this->request->isSecure(),

lib/internal/Magento/Framework/App/PageCache/Identifier.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,6 @@
1313
*/
1414
class Identifier implements IdentifierInterface
1515
{
16-
/**
17-
* Pattern detect marketing parameters
18-
*/
19-
public const PATTERN_MARKETING_PARAMETERS = [
20-
'/&?gad_source\=[^&]+/',
21-
'/&?gbraid\=[^&]+/',
22-
'/&?wbraid\=[^&]+/',
23-
'/&?_gl\=[^&]+/',
24-
'/&?dclid\=[^&]+/',
25-
'/&?gclsrc\=[^&]+/',
26-
'/&?srsltid\=[^&]+/',
27-
'/&?msclkid\=[^&]+/',
28-
'/&?_kx\=[^&]+/',
29-
'/&?gclid\=[^&]+/',
30-
'/&?cx\=[^&]+/',
31-
'/&?ie\=[^&]+/',
32-
'/&?cof\=[^&]+/',
33-
'/&?siteurl\=[^&]+/',
34-
'/&?zanpid\=[^&]+/',
35-
'/&?origin\=[^&]+/',
36-
'/&?fbclid\=[^&]+/',
37-
'/&?mc_(.*?)\=[^&]+/',
38-
'/&?utm_(.*?)\=[^&]+/',
39-
'/&?_bta_(.*?)\=[^&]+/',
40-
];
41-
4216
/**
4317
* @var \Magento\Framework\App\Request\Http
4418
*/
@@ -76,8 +50,8 @@ public function __construct(
7650
*/
7751
public function getValue()
7852
{
79-
$pattern = self::PATTERN_MARKETING_PARAMETERS;
80-
$replace = array_fill(0, count(self::PATTERN_MARKETING_PARAMETERS), '');
53+
$pattern = $this->getMarketingParameterPatterns();
54+
$replace = array_fill(0, count($pattern), '');
8155
$data = [
8256
$this->request->isSecure(),
8357
preg_replace($pattern, $replace, (string)$this->request->getUriString()),
@@ -87,4 +61,36 @@ public function getValue()
8761

8862
return sha1($this->serializer->serialize($data));
8963
}
64+
65+
/**
66+
* Pattern detect marketing parameters
67+
*
68+
*
69+
* @return array
70+
*/
71+
public function getMarketingParameterPatterns(): array
72+
{
73+
return [
74+
'/&?gad_source\=[^&]+/',
75+
'/&?gbraid\=[^&]+/',
76+
'/&?wbraid\=[^&]+/',
77+
'/&?_gl\=[^&]+/',
78+
'/&?dclid\=[^&]+/',
79+
'/&?gclsrc\=[^&]+/',
80+
'/&?srsltid\=[^&]+/',
81+
'/&?msclkid\=[^&]+/',
82+
'/&?_kx\=[^&]+/',
83+
'/&?gclid\=[^&]+/',
84+
'/&?cx\=[^&]+/',
85+
'/&?ie\=[^&]+/',
86+
'/&?cof\=[^&]+/',
87+
'/&?siteurl\=[^&]+/',
88+
'/&?zanpid\=[^&]+/',
89+
'/&?origin\=[^&]+/',
90+
'/&?fbclid\=[^&]+/',
91+
'/&?mc_(.*?)\=[^&]+/',
92+
'/&?utm_(.*?)\=[^&]+/',
93+
'/&?_bta_(.*?)\=[^&]+/',
94+
];
95+
}
9096
}

0 commit comments

Comments
 (0)