Browse Source

Add warning in verbose mode if drivers can not be used because of missing openssl

Jordi Boggiano 13 years ago
parent
commit
6d5b4d606c

+ 13 - 2
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;
     }
 }

+ 1 - 1
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;

+ 13 - 2
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;
     }
 
     /**

+ 13 - 2
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;
     }
 }

+ 1 - 1
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;

+ 1 - 1
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)) {

+ 4 - 1
src/Composer/Repository/Vcs/VcsDriverInterface.php

@@ -12,6 +12,8 @@
 
 namespace Composer\Repository\Vcs;
 
+use Composer\IO\IOInterface;
+
 /**
  * @author Jordi Boggiano <j.boggiano@seld.be>
  */
@@ -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);
 }

+ 2 - 2
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;

+ 2 - 2
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));
         }
     }
 }