Skip to content

Commit 8892e7b

Browse files
committed
Merge pull request #60 from magento-tango/MAGETWO-31522
[Tango] S45 Controller Refactoring
2 parents a68cc70 + 57c8b15 commit 8892e7b

File tree

223 files changed

+5035
-2505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

223 files changed

+5035
-2505
lines changed

app/code/Magento/Catalog/Controller/Product/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class View extends \Magento\Catalog\Controller\Product
1818
protected $viewHelper;
1919

2020
/**
21-
* @var \Magento\Framework\Controller\Result\Redirect
21+
* @var \Magento\Framework\Controller\Result\RedirectFactory
2222
*/
2323
protected $resultRedirectFactory;
2424

app/code/Magento/Catalog/Helper/Product/Composite.php

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\Framework\App\Helper\Context;
10-
use Magento\Framework\App\ViewInterface;
10+
use Magento\Framework\View\Result\LayoutFactory;
1111
use Magento\Framework\Exception\NoSuchEntityException;
1212
use Magento\Catalog\Helper\Product;
1313
use Magento\Store\Model\StoreManagerInterface;
@@ -43,9 +43,9 @@ class Composite extends \Magento\Framework\App\Helper\AbstractHelper
4343
protected $_storeManager;
4444

4545
/**
46-
* @var ViewInterface
46+
* @var \Magento\Framework\View\Result\LayoutFactory
4747
*/
48-
protected $_view;
48+
protected $resultLayoutFactory;
4949

5050
/**
5151
* @var ProductRepositoryInterface
@@ -62,7 +62,7 @@ class Composite extends \Magento\Framework\App\Helper\AbstractHelper
6262
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
6363
* @param Product $catalogProduct
6464
* @param Registry $coreRegistry
65-
* @param ViewInterface $view
65+
* @param LayoutFactory $resultLayoutFactory
6666
* @param ProductRepositoryInterface $productRepository
6767
* @param CustomerRepositoryInterface $customerRepository
6868
*/
@@ -71,14 +71,14 @@ public function __construct(
7171
StoreManagerInterface $storeManager,
7272
Product $catalogProduct,
7373
Registry $coreRegistry,
74-
ViewInterface $view,
74+
LayoutFactory $resultLayoutFactory,
7575
ProductRepositoryInterface $productRepository,
7676
CustomerRepositoryInterface $customerRepository
7777
) {
7878
$this->_storeManager = $storeManager;
7979
$this->_coreRegistry = $coreRegistry;
8080
$this->_catalogProduct = $catalogProduct;
81-
$this->_view = $view;
81+
$this->resultLayoutFactory = $resultLayoutFactory;
8282
$this->productRepository = $productRepository;
8383
$this->customerRepository = $customerRepository;
8484
parent::__construct($context);
@@ -87,30 +87,26 @@ public function __construct(
8787
/**
8888
* Init layout of product configuration update result
8989
*
90-
* @return $this
90+
* @return \Magento\Framework\View\Result\Layout
9191
*/
9292
protected function _initUpdateResultLayout()
9393
{
94-
$this->_view->getLayout()->getUpdate()->addHandle('CATALOG_PRODUCT_COMPOSITE_UPDATE_RESULT');
95-
$this->_view->loadLayoutUpdates();
96-
$this->_view->generateLayoutXml();
97-
$this->_view->generateLayoutBlocks();
98-
return $this;
94+
$resultLayout = $this->resultLayoutFactory->create();
95+
$resultLayout->addHandle('CATALOG_PRODUCT_COMPOSITE_UPDATE_RESULT');
96+
return $resultLayout;
9997
}
10098

10199
/**
102100
* Prepares and render result of composite product configuration update for a case
103101
* when single configuration submitted
104102
*
105103
* @param \Magento\Framework\Object $updateResult
106-
* @return void
104+
* @return \Magento\Framework\View\Result\Layout
107105
*/
108106
public function renderUpdateResult(\Magento\Framework\Object $updateResult)
109107
{
110108
$this->_coreRegistry->register('composite_update_result', $updateResult);
111-
112-
$this->_initUpdateResultLayout();
113-
$this->_view->renderLayout();
109+
return $this->_initUpdateResultLayout();
114110
}
115111

116112
/**
@@ -121,24 +117,18 @@ public function renderUpdateResult(\Magento\Framework\Object $updateResult)
121117
*
122118
* @param bool $isOk
123119
* @param string $productType
124-
* @return $this
120+
* @return \Magento\Framework\View\Result\Layout
125121
*/
126122
protected function _initConfigureResultLayout($isOk, $productType)
127123
{
128-
$update = $this->_view->getLayout()->getUpdate();
124+
$resultLayout = $this->resultLayoutFactory->create();
129125
if ($isOk) {
130-
$update->addHandle(
131-
'CATALOG_PRODUCT_COMPOSITE_CONFIGURE'
132-
)->addHandle(
133-
'catalog_product_view_type_' . $productType
134-
);
126+
$resultLayout->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE')
127+
->addHandle('catalog_product_view_type_' . $productType);
135128
} else {
136-
$update->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE_ERROR');
129+
$resultLayout->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE_ERROR');
137130
}
138-
$this->_view->loadLayoutUpdates();
139-
$this->_view->generateLayoutXml();
140-
$this->_view->generateLayoutBlocks();
141-
return $this;
131+
return $resultLayout;
142132
}
143133

144134
/**
@@ -149,7 +139,7 @@ protected function _initConfigureResultLayout($isOk, $productType)
149139
* - 'error' = true, and 'message' to show
150140
*
151141
* @param \Magento\Framework\Object $configureResult
152-
* @return void
142+
* @return \Magento\Framework\View\Result\Layout
153143
*/
154144
public function renderConfigureResult(\Magento\Framework\Object $configureResult)
155145
{
@@ -194,7 +184,6 @@ public function renderConfigureResult(\Magento\Framework\Object $configureResult
194184
$this->_coreRegistry->register('composite_configure_result_error_message', $e->getMessage());
195185
}
196186

197-
$this->_initConfigureResultLayout($isOk, $productType);
198-
$this->_view->renderLayout();
187+
return $this->_initConfigureResultLayout($isOk, $productType);
199188
}
200189
}

app/code/Magento/Customer/Controller/Account.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Customer\Model\Session;
99
use Magento\Framework\App\Action\Context;
1010
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\Controller\Result\RedirectFactory;
12+
use Magento\Framework\View\Result\PageFactory;
1113

1214
/**
1315
* Customer account controller
@@ -40,15 +42,31 @@ class Account extends \Magento\Framework\App\Action\Action
4042
/** @var Session */
4143
protected $session;
4244

45+
/**
46+
* @var RedirectFactory
47+
*/
48+
protected $resultRedirectFactory;
49+
50+
/**
51+
* @var PageFactory
52+
*/
53+
protected $resultPageFactory;
54+
4355
/**
4456
* @param Context $context
4557
* @param Session $customerSession
58+
* @param RedirectFactory $resultRedirectFactory
59+
* @param PageFactory $resultPageFactory
4660
*/
4761
public function __construct(
4862
Context $context,
49-
Session $customerSession
63+
Session $customerSession,
64+
RedirectFactory $resultRedirectFactory,
65+
PageFactory $resultPageFactory
5066
) {
5167
$this->session = $customerSession;
68+
$this->resultRedirectFactory = $resultRedirectFactory;
69+
$this->resultPageFactory = $resultPageFactory;
5270
parent::__construct($context);
5371
}
5472

app/code/Magento/Customer/Controller/Account/Confirm.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Framework\App\Action\Context;
1111
use Magento\Customer\Model\Session;
1212
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\Controller\Result\RedirectFactory;
14+
use Magento\Framework\View\Result\PageFactory;
1315
use Magento\Store\Model\StoreManagerInterface;
1416
use Magento\Customer\Api\AccountManagementInterface;
1517
use Magento\Customer\Api\CustomerRepositoryInterface;
@@ -46,16 +48,22 @@ class Confirm extends \Magento\Customer\Controller\Account
4648
/**
4749
* @param Context $context
4850
* @param Session $customerSession
51+
* @param RedirectFactory $resultRedirectFactory
52+
* @param PageFactory $resultPageFactory
4953
* @param ScopeConfigInterface $scopeConfig
5054
* @param StoreManagerInterface $storeManager
5155
* @param AccountManagementInterface $customerAccountManagement
5256
* @param CustomerRepositoryInterface $customerRepository
5357
* @param Address $addressHelper
5458
* @param UrlFactory $urlFactory
59+
*
60+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
5561
*/
5662
public function __construct(
5763
Context $context,
5864
Session $customerSession,
65+
RedirectFactory $resultRedirectFactory,
66+
PageFactory $resultPageFactory,
5967
ScopeConfigInterface $scopeConfig,
6068
StoreManagerInterface $storeManager,
6169
AccountManagementInterface $customerAccountManagement,
@@ -69,19 +77,22 @@ public function __construct(
6977
$this->customerRepository = $customerRepository;
7078
$this->addressHelper = $addressHelper;
7179
$this->urlModel = $urlFactory->create();
72-
parent::__construct($context, $customerSession);
80+
parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory);
7381
}
7482

7583
/**
7684
* Confirm customer account by id and confirmation key
7785
*
78-
* @return void
86+
* @return \Magento\Framework\Controller\Result\Redirect
7987
*/
8088
public function execute()
8189
{
90+
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
91+
$resultRedirect = $this->resultRedirectFactory->create();
92+
8293
if ($this->_getSession()->isLoggedIn()) {
83-
$this->_redirect('*/*/');
84-
return;
94+
$resultRedirect->setPath('*/*/');
95+
return $resultRedirect;
8596
}
8697
try {
8798
$customerId = $this->getRequest()->getParam('id', false);
@@ -96,17 +107,17 @@ public function execute()
96107
$this->_getSession()->setCustomerDataAsLoggedIn($customer);
97108

98109
$this->messageManager->addSuccess($this->getSuccessMessage());
99-
$this->getResponse()->setRedirect($this->getSuccessRedirect());
100-
return;
110+
$resultRedirect->setUrl($this->getSuccessRedirect());
111+
return $resultRedirect;
101112
} catch (StateException $e) {
102113
$this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
103114
} catch (\Exception $e) {
104115
$this->messageManager->addException($e, __('There was an error confirming the account'));
105116
}
106117
// die unhappy
107118
$url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
108-
$this->getResponse()->setRedirect($this->_redirect->error($url));
109-
return;
119+
$resultRedirect->setUrl($this->_redirect->error($url));
120+
return $resultRedirect;
110121
}
111122

112123
/**

app/code/Magento/Customer/Controller/Account/Confirmation.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
use Magento\Framework\App\Action\Context;
1010
use Magento\Customer\Model\Session;
11+
use Magento\Framework\Controller\Result\RedirectFactory;
12+
use Magento\Framework\View\Result\PageFactory;
1113
use Magento\Store\Model\StoreManagerInterface;
1214
use Magento\Customer\Api\AccountManagementInterface;
13-
use Magento\Framework\UrlFactory;
1415
use Magento\Framework\Exception\State\InvalidTransitionException;
1516

1617
class Confirmation extends \Magento\Customer\Controller\Account
@@ -21,44 +22,47 @@ class Confirmation extends \Magento\Customer\Controller\Account
2122
/** @var AccountManagementInterface */
2223
protected $customerAccountManagement;
2324

24-
/** @var \Magento\Framework\UrlInterface */
25-
protected $urlModel;
26-
2725
/**
2826
* @param Context $context
2927
* @param Session $customerSession
28+
* @param RedirectFactory $resultRedirectFactory
29+
* @param PageFactory $resultPageFactory
3030
* @param StoreManagerInterface $storeManager
3131
* @param AccountManagementInterface $customerAccountManagement
32-
* @param UrlFactory $urlFactory
3332
*/
3433
public function __construct(
3534
Context $context,
3635
Session $customerSession,
36+
RedirectFactory $resultRedirectFactory,
37+
PageFactory $resultPageFactory,
3738
StoreManagerInterface $storeManager,
38-
AccountManagementInterface $customerAccountManagement,
39-
UrlFactory $urlFactory
39+
AccountManagementInterface $customerAccountManagement
4040
) {
4141
$this->storeManager = $storeManager;
4242
$this->customerAccountManagement = $customerAccountManagement;
43-
$this->urlModel = $urlFactory->create();
44-
parent::__construct($context, $customerSession);
43+
parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory);
4544
}
4645

4746
/**
4847
* Send confirmation link to specified email
4948
*
50-
* @return void
49+
* @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
5150
*/
5251
public function execute()
5352
{
5453
if ($this->_getSession()->isLoggedIn()) {
55-
$this->_redirect('*/*/');
56-
return;
54+
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
55+
$resultRedirect = $this->resultRedirectFactory->create();
56+
$resultRedirect->setPath('*/*/');
57+
return $resultRedirect;
5758
}
5859

5960
// try to confirm by email
6061
$email = $this->getRequest()->getPost('email');
6162
if ($email) {
63+
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
64+
$resultRedirect = $this->resultRedirectFactory->create();
65+
6266
try {
6367
$this->customerAccountManagement->resendConfirmation(
6468
$email,
@@ -69,26 +73,20 @@ public function execute()
6973
$this->messageManager->addSuccess(__('This email does not require confirmation.'));
7074
} catch (\Exception $e) {
7175
$this->messageManager->addException($e, __('Wrong email.'));
72-
$this->getResponse()->setRedirect(
73-
$this->urlModel->getUrl('*/*/*', ['email' => $email, '_secure' => true])
74-
);
75-
return;
76+
$resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]);
77+
return $resultRedirect;
7678
}
7779
$this->_getSession()->setUsername($email);
78-
$this->getResponse()->setRedirect($this->urlModel->getUrl('*/*/index', ['_secure' => true]));
79-
return;
80+
$resultRedirect->setPath('*/*/index', ['_secure' => true]);
81+
return $resultRedirect;
8082
}
8183

82-
// output form
83-
$this->_view->loadLayout();
84-
85-
$this->_view->getLayout()->getBlock(
86-
'accountConfirmation'
87-
)->setEmail(
84+
/** @var \Magento\Framework\View\Result\Page $resultPage */
85+
$resultPage = $this->resultPageFactory->create();
86+
$resultPage->getLayout()->getBlock('accountConfirmation')->setEmail(
8887
$this->getRequest()->getParam('email', $email)
8988
);
90-
91-
$this->_view->getLayout()->initMessages();
92-
$this->_view->renderLayout();
89+
$resultPage->getLayout()->initMessages();
90+
return $resultPage;
9391
}
9492
}

0 commit comments

Comments
 (0)