Skip to content

Commit

Permalink
Merge branch 'release/0.4.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
ta2edchimp committed Sep 21, 2015
2 parents 5e0bda7 + 2d32782 commit 1fd9e92
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 246 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Release 0.4.7

- 44f63fe Versionbump.
- acc18bc Corrected namespaced class imports.
- 8e450fd Do not suppress errors on `file_get_contents`, as we are even specifically change the php error settings to be able to catch possible errors.
- 1a5374c Cleared up namespace uses.
- 8959698 Auto-caching not implemented, therefore to reduce dead code, removed corresponding flags.
- fc15ce4 ... and a bugfix for previously undefined variables from #2c5fc8e
- 2c5fc8e Make use of existing information when receiving errors.
- 8d02af5 Deleted commented out code.
- 08b6b7d Changes due to modifications made to the Fetcher implementations.
- 20290e8 Fetcher implementations now inherit from `FetcherBase` class. Duplicate code removed.
- 01f3e7b Changed base implementation of `Fetcher` into `FetcherInterface` and a `FetcherBase` class, to store otherwise duplicate code of the concrete Fetcher implementations of `File` and `Curl`.
- 94910e8 Merge branch 'release/0.4.6' into develop

# Release 0.4.6

- c09d3fc DB Updated for `Galatea`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Advanced editable BattleReport platform for EVE Online.

- Current Version: `0.4`
- Current Version: `0.4.7`
- Download at [`Releases`](https://github.com/ta2edchimp/BattleReporter/releases)

## Setup
Expand Down
35 changes: 5 additions & 30 deletions classes/Fetcher/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Utils\Fetcher;

class Curl implements FetcherBase {
use Utils\Fetcher\FetcherBase;

class Curl extends FetcherBase {

public function fetch ($url = "", $parameters = array(), $options = array()) {

Expand Down Expand Up @@ -122,10 +124,10 @@ public function fetch ($url = "", $parameters = array(), $options = array()) {
curl_close($curl);

if ($httpCode >= 400)
throw new Exception("HTTP-Error #$httpCode with url \"$url\":\n$result", $httpCode);
throw new \Exception("HTTP-Error #$httpCode with url \"$url\":\n$result", $httpCode);

if ($errno)
throw new Exception("Error #$errno while fetching url \"$url\":\n$error", $errno);
throw new \Exception("Error #$errno while fetching url \"$url\":\n$error", $errno);

if ($caching === true && $cache !== null) {
if ($autoCaching === true && !empty($headers["Expires"])) {
Expand All @@ -140,33 +142,6 @@ public function fetch ($url = "", $parameters = array(), $options = array()) {

}

private static function transformParameters($parameters = array(), $parametersAsQuerystring = true) {

if (!is_array($parameters) || empty($parameters))
return "";

$queryps = array();
$keys = array_keys($parameters);

if ($parametersAsQuerystring === true) {
foreach ($keys as $key) {
$queryps[] = $key . "=" . $parameters[$key];
}
if (count($queryps) > 0)
return "?" . implode("&", $queryps);
} else {
foreach ($keys as $key) {
$queryps[] = $key;
$queryps[] = $parameters[$key];
}
if (count($queryps) > 0)
return "/" . implode("/", $queryps) . "/";
}

return "";

}

public static function curlHeaderToArray($headerText = "") {

$headers = array();
Expand Down
42 changes: 42 additions & 0 deletions classes/Fetcher/FetcherBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Utils\Fetcher;

use Utils\Fetcher\FetcherInterface;

class FetcherBase implements FetcherInterface {

public function fetch ($url = "", $parameters = array(), $options = array()) {

return "";

}

public static function transformParameters($parameters = array(), $parametersAsQuerystring = true) {

if (!is_array($parameters) || empty($parameters))
return "";

$queryps = array();
$keys = array_keys($parameters);

if ($parametersAsQuerystring === true) {
foreach ($keys as $key) {
$queryps[] = $key . "=" . $parameters[$key];
}
if (count($queryps) > 0)
return "?" . implode("&", $queryps);
} else {
foreach ($keys as $key) {
$queryps[] = $key;
$queryps[] = $parameters[$key];
}
if (count($queryps) > 0)
return "/" . implode("/", $queryps) . "/";
}

return "";

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Utils\Fetcher;

interface FetcherBase {
interface FetcherInterface {

public function fetch ($url = "", $parameters = array(), $options = array());

Expand Down
46 changes: 10 additions & 36 deletions classes/Fetcher/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Utils\Fetcher;

class File implements FetcherBase {
use Utils\Fetcher\FetcherBase;

class File extends FetcherBase {

public function fetch ($url = "", $parameters = array(), $options = array()) {

Expand All @@ -29,14 +31,10 @@ public function fetch ($url = "", $parameters = array(), $options = array()) {
$opts["http"]["timeout"] = $timeout;

$caching = false;
$autoCaching = false;
$cacheLifetime = 600;
if (isset($options["caching"])) {
if ($options["caching"] === true)
$caching = true;
elseif ($options["caching"] == "auto") {
if ($options["caching"] === true || $options["caching"] == "auto") {
$caching = true;
$autoCaching = true;
}
}
if (isset($options["cacheLifetime"])) {
Expand Down Expand Up @@ -95,19 +93,22 @@ public function fetch ($url = "", $parameters = array(), $options = array()) {
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
} else {
$result = @file_get_contents($url);
$result = file_get_contents($url);
}


$httpCode = 200;
$httpVersion = '';
$httpMsg = '';
if (isset($http_response_header[0])) {
list($httpVersion, $httpCode, $httpMsg) = explode(' ', $http_response_header[0], 3);
}

if (is_numeric($httpCode) && $httpCode >= 400)
throw new Exception("HTTP-Error #$httpCode with url \"$url\":\n$result", $httpCode);
throw new \Exception("HTTP ($httpVersion) Error #$httpCode with url \"$url\":\n$httpMsg\nResult:\n$result", $httpCode);

if ($result === false)
throw new Exception("Error while fetching url \"$url\":\n" . ($php_errormsg ? $php_errormsg : "HTTP Request Failed"), 666);
throw new \Exception("Error while fetching url \"$url\":\n" . ($php_errormsg ? $php_errormsg : "HTTP Request Failed"), 666);

// reset "track_errors" setting
ini_set('track_errors', $oldTrackErrors);
Expand All @@ -121,31 +122,4 @@ public function fetch ($url = "", $parameters = array(), $options = array()) {

}

private static function transformParameters($parameters = array(), $parametersAsQuerystring = true) {

if (!is_array($parameters) || empty($parameters))
return "";

$queryps = array();
$keys = array_keys($parameters);

if ($parametersAsQuerystring === true) {
foreach ($keys as $key) {
$queryps[] = $key . "=" . $parameters[$key];
}
if (count($queryps) > 0)
return "?" . implode("&", $queryps);
} else {
foreach ($keys as $key) {
$queryps[] = $key;
$queryps[] = $parameters[$key];
}
if (count($queryps) > 0)
return "/" . implode("/", $queryps) . "/";
}

return "";

}

}
Loading

0 comments on commit 1fd9e92

Please sign in to comment.