PathChecker.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\Util\Command;
  7. use Magento\Mtf\Util\Protocol\CurlInterface;
  8. use Magento\Mtf\Util\Protocol\CurlTransport;
  9. /**
  10. * PathChecker checks that path to file or directory exists.
  11. */
  12. class PathChecker
  13. {
  14. /**
  15. * Url to checkPath.php.
  16. */
  17. const URL = 'dev/tests/functional/utils/pathChecker.php';
  18. /**
  19. * Curl transport protocol.
  20. *
  21. * @var CurlTransport
  22. */
  23. private $transport;
  24. /**
  25. * @param CurlTransport $transport
  26. */
  27. public function __construct(CurlTransport $transport)
  28. {
  29. $this->transport = $transport;
  30. }
  31. /**
  32. * Check that $path exists.
  33. *
  34. * @param string $path
  35. * @return bool
  36. */
  37. public function pathExists($path)
  38. {
  39. $url = $_ENV['app_frontend_url'] . self::URL . '?path=' . urlencode($path);
  40. $curl = $this->transport;
  41. $curl->write($url, [], CurlInterface::GET);
  42. $result = $curl->read();
  43. $curl->close();
  44. return strpos($result, 'path exists: true') !== false;
  45. }
  46. }