Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Update deps (#17)
Browse files Browse the repository at this point in the history
- Change PHP constraint
- Update PHPUnit
- Delegate openssl check to Composer
- make `FileGetContents::getTlsStreamContextDefaults()` private

Regarding `FileGetContents::getTlsStreamContextDefaults()` the reason is it's more of an `init()` method in the first place and can easily be overridden in the constructor instead of overriding the method itself.
  • Loading branch information
theofidry authored May 28, 2017
1 parent f54fa5b commit a96b01d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
],

"require": {
"php": ">=5.3",
"php": "^5.3 || ^7.0",
"ext-openssl": "*",
"composer/ca-bundle": "^1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.1",
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0"
},

"autoload": {
Expand Down
32 changes: 15 additions & 17 deletions src/Humbug/FileGetContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
namespace Humbug;

use Composer\CaBundle\CaBundle;
use RuntimeException;

/**
* This is largely extracted from the Composer Installer where originally implemented.
*/
class FileGetContents
{
protected $options = array('http' => array());

protected static $lastResponseHeaders;

protected static $nextRequestHeaders;

protected $options = array('http' => array());

public function __construct()
{
$this->checkConfig();
$options = $this->getTlsStreamContextDefaults(null);
$this->options = array_replace_recursive($this->options, $options);
}
Expand Down Expand Up @@ -93,15 +93,6 @@ public static function setHttpHeaders($context)
return $context;
}

protected function checkConfig()
{
if (!extension_loaded('openssl')) {
throw new \RuntimeException(
'The openssl extension is not loaded but is required for secure HTTPS connections'
);
}
}

protected function getStreamContext($url)
{
$host = parse_url($url, PHP_URL_HOST);
Expand All @@ -113,6 +104,13 @@ protected function getStreamContext($url)
return $this->getMergedStreamContext($url);
}

/**
* @param string $cafile
*
* @return array
*
* @private since 1.1.0
*/
protected function getTlsStreamContextDefaults($cafile)
{
$ciphers = implode(':', array(
Expand Down Expand Up @@ -177,7 +175,7 @@ protected function getTlsStreamContextDefaults($cafile)
} elseif ($cafile) {
$options['ssl']['cafile'] = $cafile;
} else {
throw new \RuntimeException('A valid cafile could not be located locally.');
throw new RuntimeException('A valid cafile could not be located locally.');
}

if (version_compare(PHP_VERSION, '5.4.13') >= 0) {
Expand All @@ -188,7 +186,7 @@ protected function getTlsStreamContextDefaults($cafile)
}

/**
* function copied from Composer\Util\StreamContextFactory::getContext
* Function copied from Composer\Util\StreamContextFactory::getContext
*
* This function is part of Composer.
*
Expand All @@ -197,7 +195,7 @@ protected function getTlsStreamContextDefaults($cafile)
*
* @param string $url URL the context is to be used for
*
* @throws \\RuntimeException if https proxy required and OpenSSL uninstalled
* @throws \RuntimeException If https proxy required and OpenSSL uninstalled
*
* @return resource Default context
*/
Expand Down Expand Up @@ -227,7 +225,7 @@ protected function getMergedStreamContext($url)
$proxyURL = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $proxyURL);

if (0 === strpos($proxyURL, 'ssl:') && !extension_loaded('openssl')) {
throw new \RuntimeException('You must enable the openssl extension to use a proxy over https');
throw new RuntimeException('You must enable the openssl extension to use a proxy over https');
}

$options['http'] = array(
Expand Down Expand Up @@ -278,7 +276,7 @@ public static function getSystemCaRootBundlePath()
*/
protected static function validateCaFile($contents)
{
// assume the CA is valid if php is vunerable to
// assume the CA is valid if php is vulnerable to
// https://www.sektioneins.de/advisories/advisory-012013-php-openssl_x509_parse-memory-corruption-vulnerability.html
if (!CaBundle::isOpensslParseSafe()) {
return !empty($contents);
Expand Down
8 changes: 7 additions & 1 deletion tests/Humbug/Test/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@

namespace Humbug\Test;

use PHPUnit\Framework\TestCase;

if (!class_exists('\PHPUnit\Framework\TestCase', true)) {
class_alias('\PHPUnit_Framework_TestCase', 'TestCase');
}

/**
* @coversNothing
*/
class FunctionTest extends \PHPUnit_Framework_TestCase
class FunctionTest extends TestCase
{
private static $result;

Expand Down

0 comments on commit a96b01d

Please sign in to comment.