Skip to content

Commit

Permalink
- Updated DefaultSettings to include curl proxy settings
Browse files Browse the repository at this point in the history
- Use DefaultSettings in HttpRequest helper
- Update .gitignore for .idea folder and fix composer.json intendation
  • Loading branch information
tholu committed Mar 17, 2016
1 parent fb5787d commit 330a357
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ vendor/
composer.lock
.project
.settings
.DS_Store
.DS_Store
.idea
9 changes: 9 additions & 0 deletions SEOstats/Config/DefaultSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,13 @@ interface DefaultSettings
// fr – France
// it – Italy
const SISTRIX_DB = 'de';

// Enter proxy to use with curl
// leave empty to disable proxy
const CURLOPT_PROXY = '';

// Enter proxy username and password (seperated by :) if necessary
// leave empty tp to disable
const CURLOPT_PROXYUSERPWD = '';

}
22 changes: 21 additions & 1 deletion SEOstats/Helper/HttpRequest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php
namespace SEOstats\Helper;

use SEOstats\Config\DefaultSettings;

/**
* HTTP Request Helper Class
*
* @package SEOstats
* @author Stephan Schmitz <[email protected]>
* @copyright Copyright (c) 2010 - present Stephan Schmitz
* @license http://eyecatchup.mit-license.org/ MIT License
* @updated 2013/05/12
* @updated 2016/03/17
*/

class HttpRequest
Expand Down Expand Up @@ -36,6 +38,12 @@ public static function sendRequest($url, $postData = false, $postJson = false)
CURLOPT_MAXREDIRS => 2,
CURLOPT_SSL_VERIFYPEER => 0,
));
if(!empty(DefaultSettings::CURLOPT_PROXY)) {
curl_setopt($ch, CURLOPT_PROXY, DefaultSettings::CURLOPT_PROXY);
}
if(!empty(DefaultSettings::CURLOPT_PROXYUSERPWD)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, DefaultSettings::CURLOPT_PROXYUSERPWD);
}

if (false !== $postData) {
if (false !== $postJson) {
Expand Down Expand Up @@ -79,6 +87,12 @@ public static function getHttpCode($url)
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_NOBODY => 1,
));
if(!empty(DefaultSettings::CURLOPT_PROXY)) {
curl_setopt($ch, CURLOPT_PROXY, DefaultSettings::CURLOPT_PROXY);
}
if(!empty(DefaultSettings::CURLOPT_PROXYUSERPWD)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, DefaultSettings::CURLOPT_PROXYUSERPWD);
}

curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
Expand All @@ -104,6 +118,12 @@ public function getFile($url, $file)
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_FILE => $fp,
));
if(!empty(DefaultSettings::CURLOPT_PROXY)) {
curl_setopt($ch, CURLOPT_PROXY, DefaultSettings::CURLOPT_PROXY);
}
if(!empty(DefaultSettings::CURLOPT_PROXYUSERPWD)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, DefaultSettings::CURLOPT_PROXYUSERPWD);
}

curl_exec($ch);
curl_close($ch);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"ext-json" : "*"
},
"require-dev" : {
"squizlabs/php_codesniffer" : "~1",
"squizlabs/php_codesniffer" : "~1",
"composer/composer": "1.0.*@dev",
"phpunit/phpunit" : ">=3.7,<4",
"scrutinizer/ocular" : "~1"
"scrutinizer/ocular" : "~1"
},
"autoload" : {
"psr-0" : {
Expand Down

0 comments on commit 330a357

Please sign in to comment.