-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstant.php
More file actions
71 lines (55 loc) · 1.59 KB
/
Copy pathConstant.php
File metadata and controls
71 lines (55 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/base/blob/master/LICENSE
*/
namespace Quid\Base;
// constant
// class with static methods to work with PHP constants
final class Constant extends Root
{
// config
protected static array $config = [];
// is
// retourne vrai si la constante est défini
final public static function is($name):bool
{
return is_string($name) && defined($name);
}
// get
// retourne la valeur d'une constante définie
final public static function get(string $name)
{
return (defined($name))? constant($name):null;
}
// set
// crée une nouvelle constante si elle n'existe pas
final public static function set(string $name,$value):bool
{
return (!empty($name) && !self::is($name))? define($name,$value):false;
}
// all
// retourne toutes les constantes définis
final public static function all(?string $key=null,bool $categorize=true):array
{
$return = [];
$constants = get_defined_constants($categorize);
if(!empty($key))
{
if(array_key_exists($key,$constants))
$return = $constants[$key];
}
else
$return = $constants;
return $return;
}
// user
// retourne les constantes définis par l'utilisateur
final public static function user(bool $categorize=true):array
{
return self::all('user',$categorize);
}
}
?>