DocRootLocator.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. use Magento\Framework\Filesystem\Directory\ReadFactory;
  9. /**
  10. * This class calculates if document root is set to pub
  11. */
  12. class DocRootLocator
  13. {
  14. /**
  15. * @var RequestInterface
  16. */
  17. private $request;
  18. /**
  19. * @var ReadFactory
  20. */
  21. private $readFactory;
  22. /**
  23. * @param RequestInterface $request
  24. * @param ReadFactory $readFactory
  25. */
  26. public function __construct(RequestInterface $request, ReadFactory $readFactory)
  27. {
  28. $this->request = $request;
  29. $this->readFactory = $readFactory;
  30. }
  31. /**
  32. * Returns true if doc root is pub/ and not BP
  33. *
  34. * @return bool
  35. */
  36. public function isPub()
  37. {
  38. $rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
  39. $readDirectory = $this->readFactory->create(DirectoryList::ROOT);
  40. return (substr($rootBasePath, -strlen('/pub')) === '/pub') && !$readDirectory->isExist($rootBasePath . 'setup');
  41. }
  42. }