Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 | 11 | |
50bfb460 SB |
12 | /** |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
50bfb460 SB |
16 | */ |
17 | ||
5bc392e6 EM |
18 | /** |
19 | * Class CRM_Utils_Constant | |
20 | */ | |
6a488035 TO |
21 | class CRM_Utils_Constant { |
22 | ||
23 | /** | |
02549793 | 24 | * Determine the value of a constant, if any. |
5bc392e6 | 25 | * |
f9920e29 | 26 | * If the specified constant is undefined, check for an environment |
27 | * variable, defaulting the passed in default value. | |
6a488035 TO |
28 | * |
29 | * @param string $name | |
30 | * @param mixed $default | |
02549793 | 31 | * (optional) |
6a488035 TO |
32 | * @return mixed |
33 | */ | |
f9920e29 | 34 | public static function value(string $name, $default = NULL) { |
6a488035 TO |
35 | if (defined($name)) { |
36 | return constant($name); | |
0db6c3e1 | 37 | } |
f9920e29 | 38 | if (($value = getenv($name)) !== FALSE) { |
39 | define($name, $value); | |
40 | return $value; | |
6a488035 | 41 | } |
f9920e29 | 42 | return $default; |
6a488035 | 43 | } |
96025800 | 44 | |
232624b1 | 45 | } |