AfterCustomUrlChangedObserver.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Observer\Config\Backend\Admin;
  7. use Magento\Framework\Event\ObserverInterface;
  8. class AfterCustomUrlChangedObserver implements ObserverInterface
  9. {
  10. /**
  11. * Backend data
  12. *
  13. * @var \Magento\Backend\Helper\Data
  14. */
  15. protected $_backendData;
  16. /**
  17. * Core registry
  18. *
  19. * @var \Magento\Framework\Registry
  20. */
  21. protected $_coreRegistry;
  22. /**
  23. * @var \Magento\Backend\Model\Auth\Session
  24. */
  25. protected $_authSession;
  26. /**
  27. * @var \Magento\Framework\App\ResponseInterface
  28. */
  29. protected $_response;
  30. /**
  31. * @param \Magento\Backend\Helper\Data $backendData
  32. * @param \Magento\Framework\Registry $coreRegistry
  33. * @param \Magento\Backend\Model\Auth\Session $authSession
  34. * @param \Magento\Framework\App\ResponseInterface $response
  35. */
  36. public function __construct(
  37. \Magento\Backend\Helper\Data $backendData,
  38. \Magento\Framework\Registry $coreRegistry,
  39. \Magento\Backend\Model\Auth\Session $authSession,
  40. \Magento\Framework\App\ResponseInterface $response
  41. ) {
  42. $this->_backendData = $backendData;
  43. $this->_coreRegistry = $coreRegistry;
  44. $this->_authSession = $authSession;
  45. $this->_response = $response;
  46. }
  47. /**
  48. * Log out user and redirect to new admin custom url
  49. *
  50. * @param \Magento\Framework\Event\Observer $observer
  51. * @return void
  52. * @SuppressWarnings(PHPMD.ExitExpression)
  53. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  54. */
  55. public function execute(\Magento\Framework\Event\Observer $observer)
  56. {
  57. if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) {
  58. return;
  59. }
  60. $this->_authSession->destroy();
  61. $adminUrl = $this->_backendData->getHomePageUrl();
  62. $this->_response->setRedirect($adminUrl)->sendResponse();
  63. exit(0);
  64. }
  65. }