Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 */
9
trait NeedsTrait
10
{
11
    /**
12
     * Preconditions, postconditions, and loop invariants are very
13
     * useful for safe programing.  They also document the specifications.
14
     * This function is to help simplify the semantic burden of parsing
15
     * these constructions.
16
     *
17
     * Instead of constructions like
18
     *     if (!(GOOD CONDITION)) {
19
     *         throw new \Exception('condition not true');
20
     *     }
21
     *
22
     * you can write:
23
     *     needs(GOOD CONDITION, 'condition not true');
24
     * @param $condition
25
     * @param $errorMessage
26
     * @param null $exceptionClass
27
     */
28
    public static function needs($condition, $errorMessage, $exceptionClass = null)
29
    {
30
        if (!$condition) {
31
            if (!$exceptionClass) {
32
                $exceptionClass = CryptoPolyfillException::class;
33
            }
34
            throw new $exceptionClass($errorMessage);
35
        }
36
    }
37
}