Skip to content

Commit

Permalink
Merge pull request #37 from mike42/feature/36-hhvm
Browse files Browse the repository at this point in the history
Add HHVM to CI
  • Loading branch information
mike42 authored Feb 24, 2019
2 parents b1a1377 + 542211d commit 0ea8f50
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ php:
- 7.1
- 7.2
- 7.3
- hhvm-3.21
- hhvm-3.27
- nightly
- hhvm-nightly

Expand All @@ -21,6 +23,7 @@ install:
- composer install

before_script:
- bash -c 'if [[ $TRAVIS_PHP_VERSION == hhvm* ]]; then echo "hhvm.php7.all = 1" | sudo tee -a /etc/hhvm/php.ini; fi'
- mkdir -p build/logs/

script:
Expand Down
30 changes: 27 additions & 3 deletions src/Mike42/GfxPhp/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ class Image
public static function fromFile(string $filename) : RasterImage
{
// Attempt to catch the cause of any errors
error_clear_last();
self::clearLastError();
$blob = @file_get_contents($filename);
if ($blob === false) {
$e = error_get_last();
$error = (isset($e) && isset($e['message']) && $e['message'] != "") ? $e['message'] : "Check that the file exists and can be read.";
$error = self::getLastErrorOrDefault("Check that the file exists and can be read.");
throw new \Exception("Could not retrieve image data from '$filename'. $error");
}
return self::fromBlob($blob, $filename);
Expand All @@ -47,4 +46,29 @@ public static function create(int $width, int $height, int $impl = self::IMAGE_B
{
return BlackAndWhiteRasterImage::create($width, $height);
}

/**
* Call error_clear_last() if it exists. This is dependent on which PHP runtime is used.
*/
private static function clearLastError()
{
if (function_exists('error_clear_last')) {
error_clear_last();
}
}

/**
* Retrieve the message from error_get_last() if possible. This is very useful for debugging, but it will not
* always exist or return anything useful.
*/
private static function getLastErrorOrDefault(string $default)
{
if (function_exists('error_clear_last')) {
$e = error_get_last();
if (isset($e) && isset($e['message']) && $e['message'] != "") {
return $e['message'];
}
}
return $default;
}
}

0 comments on commit 0ea8f50

Please sign in to comment.