Address.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Controller;
  7. use Magento\Framework\App\RequestInterface;
  8. /**
  9. * Customer address controller
  10. *
  11. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  12. */
  13. abstract class Address extends \Magento\Framework\App\Action\Action
  14. {
  15. /**
  16. * @var \Magento\Customer\Model\Session
  17. */
  18. protected $_customerSession;
  19. /**
  20. * @var \Magento\Framework\Data\Form\FormKey\Validator
  21. */
  22. protected $_formKeyValidator;
  23. /**
  24. * @var \Magento\Customer\Api\AddressRepositoryInterface
  25. */
  26. protected $_addressRepository;
  27. /**
  28. * @var \Magento\Customer\Model\Metadata\FormFactory
  29. */
  30. protected $_formFactory;
  31. /**
  32. * @var \Magento\Customer\Api\Data\AddressInterfaceFactory
  33. */
  34. protected $addressDataFactory;
  35. /**
  36. * @var \Magento\Customer\Api\Data\RegionInterfaceFactory
  37. */
  38. protected $regionDataFactory;
  39. /**
  40. * @var \Magento\Framework\Reflection\DataObjectProcessor
  41. */
  42. protected $_dataProcessor;
  43. /**
  44. * @var \Magento\Framework\Api\DataObjectHelper
  45. */
  46. protected $dataObjectHelper;
  47. /**
  48. * @var \Magento\Framework\Controller\Result\ForwardFactory
  49. */
  50. protected $resultForwardFactory;
  51. /**
  52. * @var \Magento\Framework\View\Result\PageFactory
  53. */
  54. protected $resultPageFactory;
  55. /**
  56. * @param \Magento\Framework\App\Action\Context $context
  57. * @param \Magento\Customer\Model\Session $customerSession
  58. * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
  59. * @param \Magento\Customer\Model\Metadata\FormFactory $formFactory
  60. * @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
  61. * @param \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory
  62. * @param \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory
  63. * @param \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor
  64. * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
  65. * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory
  66. * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
  67. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  68. */
  69. public function __construct(
  70. \Magento\Framework\App\Action\Context $context,
  71. \Magento\Customer\Model\Session $customerSession,
  72. \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
  73. \Magento\Customer\Model\Metadata\FormFactory $formFactory,
  74. \Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
  75. \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory,
  76. \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory,
  77. \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor,
  78. \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
  79. \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
  80. \Magento\Framework\View\Result\PageFactory $resultPageFactory
  81. ) {
  82. $this->_customerSession = $customerSession;
  83. $this->_formKeyValidator = $formKeyValidator;
  84. $this->_formFactory = $formFactory;
  85. $this->_addressRepository = $addressRepository;
  86. $this->addressDataFactory = $addressDataFactory;
  87. $this->regionDataFactory = $regionDataFactory;
  88. $this->_dataProcessor = $dataProcessor;
  89. $this->dataObjectHelper = $dataObjectHelper;
  90. $this->resultForwardFactory = $resultForwardFactory;
  91. $this->resultPageFactory = $resultPageFactory;
  92. parent::__construct($context);
  93. }
  94. /**
  95. * Retrieve customer session object
  96. *
  97. * @return \Magento\Customer\Model\Session
  98. */
  99. protected function _getSession()
  100. {
  101. return $this->_customerSession;
  102. }
  103. /**
  104. * Check customer authentication
  105. *
  106. * @param RequestInterface $request
  107. * @return \Magento\Framework\App\ResponseInterface
  108. */
  109. public function dispatch(RequestInterface $request)
  110. {
  111. if (!$this->_getSession()->authenticate()) {
  112. $this->_actionFlag->set('', 'no-dispatch', true);
  113. }
  114. return parent::dispatch($request);
  115. }
  116. /**
  117. * @param string $route
  118. * @param array $params
  119. * @return string
  120. */
  121. protected function _buildUrl($route = '', $params = [])
  122. {
  123. /** @var \Magento\Framework\UrlInterface $urlBuilder */
  124. $urlBuilder = $this->_objectManager->create(\Magento\Framework\UrlInterface::class);
  125. return $urlBuilder->getUrl($route, $params);
  126. }
  127. }