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

Commit

Permalink
Merge branch 'hotfix/29' into develop
Browse files Browse the repository at this point in the history
Forward port #29
  • Loading branch information
weierophinney committed Apr 26, 2018
2 parents 4aebba1 + 92f56ca commit 5223b57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ All notable changes to this project will be documented in this file, in reverse

- Nothing.

### Changed

- [#29](https://github.com/zendframework/zend-math/pull/29) modifies how caught exceptions are re-thrown; all such cases now provide
the original exception as the previous exception.

### Deprecated

- Nothing.
Expand Down
24 changes: 18 additions & 6 deletions src/Rand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@ public static function getBytes($length)
return random_bytes($length);
} catch (\TypeError $e) {
throw new Exception\InvalidArgumentException(
'Invalid parameter provided to getBytes(length)'
'Invalid parameter provided to getBytes(length)',
0,
$e
);
} catch (\Error $e) {
throw new Exception\DomainException(
'The length must be a positive number in getBytes(length)'
'The length must be a positive number in getBytes(length)',
0,
$e
);
} catch (\Exception $e) {
throw new Exception\RuntimeException(
'This PHP environment doesn\'t support secure random number generation. ' .
'Please consider upgrading to PHP 7'
'Please consider upgrading to PHP 7',
0,
$e
);
}
}
Expand Down Expand Up @@ -76,16 +82,22 @@ public static function getInteger($min, $max)
return random_int($min, $max);
} catch (\TypeError $e) {
throw new Exception\InvalidArgumentException(
'Invalid parameters provided to getInteger(min, max)'
'Invalid parameters provided to getInteger(min, max)',
0,
$e
);
} catch (\Error $e) {
throw new Exception\DomainException(
'The min parameter must be lower than max in getInteger(min, max)'
'The min parameter must be lower than max in getInteger(min, max)',
0,
$e
);
} catch (\Exception $e) {
throw new Exception\RuntimeException(
'This PHP environment doesn\'t support secure random number generation. ' .
'Please consider upgrading to PHP 7'
'Please consider upgrading to PHP 7',
0,
$e
);
}
}
Expand Down

0 comments on commit 5223b57

Please sign in to comment.