DefaultPath.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Default application path for backend area
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Backend\App;
  9. /**
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class DefaultPath implements \Magento\Framework\App\DefaultPathInterface
  14. {
  15. /**
  16. * @var array
  17. */
  18. protected $_parts;
  19. /**
  20. * @param \Magento\Backend\App\ConfigInterface $config
  21. * @SuppressWarnings(PHPMD.NPathComplexity)
  22. */
  23. public function __construct(\Magento\Backend\App\ConfigInterface $config)
  24. {
  25. $pathParts = explode('/', $config->getValue('web/default/admin'));
  26. $this->_parts = [
  27. 'area' => isset($pathParts[0]) ? $pathParts[0] : '',
  28. 'module' => isset($pathParts[1]) ? $pathParts[1] : 'admin',
  29. 'controller' => isset($pathParts[2]) ? $pathParts[2] : 'index',
  30. 'action' => isset($pathParts[3]) ? $pathParts[3] : 'index',
  31. ];
  32. }
  33. /**
  34. * Retrieve default path part by code
  35. *
  36. * @param string $code
  37. * @return string
  38. */
  39. public function getPart($code)
  40. {
  41. return $this->_parts[$code] ?? null;
  42. }
  43. }