VcsDriver.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\Repository\Vcs;
  12. use Composer\Downloader\TransportException;
  13. use Composer\IO\IOInterface;
  14. use Composer\Util\ProcessExecutor;
  15. use Composer\Util\RemoteFilesystem;
  16. /**
  17. * A driver implementation for driver with authorization interaction.
  18. *
  19. * @author François Pluchino <francois.pluchino@opendisplay.com>
  20. */
  21. abstract class VcsDriver implements VcsDriverInterface
  22. {
  23. protected $url;
  24. protected $io;
  25. protected $process;
  26. /**
  27. * Constructor.
  28. *
  29. * @param string $url The URL
  30. * @param IOInterface $io The IO instance
  31. * @param ProcessExecutor $process Process instance, injectable for mocking
  32. */
  33. public function __construct($url, IOInterface $io, ProcessExecutor $process = null)
  34. {
  35. $this->url = $url;
  36. $this->io = $io;
  37. $this->process = $process ?: new ProcessExecutor;
  38. }
  39. /**
  40. * {@inheritDoc}
  41. */
  42. public function hasComposerFile($identifier)
  43. {
  44. try {
  45. return (Boolean) $this->getComposerInformation($identifier);
  46. } catch (TransportException $e) {
  47. }
  48. return false;
  49. }
  50. /**
  51. * Get the https or http protocol depending on SSL support.
  52. *
  53. * Call this only if you know that the server supports both.
  54. *
  55. * @return string The correct type of protocol
  56. */
  57. protected function getScheme()
  58. {
  59. if (extension_loaded('openssl')) {
  60. return 'https';
  61. }
  62. return 'http';
  63. }
  64. /**
  65. * Get the remote content.
  66. *
  67. * @param string $url The URL of content
  68. *
  69. * @return mixed The result
  70. */
  71. protected function getContents($url)
  72. {
  73. $rfs = new RemoteFilesystem($this->io);
  74. return $rfs->getContents($this->url, $url, false);
  75. }
  76. protected static function isLocalUrl($url)
  77. {
  78. return (Boolean) preg_match('{^(file://|/|[a-z]:[\\\\/])}i', $url);
  79. }
  80. }