GitBitbucketDriver.php 2.3 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\Config;
  13. use Composer\IO\IOInterface;
  14. /**
  15. * @author Per Bernhardt <plb@webfactory.de>
  16. */
  17. class GitBitbucketDriver extends BitbucketDriver
  18. {
  19. /**
  20. * {@inheritDoc}
  21. */
  22. public function getRootIdentifier()
  23. {
  24. if ($this->fallbackDriver) {
  25. return $this->fallbackDriver->getRootIdentifier();
  26. }
  27. if (null === $this->rootIdentifier) {
  28. if (! $this->getRepoData()) {
  29. return $this->fallbackDriver->getRootIdentifier();
  30. }
  31. if ($this->vcsType !== 'git') {
  32. throw new \RuntimeException(
  33. $this->url.' does not appear to be a git repository, use '.
  34. $this->cloneHttpsUrl.' if this is a mercurial bitbucket repository'
  35. );
  36. }
  37. $mainBranchData = $this->getMainBranchData();
  38. $this->rootIdentifier = !empty($mainBranchData['name']) ? $mainBranchData['name'] : 'master';
  39. }
  40. return $this->rootIdentifier;
  41. }
  42. /**
  43. * {@inheritDoc}
  44. */
  45. public static function supports(IOInterface $io, Config $config, $url, $deep = false)
  46. {
  47. if (!preg_match('#^https?://bitbucket\.org/([^/]+)/(.+?)\.git$#', $url)) {
  48. return false;
  49. }
  50. if (!extension_loaded('openssl')) {
  51. $io->writeError('Skipping Bitbucket git driver for '.$url.' because the OpenSSL PHP extension is missing.', true, IOInterface::VERBOSE);
  52. return false;
  53. }
  54. return true;
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. protected function setupFallbackDriver($url)
  60. {
  61. $this->fallbackDriver = new GitDriver(
  62. array('url' => $url),
  63. $this->io,
  64. $this->config,
  65. $this->process,
  66. $this->remoteFilesystem
  67. );
  68. $this->fallbackDriver->initialize();
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. protected function generateSshUrl()
  74. {
  75. return 'git@' . $this->originUrl . ':' . $this->owner.'/'.$this->repository.'.git';
  76. }
  77. }