1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 05:11:42 +01:00

Fix exception breakage across 5.x/7 environments

This commit is contained in:
Daniel Lowrey 2015-06-11 15:22:14 -04:00
parent 7ce6734976
commit 8a8930c8fd

View File

@ -8,7 +8,18 @@ namespace Amp;
class Failure implements Promise {
private $error;
public function __construct(\Exception $error) {
/**
* The error parameter used to fail a promisor must always be an exception
* instance. However, we cannot typehint this parameter in environments
* where PHP5.x compatibility is required because PHP7 BaseException
* instances will break the typehint.
*/
public function __construct($error) {
if (!($error instanceof \Exception || $error instanceof \BaseException)) {
throw new \InvalidArgumentException(
"Only exceptions may be used to fail a promise"
);
}
$this->error = $error;
}