DocumentRoot.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Model\Config\Reader\Source\Deployed;
  7. use Magento\Framework\Config\ConfigOptionsListConstants;
  8. use Magento\Framework\App\Filesystem\DirectoryList;
  9. use Magento\Framework\App\DeploymentConfig;
  10. /**
  11. * Class DocumentRoot
  12. * @package Magento\Config\Model\Config\Reader\Source\Deployed
  13. * @api
  14. * @since 101.0.0
  15. */
  16. class DocumentRoot
  17. {
  18. /**
  19. * @var DeploymentConfig
  20. */
  21. private $config;
  22. /**
  23. * DocumentRoot constructor.
  24. * @param DeploymentConfig $config
  25. */
  26. public function __construct(DeploymentConfig $config)
  27. {
  28. $this->config = $config;
  29. }
  30. /**
  31. * A shortcut to load the document root path from the DirectoryList based on the
  32. * deployment configuration.
  33. *
  34. * @return string
  35. * @since 101.0.0
  36. */
  37. public function getPath()
  38. {
  39. return $this->isPub() ? DirectoryList::PUB : DirectoryList::ROOT;
  40. }
  41. /**
  42. * Returns whether the deployment configuration specifies that the document root is
  43. * in the pub/ folder. This affects ares such as sitemaps and robots.txt (and will
  44. * likely be extended to control other areas).
  45. *
  46. * @return bool
  47. * @since 101.0.0
  48. */
  49. public function isPub()
  50. {
  51. return (bool)$this->config->get(ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB);
  52. }
  53. }