Skip to content

Commit

Permalink
Improve detection of unsupported Exit Metadata Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed Dec 4, 2019
1 parent ad67cd8 commit 07f0a6e
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/Image/Metadata/ExifMetadataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,40 @@ class ExifMetadataReader extends AbstractMetadataReader
*/
public function __construct()
{
if (!self::isSupported()) {
throw new NotSupportedException('PHP exif extension is required to use the ExifMetadataReader');
$whyNot = static::getUnsupportedReason();
if ($whyNot !== '') {
throw new NotSupportedException($whyNot);
}
}

/**
* Get the reason why this metadata reader is not supported.
*
* @return string empty string if the reader is available
*/
public static function getUnsupportedReason()
{
if (!function_exists('exif_read_data')) {
return 'The PHP EXIF extension is required to use the ExifMetadataReader';
}
if (!in_array('data', stream_get_wrappers(), true)) {
return 'The data:// stream wrapper must be enabled';
}
if (in_array(ini_get('allow_url_fopen'), array('', '0', 0), true)) {
return 'The allow_url_fopen php.ini configuration key must be must be enabled';
}

return '';
}

/**
* Is this metadata reader supported?
*
* @return bool
*/
public static function isSupported()
{
return function_exists('exif_read_data');
return static::getUnsupportedReason() === '';
}

/**
Expand Down

0 comments on commit 07f0a6e

Please sign in to comment.