PerforceDriver.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. * Contributor: matt-whittom
  9. * Date: 7/17/13
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. namespace Composer\Repository\Vcs;
  15. use Composer\IO\IOInterface;
  16. use Composer\Util\ProcessExecutor;
  17. use Composer\Util\Filesystem;
  18. use Composer\Util\Perforce;
  19. /**
  20. * @author matt-whittom <>
  21. */
  22. class PerforceDriver extends VcsDriver {
  23. protected $depot;
  24. protected $branch;
  25. protected $perforce;
  26. /**
  27. * {@inheritDoc}
  28. */
  29. public function initialize() {
  30. $this->depot = $this->repoConfig['depot'];
  31. $this->branch = "";
  32. if (isset($this->repoConfig['branch'])) {
  33. $this->branch = $this->repoConfig['branch'];
  34. }
  35. $repoDir = $this->config->get('cache-vcs-dir') . "/$this->depot";
  36. if (!isset($this->perforce)) {
  37. $this->perforce = new Perforce($this->depot, $this->branch, $this->getUrl(), $repoDir, $this->process);
  38. }
  39. $this->perforce->p4Login($this->io);
  40. $this->perforce->checkStream($this->depot);
  41. $this->perforce->writeP4ClientSpec();
  42. $this->perforce->connectClient();
  43. return TRUE;
  44. }
  45. public function injectPerforce(Perforce $perforce) {
  46. $this->perforce = $perforce;
  47. }
  48. /**
  49. * {@inheritDoc}
  50. */
  51. public function getComposerInformation($identifier) {
  52. $composer_info = $this->perforce->getComposerInformation($identifier);
  53. return $composer_info;
  54. }
  55. /**
  56. * {@inheritDoc}
  57. */
  58. public function getRootIdentifier() {
  59. return $this->branch;
  60. }
  61. /**
  62. * {@inheritDoc}
  63. */
  64. public function getBranches() {
  65. $branches = $this->perforce->getBranches();
  66. return $branches;
  67. }
  68. /**
  69. * {@inheritDoc}
  70. */
  71. public function getTags() {
  72. $tags = $this->perforce->getTags();
  73. return $tags;
  74. }
  75. /**
  76. * {@inheritDoc}
  77. */
  78. public function getDist($identifier) {
  79. return NULL;
  80. }
  81. /**
  82. * {@inheritDoc}
  83. */
  84. public function getSource($identifier) {
  85. $source = array(
  86. 'type' => 'perforce',
  87. 'url' => $this->repoConfig['url'],
  88. 'reference' => $identifier
  89. );
  90. return $source;
  91. }
  92. /**
  93. * {@inheritDoc}
  94. */
  95. public function getUrl() {
  96. return $this->url;
  97. }
  98. /**
  99. * {@inheritDoc}
  100. */
  101. public function hasComposerFile($identifier) {
  102. $composer_info = $this->perforce->getComposerInformation("//$this->depot/$identifier");
  103. $result = strlen(trim($composer_info)) > 0;
  104. return $result;
  105. }
  106. /**
  107. * {@inheritDoc}
  108. */
  109. public function getContents($url) {
  110. return FALSE;
  111. }
  112. /**
  113. * {@inheritDoc}
  114. */
  115. public static function supports(IOInterface $io, $url, $deep = FALSE) {
  116. return Perforce::checkServerExists($url, new ProcessExecutor);
  117. }
  118. }