* Jordi Boggiano * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer\Repository\Vcs; use Composer\IO\IOInterface; use Composer\Util\ProcessExecutor; use Composer\Util\Perforce; /** * @author Matt Whittom */ class PerforceDriver extends VcsDriver { protected $depot; protected $branch; protected $perforce; protected $composerInfo; protected $composerInfoIdentifier; /** * {@inheritDoc} */ public function initialize() { $this->depot = $this->repoConfig['depot']; $this->branch = ''; if (isset($this->repoConfig['branch'])) { $this->branch = $this->repoConfig['branch']; } $this->initPerforce($this->repoConfig); $this->perforce->p4Login($this->io); $this->perforce->checkStream($this->depot); $this->perforce->writeP4ClientSpec(); $this->perforce->connectClient(); return true; } private function initPerforce($repoConfig) { if (isset($this->perforce)) { return; } $repoDir = $this->config->get('cache-vcs-dir') . '/' . $this->depot; $this->perforce = Perforce::createPerforce($repoConfig, $this->getUrl(), $repoDir, $this->process); } /** * {@inheritDoc} */ public function getComposerInformation($identifier) { if (isset($this->composerInfoIdentifier)) { if (strcmp($identifier, $this->composerInfoIdentifier) === 0) { return $this->composerInfo; } } $composer_info = $this->perforce->getComposerInformation($identifier); return $composer_info; } /** * {@inheritDoc} */ public function getRootIdentifier() { return $this->branch; } /** * {@inheritDoc} */ public function getBranches() { $branches = $this->perforce->getBranches(); return $branches; } /** * {@inheritDoc} */ public function getTags() { $tags = $this->perforce->getTags(); return $tags; } /** * {@inheritDoc} */ public function getDist($identifier) { return null; } /** * {@inheritDoc} */ public function getSource($identifier) { $source = array( 'type' => 'perforce', 'url' => $this->repoConfig['url'], 'reference' => $identifier, 'p4user' => $this->perforce->getUser() ); return $source; } /** * {@inheritDoc} */ public function getUrl() { return $this->url; } /** * {@inheritDoc} */ public function hasComposerFile($identifier) { $this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); $this->composerInfoIdentifier = $identifier; $result = false; if (isset($this->composerInfo)) { $result = count($this->composerInfo) > 0; } return $result; } /** * {@inheritDoc} */ public function getContents($url) { return false; } /** * {@inheritDoc} */ public static function supports(IOInterface $io, $url, $deep = false) { return Perforce::checkServerExists($url, new ProcessExecutor); } /** * {@inheritDoc} */ public function cleanup() { $this->perforce->cleanupClientSpec(); $this->perforce = null; } public function getDepot() { return $this->depot; } public function getBranch() { return $this->branch; } public function injectPerforce(Perforce $perforce) { $this->perforce = $perforce; } }