diff options
Diffstat (limited to 'vendor/aws/aws-sdk-php/src/Crypto/Polyfill/NeedsTrait.php')
-rw-r--r-- | vendor/aws/aws-sdk-php/src/Crypto/Polyfill/NeedsTrait.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/aws/aws-sdk-php/src/Crypto/Polyfill/NeedsTrait.php b/vendor/aws/aws-sdk-php/src/Crypto/Polyfill/NeedsTrait.php new file mode 100644 index 0000000..5ba4d64 --- /dev/null +++ b/vendor/aws/aws-sdk-php/src/Crypto/Polyfill/NeedsTrait.php @@ -0,0 +1,38 @@ +<?php +namespace Aws\Crypto\Polyfill; + +use Aws\Exception\CryptoPolyfillException; + +/** + * Trait NeedsTrait + * @package Aws\Crypto\Polyfill + */ +trait NeedsTrait +{ + /** + * Preconditions, postconditions, and loop invariants are very + * useful for safe programing. They also document the specifications. + * This function is to help simplify the semantic burden of parsing + * these constructions. + * + * Instead of constructions like + * if (!(GOOD CONDITION)) { + * throw new \Exception('condition not true'); + * } + * + * you can write: + * needs(GOOD CONDITION, 'condition not true'); + * @param $condition + * @param $errorMessage + * @param null $exceptionClass + */ + public static function needs($condition, $errorMessage, $exceptionClass = null) + { + if (!$condition) { + if (!$exceptionClass) { + $exceptionClass = CryptoPolyfillException::class; + } + throw new $exceptionClass($errorMessage); + } + } +} |