BackendAppList.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\App;
  7. /**
  8. * List of Backend Applications to allow injection of them through the DI
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class BackendAppList
  13. {
  14. /**
  15. * @var BackendApp[]
  16. */
  17. private $backendApps = [];
  18. /**
  19. * @var \Magento\Framework\App\RequestInterface
  20. */
  21. private $request;
  22. /**
  23. * @param \Magento\Framework\App\Request\Http $request
  24. * @param array $backendApps
  25. */
  26. public function __construct(
  27. \Magento\Framework\App\Request\Http $request,
  28. array $backendApps = []
  29. ) {
  30. $this->backendApps = $backendApps;
  31. $this->request = $request;
  32. }
  33. /**
  34. * Get Backend app based on its name
  35. *
  36. * @return BackendApp|null
  37. */
  38. public function getCurrentApp()
  39. {
  40. $appName = $this->request->getQuery('app');
  41. if ($appName && isset($this->backendApps[$appName])) {
  42. return $this->backendApps[$appName];
  43. }
  44. return null;
  45. }
  46. /**
  47. * Retrieve backend application by name
  48. *
  49. * @param string $appName
  50. * @return BackendApp|null
  51. */
  52. public function getBackendApp($appName)
  53. {
  54. if (isset($this->backendApps[$appName])) {
  55. return $this->backendApps[$appName];
  56. }
  57. return null;
  58. }
  59. }