2012-01-10 14:44:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Repository\Vcs;
|
|
|
|
|
2012-03-08 20:59:02 +00:00
|
|
|
use Composer\Downloader\TransportException;
|
2012-04-24 14:56:03 +00:00
|
|
|
use Composer\Config;
|
2012-01-16 13:14:15 +00:00
|
|
|
use Composer\IO\IOInterface;
|
2012-01-18 07:56:35 +00:00
|
|
|
use Composer\Util\ProcessExecutor;
|
2012-02-15 12:11:29 +00:00
|
|
|
use Composer\Util\RemoteFilesystem;
|
2012-01-16 13:14:15 +00:00
|
|
|
|
2012-01-10 14:44:13 +00:00
|
|
|
/**
|
2012-01-17 13:53:50 +00:00
|
|
|
* A driver implementation for driver with authorization interaction.
|
2012-01-10 14:44:13 +00:00
|
|
|
*
|
|
|
|
* @author François Pluchino <francois.pluchino@opendisplay.com>
|
|
|
|
*/
|
2012-03-08 20:59:02 +00:00
|
|
|
abstract class VcsDriver implements VcsDriverInterface
|
2012-01-10 14:44:13 +00:00
|
|
|
{
|
|
|
|
protected $url;
|
2012-01-16 13:14:15 +00:00
|
|
|
protected $io;
|
2012-04-24 14:56:03 +00:00
|
|
|
protected $config;
|
2012-01-18 07:56:35 +00:00
|
|
|
protected $process;
|
2012-03-15 01:44:27 +00:00
|
|
|
protected $remoteFilesystem;
|
2012-01-10 14:44:13 +00:00
|
|
|
|
|
|
|
/**
|
2012-01-11 12:55:05 +00:00
|
|
|
* Constructor.
|
2012-01-10 14:44:13 +00:00
|
|
|
*
|
2012-01-16 13:14:15 +00:00
|
|
|
* @param string $url The URL
|
|
|
|
* @param IOInterface $io The IO instance
|
2012-04-24 14:56:03 +00:00
|
|
|
* @param Config $config The composer configuration
|
2012-01-18 07:56:35 +00:00
|
|
|
* @param ProcessExecutor $process Process instance, injectable for mocking
|
2012-03-15 01:44:27 +00:00
|
|
|
* @param callable $remoteFilesystem Remote Filesystem, injectable for mocking
|
2012-01-10 14:44:13 +00:00
|
|
|
*/
|
2012-04-24 14:58:29 +00:00
|
|
|
final public function __construct($url, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null)
|
2012-01-10 14:44:13 +00:00
|
|
|
{
|
|
|
|
$this->url = $url;
|
2012-01-16 13:14:15 +00:00
|
|
|
$this->io = $io;
|
2012-04-24 14:56:03 +00:00
|
|
|
$this->config = $config;
|
2012-01-18 07:56:35 +00:00
|
|
|
$this->process = $process ?: new ProcessExecutor;
|
2012-03-15 01:44:27 +00:00
|
|
|
$this->remoteFilesystem = $remoteFilesystem ?: new RemoteFilesystem($io);
|
2012-01-10 14:44:13 +00:00
|
|
|
}
|
|
|
|
|
2012-03-08 20:59:02 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function hasComposerFile($identifier)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return (Boolean) $this->getComposerInformation($identifier);
|
|
|
|
} catch (TransportException $e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-10 14:44:13 +00:00
|
|
|
/**
|
2012-01-17 22:07:33 +00:00
|
|
|
* Get the https or http protocol depending on SSL support.
|
|
|
|
*
|
|
|
|
* Call this only if you know that the server supports both.
|
2012-01-10 14:44:13 +00:00
|
|
|
*
|
|
|
|
* @return string The correct type of protocol
|
|
|
|
*/
|
2012-01-11 00:11:56 +00:00
|
|
|
protected function getScheme()
|
2012-01-10 14:44:13 +00:00
|
|
|
{
|
|
|
|
if (extension_loaded('openssl')) {
|
|
|
|
return 'https';
|
|
|
|
}
|
|
|
|
return 'http';
|
|
|
|
}
|
2012-01-16 13:14:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the remote content.
|
|
|
|
*
|
|
|
|
* @param string $url The URL of content
|
|
|
|
*
|
|
|
|
* @return mixed The result
|
|
|
|
*/
|
|
|
|
protected function getContents($url)
|
|
|
|
{
|
2012-03-15 01:44:27 +00:00
|
|
|
return $this->remoteFilesystem->getContents($this->url, $url, false);
|
2012-01-16 13:14:15 +00:00
|
|
|
}
|
2012-02-19 15:38:07 +00:00
|
|
|
|
|
|
|
protected static function isLocalUrl($url)
|
|
|
|
{
|
|
|
|
return (Boolean) preg_match('{^(file://|/|[a-z]:[\\\\/])}i', $url);
|
|
|
|
}
|
2012-01-10 14:44:13 +00:00
|
|
|
}
|