Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
namespace Aws\Crypto\Polyfill;
3
 
4
use Aws\Exception\CryptoPolyfillException;
5
 
6
/**
7
 * Trait NeedsTrait
8
 * @package Aws\Crypto\Polyfill
9
 */
10
trait NeedsTrait
11
{
12
    /**
13
     * Preconditions, postconditions, and loop invariants are very
14
     * useful for safe programing.  They also document the specifications.
15
     * This function is to help simplify the semantic burden of parsing
16
     * these constructions.
17
     *
18
     * Instead of constructions like
19
     *     if (!(GOOD CONDITION)) {
20
     *         throw new \Exception('condition not true');
21
     *     }
22
     *
23
     * you can write:
24
     *     needs(GOOD CONDITION, 'condition not true');
25
     * @param $condition
26
     * @param $errorMessage
27
     * @param null $exceptionClass
28
     */
29
    public static function needs($condition, $errorMessage, $exceptionClass = null)
30
    {
31
        if (!$condition) {
32
            if (!$exceptionClass) {
33
                $exceptionClass = CryptoPolyfillException::class;
34
            }
35
            throw new $exceptionClass($errorMessage);
36
        }
37
    }
38
}