From 6d5b4d606c506cd1d5f8656691a87a5dde8260da Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 1 Apr 2012 18:52:53 +0200 Subject: [PATCH] Add warning in verbose mode if drivers can not be used because of missing openssl --- .../Repository/Vcs/GitBitbucketDriver.php | 15 +++++++++++++-- src/Composer/Repository/Vcs/GitDriver.php | 2 +- src/Composer/Repository/Vcs/GitHubDriver.php | 15 +++++++++++++-- src/Composer/Repository/Vcs/HgBitbucketDriver.php | 15 +++++++++++++-- src/Composer/Repository/Vcs/HgDriver.php | 2 +- src/Composer/Repository/Vcs/SvnDriver.php | 2 +- .../Repository/Vcs/VcsDriverInterface.php | 5 ++++- src/Composer/Repository/VcsRepository.php | 4 ++-- .../Test/Repository/Vcs/SvnDriverTest.php | 4 ++-- 9 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitBitbucketDriver.php b/src/Composer/Repository/Vcs/GitBitbucketDriver.php index 8021a2cb8..c0132cd10 100644 --- a/src/Composer/Repository/Vcs/GitBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/GitBitbucketDriver.php @@ -143,8 +143,19 @@ class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface /** * {@inheritDoc} */ - public static function supports($url, $deep = false) + public static function supports(IOInterface $io, $url, $deep = false) { - return preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)\.git$#', $url); + if (!preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)\.git$#', $url)) { + return false; + } + + if (!extension_loaded('openssl')) { + if ($io->isVerbose()) { + $io->write('Skipping Bitbucket git driver for '.$url.' because the OpenSSL PHP extension is missing.'); + } + return false; + } + + return true; } } diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index af6a11209..2b05f0b45 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -184,7 +184,7 @@ class GitDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports($url, $deep = false) + public static function supports(IOInterface $io, $url, $deep = false) { if (preg_match('#(^git://|\.git$|git@|//git\.)#i', $url)) { return true; diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index efe1a89a4..3a315018a 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -186,9 +186,20 @@ class GitHubDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports($url, $deep = false) + public static function supports(IOInterface $io, $url, $deep = false) { - return extension_loaded('openssl') && preg_match('#^(?:https?|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $url); + if (!preg_match('#^(?:https?|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $url)) { + return false; + } + + if (!extension_loaded('openssl')) { + if ($io->isVerbose()) { + $io->write('Skipping GitHub driver for '.$url.' because the OpenSSL PHP extension is missing.'); + } + return false; + } + + return true; } /** diff --git a/src/Composer/Repository/Vcs/HgBitbucketDriver.php b/src/Composer/Repository/Vcs/HgBitbucketDriver.php index 54dfd5d30..993ece82d 100644 --- a/src/Composer/Repository/Vcs/HgBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/HgBitbucketDriver.php @@ -143,8 +143,19 @@ class HgBitbucketDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports($url, $deep = false) + public static function supports(IOInterface $io, $url, $deep = false) { - return extension_loaded('openssl') && preg_match('#^https://bitbucket\.org/([^/]+)/([^/]+)/?$#', $url); + if (!preg_match('#^https://bitbucket\.org/([^/]+)/([^/]+)/?$#', $url)) { + return false; + } + + if (!extension_loaded('openssl')) { + if ($io->isVerbose()) { + $io->write('Skipping Bitbucket hg driver for '.$url.' because the OpenSSL PHP extension is missing.'); + } + return false; + } + + return true; } } diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index f7390fb47..833669cf9 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -162,7 +162,7 @@ class HgDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports($url, $deep = false) + public static function supports(IOInterface $io, $url, $deep = false) { if (preg_match('#(^(?:https?|ssh)://(?:[^@]@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i', $url)) { return true; diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index b18f362c3..6f13296ce 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -218,7 +218,7 @@ class SvnDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports($url, $deep = false) + public static function supports(IOInterface $io, $url, $deep = false) { $url = self::normalizeUrl($url); if (preg_match('#(^svn://|^svn\+ssh://|svn\.)#i', $url)) { diff --git a/src/Composer/Repository/Vcs/VcsDriverInterface.php b/src/Composer/Repository/Vcs/VcsDriverInterface.php index cff522209..472461ed3 100644 --- a/src/Composer/Repository/Vcs/VcsDriverInterface.php +++ b/src/Composer/Repository/Vcs/VcsDriverInterface.php @@ -12,6 +12,8 @@ namespace Composer\Repository\Vcs; +use Composer\IO\IOInterface; + /** * @author Jordi Boggiano */ @@ -82,9 +84,10 @@ interface VcsDriverInterface /** * Checks if this driver can handle a given url * + * @param IOInterface $io IO instance * @param string $url * @param Boolean $shallow unless true, only shallow checks (url matching typically) should be done * @return Boolean */ - static function supports($url, $deep = false); + static function supports(IOInterface $io, $url, $deep = false); } diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index fd8f4b8a4..ca117e8cb 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -59,7 +59,7 @@ class VcsRepository extends ArrayRepository } foreach ($this->drivers as $driver) { - if ($driver::supports($this->url)) { + if ($driver::supports($this->io, $this->url)) { $driver = new $driver($this->url, $this->io); $driver->initialize(); return $driver; @@ -67,7 +67,7 @@ class VcsRepository extends ArrayRepository } foreach ($this->drivers as $driver) { - if ($driver::supports($this->url, true)) { + if ($driver::supports($this->io, $this->url, true)) { $driver = new $driver($this->url, $this->io); $driver->initialize(); return $driver; diff --git a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php index 6dff2f113..5399c394e 100644 --- a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php @@ -68,9 +68,9 @@ class SvnDriverTest extends \PHPUnit_Framework_TestCase public function testSupport($url, $assertion) { if ($assertion === true) { - $this->assertTrue(SvnDriver::supports($url)); + $this->assertTrue(SvnDriver::supports($this->getMock('Composer\IO\IOInterface'), $url)); } else { - $this->assertFalse(SvnDriver::supports($url)); + $this->assertFalse(SvnDriver::supports($this->getMock('Composer\IO\IOInterface'), $url)); } } }