Skip to content

Commit cfe3b7d

Browse files
committed
Make session classes to be instantiated configurable via DI
1 parent 1ef90b2 commit cfe3b7d

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

Plugin/SectionLoadControllerPlugin.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
namespace IntegerNet\SessionUnblocker\Plugin;
55

6-
use \Magento\Framework\Session\Generic as GenericSession;
7-
use \Magento\Customer\Model\Session as CustomerSession;
8-
use \Magento\Framework\Message\Session as MessageSession;
9-
use \Magento\Catalog\Model\Session as CatalogSession;
6+
use Magento\Framework\Session\Generic as GenericSession;
7+
use Magento\Framework\Session\SessionManagerInterface;
108

119
/**
1210
* We are writing this plugin to make sure sessions are all loaded before
@@ -25,10 +23,7 @@ class SectionLoadControllerPlugin
2523
{
2624
/**
2725
* @param GenericSession $genericSession
28-
* @param CustomerSession $customerSession
29-
* @param MessageSession $messageSession
30-
* @param CatalogSession $catalogSession
31-
* @param GenericSession $reviewSession
26+
* @param SessionManagerInterface[] $additionalSessions
3227
*
3328
* Disabling 3 PHPCS rules because:
3429
* 1 - We are well aware that we normally shouldn't call Sessions without
@@ -43,10 +38,7 @@ class SectionLoadControllerPlugin
4338
*/
4439
public function __construct(
4540
GenericSession $genericSession,
46-
CustomerSession $customerSession,
47-
MessageSession $messageSession,
48-
CatalogSession $catalogSession,
49-
GenericSession $reviewSession //virtualType
41+
array $additionalSessions = []
5042
) {
5143
/*
5244
* This is earliest moment where we can close the session,

etc/di.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
<type name="IntegerNet\SessionUnblocker\Plugin\SectionLoadControllerPlugin">
1212
<arguments>
13-
<argument name="reviewSession" xsi:type="object">Magento\Review\Model\Session</argument>
13+
<argument name="additionalSessions" xsi:type="array">
14+
<item name="customerSession" xsi:type="object">Magento\Customer\Model\Session</item>
15+
<item name="messageSession" xsi:type="object">Magento\Framework\Message\Session</item>
16+
<item name="catalogSession" xsi:type="object">Magento\Catalog\Model\Session</item>
17+
<item name="reviewSession" xsi:type="object">Magento\Review\Model\Session</item>
18+
</argument>
1419
</arguments>
1520
</type>
1621
</config>

0 commit comments

Comments
 (0)