Skip to content

Commit 6950ee8

Browse files
ihorvansachnaydav
authored andcommitted
[Login As Customer] get rid of the object manager
1 parent bfacf2b commit 6950ee8

File tree

4 files changed

+38
-41
lines changed

4 files changed

+38
-41
lines changed

app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ class Index extends \Magento\Backend\App\Action
2020
/**
2121
* @var \Magento\LoginAsCustomer\Model\Login
2222
*/
23-
private $loginModel = null;
23+
private $loginModel;
2424

2525
/**
2626
* Index constructor.
2727
* @param \Magento\Backend\App\Action\Context $context
28-
* @param \Magento\LoginAsCustomer\Model\Login|null $login
28+
* @param \Magento\LoginAsCustomer\Model\Login $loginModel
2929
*/
3030
public function __construct(
3131
\Magento\Backend\App\Action\Context $context,
32-
\Magento\LoginAsCustomer\Model\Login $loginModel = null
32+
\Magento\LoginAsCustomer\Model\Login $loginModel
3333
) {
3434
parent::__construct($context);
35-
$this->loginModel = $loginModel ?: $this->_objectManager->get(\Magento\LoginAsCustomer\Model\Login::class);
35+
$this->loginModel = $loginModel;
3636
}
3737
/**
3838
* Login as customer log

app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Login.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,50 @@ class Login extends \Magento\Backend\App\Action
2222
* @var \Magento\LoginAsCustomer\Model\Login
2323
*/
2424
private $loginModel;
25+
2526
/**
2627
* @var \Magento\Backend\Model\Auth\Session
2728
*/
28-
private $authSession = null;
29+
private $authSession;
30+
2931
/**
3032
* @var \Magento\Store\Model\StoreManagerInterface
3133
*/
32-
private $storeManager = null;
34+
private $storeManager;
35+
3336
/**
3437
* @var \Magento\Framework\Url
3538
*/
36-
private $url = null;
39+
private $url;
40+
3741
/**
3842
* @var \Magento\LoginAsCustomer\Model\Config
3943
*/
40-
private $config = null;
44+
private $config;
4145

4246
/**
4347
* Login constructor.
4448
* @param \Magento\Backend\App\Action\Context $context
45-
* @param \Magento\LoginAsCustomer\Model\Login|null $loginModel
46-
* @param \Magento\Backend\Model\Auth\Session|null $authSession
47-
* @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
48-
* @param \Magento\Framework\Url|null $url
49-
* @param \Magento\LoginAsCustomer\Model\Config|null $config
49+
* @param \Magento\LoginAsCustomer\Model\Login $loginModel
50+
* @param \Magento\Backend\Model\Auth\Session $authSession
51+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
52+
* @param \Magento\Framework\Url $url
53+
* @param \Magento\LoginAsCustomer\Model\Config $config
5054
*/
5155
public function __construct(
5256
\Magento\Backend\App\Action\Context $context,
53-
\Magento\LoginAsCustomer\Model\Login $loginModel = null,
54-
\Magento\Backend\Model\Auth\Session $authSession = null,
55-
\Magento\Store\Model\StoreManagerInterface $storeManager = null,
56-
\Magento\Framework\Url $url = null,
57-
\Magento\LoginAsCustomer\Model\Config $config = null
57+
\Magento\LoginAsCustomer\Model\Login $loginModel,
58+
\Magento\Backend\Model\Auth\Session $authSession,
59+
\Magento\Store\Model\StoreManagerInterface $storeManager,
60+
\Magento\Framework\Url $url,
61+
\Magento\LoginAsCustomer\Model\Config $config
5862
) {
5963
parent::__construct($context);
60-
$this->loginModel = $loginModel ?: $this->_objectManager->get(\Magento\LoginAsCustomer\Model\Login::class);
61-
$this->authSession = $authSession ?: $this->_objectManager->get(\Magento\Backend\Model\Auth\Session::class);
62-
$this->storeManager = $storeManager ?: $this->_objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
63-
$this->url = $url ?: $this->_objectManager->get(\Magento\Framework\Url::class);
64-
$this->config = $config ?: $this->_objectManager->get(\Magento\LoginAsCustomer\Model\Config::class);
64+
$this->loginModel = $loginModel;
65+
$this->authSession = $authSession;
66+
$this->storeManager = $storeManager;
67+
$this->url = $url;
68+
$this->config = $config;
6569
}
6670
/**
6771
* Login as customer action

app/code/Magento/LoginAsCustomer/Controller/Login/Index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ class Index extends \Magento\Framework\App\Action\Action
1717
/**
1818
* @var \Magento\LoginAsCustomer\Model\Login
1919
*/
20-
private $loginModel = null;
20+
private $loginModel;
2121

2222
/**
2323
* Index constructor.
2424
* @param \Magento\Framework\App\Action\Context $context
25-
* @param \Magento\LoginAsCustomer\Model\Login|null $loginModel
25+
* @param \Magento\LoginAsCustomer\Model\Login $loginModel
2626
*/
2727
public function __construct(
2828
\Magento\Framework\App\Action\Context $context,
29-
\Magento\LoginAsCustomer\Model\Login $loginModel = null
29+
\Magento\LoginAsCustomer\Model\Login $loginModel
3030
) {
3131
parent::__construct($context);
32-
$this->loginModel = $loginModel ?: $this->_objectManager->get(\Magento\LoginAsCustomer\Model\Login::class);
32+
$this->loginModel = $loginModel;
3333
}
3434
/**
3535
* Login as customer action

app/code/Magento/LoginAsCustomer/Model/Login.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,18 @@ class Login extends \Magento\Framework\Model\AbstractModel
7777

7878
/**
7979
* Initialize dependencies.
80-
*
8180
* @param \Magento\Framework\Model\Context $context
8281
* @param \Magento\Framework\Registry $registry
8382
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
8483
* @param \Magento\Customer\Model\Session $customerSession
8584
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
8685
* @param \Magento\Framework\Math\Random $random
8786
* @param \Magento\Checkout\Model\Cart $cart
87+
* @param \Magento\Checkout\Model\Session $checkoutSession
88+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
8889
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
8990
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
9091
* @param array $data
91-
* @param null|\Magento\Checkout\Model\Session $checkoutSession
92-
* @param null|\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
9392
*/
9493
public function __construct(
9594
\Magento\Framework\Model\Context $context,
@@ -99,26 +98,20 @@ public function __construct(
9998
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
10099
\Magento\Framework\Math\Random $random,
101100
\Magento\Checkout\Model\Cart $cart,
101+
\Magento\Checkout\Model\Session $checkoutSession,
102+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
102103
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
103104
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
104-
array $data = [],
105-
$checkoutSession = null,
106-
$scopeConfig = null
105+
array $data = []
107106
) {
108107
$this->_customerFactory = $customerFactory;
109108
$this->_customerSession = $customerSession;
110109
$this->_checkoutSession = $checkoutSession;
111110
$this->_dateTime = $dateTime;
112111
$this->_random = $random;
113112
$this->cart = $cart;
114-
115-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
116-
$this->_checkoutSession = $checkoutSession ?: $objectManager->get(
117-
\Magento\Checkout\Model\Session::class
118-
);
119-
$this->scopeConfig = $scopeConfig ?: $objectManager->get(
120-
\Magento\Framework\App\Config\ScopeConfigInterface::class
121-
);
113+
$this->_checkoutSession = $checkoutSession;
114+
$this->scopeConfig = $scopeConfig;
122115

123116
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
124117
}

0 commit comments

Comments
 (0)