Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

111 lines
2.7KB

  1. <?php
  2. /*
  3. * This file is part of the Fxp Composer Asset Plugin package.
  4. *
  5. * (c) François Pluchino <francois.pluchino@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Fxp\Composer\AssetPlugin\Repository\Vcs;
  11. use Composer\Cache;
  12. use Composer\Repository\Vcs\PerforceDriver as BasePerforceDriver;
  13. use Fxp\Composer\AssetPlugin\Util\Perforce;
  14. /**
  15. * Perforce vcs driver.
  16. *
  17. * @author François Pluchino <francois.pluchino@gmail.com>
  18. */
  19. class PerforceDriver extends BasePerforceDriver
  20. {
  21. /**
  22. * @var Perforce
  23. */
  24. protected $perforce;
  25. /**
  26. * @var array
  27. */
  28. protected $infoCache = array();
  29. /**
  30. * @var Cache
  31. */
  32. protected $cache;
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function initialize()
  37. {
  38. $this->depot = $this->repoConfig['depot'];
  39. $this->branch = '';
  40. if (!empty($this->repoConfig['branch'])) {
  41. $this->branch = $this->repoConfig['branch'];
  42. }
  43. $this->initAssetPerforce($this->repoConfig);
  44. $this->perforce->p4Login();
  45. $this->perforce->checkStream();
  46. $this->perforce->writeP4ClientSpec();
  47. $this->perforce->connectClient();
  48. $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.$this->originUrl.'/'.$this->depot);
  49. return true;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getComposerInformation($identifier)
  55. {
  56. $this->infoCache[$identifier] = Util::readCache($this->infoCache, $this->cache, $this->repoConfig['asset-type'], $identifier, true);
  57. if (!isset($this->infoCache[$identifier])) {
  58. $composer = $this->getComposerContent($identifier);
  59. Util::writeCache($this->cache, $this->repoConfig['asset-type'], $identifier, $composer, true);
  60. $this->infoCache[$identifier] = $composer;
  61. }
  62. return $this->infoCache[$identifier];
  63. }
  64. /**
  65. * Get composer content.
  66. *
  67. * @param string $identifier
  68. *
  69. * @return array
  70. */
  71. protected function getComposerContent($identifier)
  72. {
  73. $composer = $this->perforce->getComposerInformation($identifier);
  74. if (empty($composer) || !is_array($composer)) {
  75. $composer = array('_nonexistent_package' => true);
  76. }
  77. return $composer;
  78. }
  79. /**
  80. * @param array $repoConfig
  81. */
  82. private function initAssetPerforce($repoConfig)
  83. {
  84. if (!empty($this->perforce)) {
  85. return;
  86. }
  87. $repoDir = $this->config->get('cache-vcs-dir').'/'.$this->depot;
  88. $this->perforce = Perforce::create($repoConfig, $this->getUrl(), $repoDir, $this->process, $this->io);
  89. }
  90. }