class VcsDriver
A driver implementation for driver with authentication interaction.
@author François Pluchino <francois.pluchino@opendisplay.com>
Hierarchy
- class \Composer\Repository\Vcs\VcsDriver implements \Composer\Repository\Vcs\VcsDriverInterface
Expanded class hierarchy of VcsDriver
File
-
vendor/
composer/ composer/ src/ Composer/ Repository/ Vcs/ VcsDriver.php, line 31
Namespace
Composer\Repository\VcsView source
abstract class VcsDriver implements VcsDriverInterface {
/** @var string */
protected $url;
/** @var string */
protected $originUrl;
/** @var array<string, mixed> */
protected $repoConfig;
/** @var IOInterface */
protected $io;
/** @var Config */
protected $config;
/** @var ProcessExecutor */
protected $process;
/** @var HttpDownloader */
protected $httpDownloader;
/** @var array<int|string, mixed> */
protected $infoCache = [];
/** @var ?Cache */
protected $cache;
/**
* Constructor.
*
* @param array{url: string}&array<string, mixed> $repoConfig The repository configuration
* @param IOInterface $io The IO instance
* @param Config $config The composer configuration
* @param HttpDownloader $httpDownloader Remote Filesystem, injectable for mocking
* @param ProcessExecutor $process Process instance, injectable for mocking
*/
public final function __construct(array $repoConfig, IOInterface $io, Config $config, HttpDownloader $httpDownloader, ProcessExecutor $process) {
if (Filesystem::isLocalPath($repoConfig['url'])) {
$repoConfig['url'] = Filesystem::getPlatformPath($repoConfig['url']);
}
$this->url = $repoConfig['url'];
$this->originUrl = $repoConfig['url'];
$this->repoConfig = $repoConfig;
$this->io = $io;
$this->config = $config;
$this->httpDownloader = $httpDownloader;
$this->process = $process;
}
/**
* Returns whether or not the given $identifier should be cached or not.
*/
protected function shouldCache(string $identifier) : bool {
return $this->cache && Preg::isMatch('{^[a-f0-9]{40}$}iD', $identifier);
}
/**
* @inheritDoc
*/
public function getComposerInformation(string $identifier) : ?array {
if (!isset($this->infoCache[$identifier])) {
if ($this->shouldCache($identifier) && ($res = $this->cache
->read($identifier))) {
return $this->infoCache[$identifier] = JsonFile::parseJson($res);
}
$composer = $this->getBaseComposerInformation($identifier);
if ($this->shouldCache($identifier)) {
$this->cache
->write($identifier, JsonFile::encode($composer, 0));
}
$this->infoCache[$identifier] = $composer;
}
return $this->infoCache[$identifier];
}
/**
* @return array<mixed>|null
*/
protected function getBaseComposerInformation(string $identifier) : ?array {
$composerFileContent = $this->getFileContent('composer.json', $identifier);
if (!$composerFileContent) {
return null;
}
$composer = JsonFile::parseJson($composerFileContent, $identifier . ':composer.json');
if ([] === $composer || !is_array($composer)) {
return null;
}
if (empty($composer['time']) && null !== ($changeDate = $this->getChangeDate($identifier))) {
$composer['time'] = $changeDate->format(DATE_RFC3339);
}
return $composer;
}
/**
* @inheritDoc
*/
public function hasComposerFile(string $identifier) : bool {
try {
return null !== $this->getComposerInformation($identifier);
} catch (TransportException $e) {
}
return false;
}
/**
* Get the https or http protocol depending on SSL support.
*
* Call this only if you know that the server supports both.
*
* @return string The correct type of protocol
*/
protected function getScheme() : string {
if (extension_loaded('openssl')) {
return 'https';
}
return 'http';
}
/**
* Get the remote content.
*
* @param string $url The URL of content
*
* @throws TransportException
*/
protected function getContents(string $url) : Response {
$options = $this->repoConfig['options'] ?? [];
return $this->httpDownloader
->get($url, $options);
}
/**
* @inheritDoc
*/
public function cleanup() : void {
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
VcsDriver::$cache | protected | property | @var ?Cache | ||
VcsDriver::$config | protected | property | @var Config | ||
VcsDriver::$httpDownloader | protected | property | @var HttpDownloader | ||
VcsDriver::$infoCache | protected | property | @var array<int|string, mixed> | ||
VcsDriver::$io | protected | property | @var IOInterface | ||
VcsDriver::$originUrl | protected | property | @var string | ||
VcsDriver::$process | protected | property | @var ProcessExecutor | ||
VcsDriver::$repoConfig | protected | property | @var array<string, mixed> | ||
VcsDriver::$url | protected | property | @var string | ||
VcsDriver::cleanup | public | function | @inheritDoc | Overrides VcsDriverInterface::cleanup | 1 |
VcsDriver::getBaseComposerInformation | protected | function | |||
VcsDriver::getComposerInformation | public | function | @inheritDoc | Overrides VcsDriverInterface::getComposerInformation | 4 |
VcsDriver::getContents | protected | function | Get the remote content. | 3 | |
VcsDriver::getScheme | protected | function | Get the https or http protocol depending on SSL support. | ||
VcsDriver::hasComposerFile | public | function | @inheritDoc | Overrides VcsDriverInterface::hasComposerFile | 1 |
VcsDriver::shouldCache | protected | function | Returns whether or not the given $identifier should be cached or not. | 1 | |
VcsDriver::__construct | final public | function | Constructor. | ||
VcsDriverInterface::getBranches | public | function | Return list of branches in the repository | 8 | |
VcsDriverInterface::getChangeDate | public | function | Get the changedate for $identifier. | 8 | |
VcsDriverInterface::getDist | public | function | 8 | ||
VcsDriverInterface::getFileContent | public | function | Return the content of $file or null if the file does not exist. | 8 | |
VcsDriverInterface::getRootIdentifier | public | function | Return the root identifier (trunk, master, default/tip ..) | 8 | |
VcsDriverInterface::getSource | public | function | 8 | ||
VcsDriverInterface::getTags | public | function | Return list of tags in the repository | 8 | |
VcsDriverInterface::getUrl | public | function | Return the URL of the repository | 8 | |
VcsDriverInterface::initialize | public | function | Initializes the driver (git clone, svn checkout, fetch info etc) | 8 | |
VcsDriverInterface::supports | public static | function | Checks if this driver can handle a given url | 8 |