mirror of
https://gh.wpcy.net/https://github.com/pixelabs-wp/whitelabel-plugins-update-server.git
synced 2026-04-19 05:26:01 +08:00
38 lines
1 KiB
PHP
38 lines
1 KiB
PHP
<?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);
|
|
}
|
|
}
|
|
}
|