RemoteFilesystemMock.php 987 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Mock;
  12. use Composer\Util\RemoteFilesystem;
  13. use Composer\Downloader\TransportException;
  14. /**
  15. * Remote filesystem mock
  16. */
  17. class RemoteFilesystemMock extends RemoteFilesystem
  18. {
  19. /**
  20. * @param array $contentMap associative array of locations and content
  21. */
  22. public function __construct(array $contentMap)
  23. {
  24. $this->contentMap = $contentMap;
  25. }
  26. public function getContents($originUrl, $fileUrl, $progress = true, $options = array())
  27. {
  28. if (!empty($this->contentMap[$fileUrl])) {
  29. return $this->contentMap[$fileUrl];
  30. }
  31. throw new TransportException('The "'.$fileUrl.'" file could not be downloaded (NOT FOUND)', 404);
  32. }
  33. }