-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-vars.php
62 lines (56 loc) · 1.19 KB
/
class-vars.php
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
<?php
/**
* Setter & getter utility
*
* @package Ultimate_Dashboard
*/
namespace Udb;
defined( 'ABSPATH' ) || die( "Can't access directly" );
/**
* Global setter & getter utility
*
* Vars::set($key, $value);
*
* @param string/array $key
* @param mix $value
*
* Vars::get($key);
* @param string $key
* @return mix $value
*/
class Vars {
/**
* Item's container
*
* @var array
*/
private static $vars = [];
/**
* Get value from a given key
*
* @param string $name The key name.
* @return mixed
*/
public static function get( $name ) {
$value = isset( self::$vars[ $name ] ) ? self::$vars[ $name ] : '';
return $value;
}
/**
* Set key-value pair
* - single mode: set the $key as key name, $value as the data
* - multiple mode: set the $key as array of key-value pairs, and leave the $value empty
*
* @param string $name Can be either key name or array of key-value pairs.
* @param string $value The data.
* @return void
*/
public static function set( $name, $value = '' ) {
if ( is_array( $name ) ) {
foreach ( $name as $key => $value ) {
self::$vars[ $key ] = $value;
}
} else {
self::$vars[ $name ] = $value;
}
}
}