Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Context | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| all | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| set | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace NewfoldLabs\WP\Context; |
| 3 | |
| 4 | use function WP_Forge\Helpers\dataGet; |
| 5 | use function WP_Forge\Helpers\dataSet; |
| 6 | |
| 7 | /** |
| 8 | * This class adds context functionality. |
| 9 | **/ |
| 10 | class Context { |
| 11 | |
| 12 | /** |
| 13 | * Context array |
| 14 | * |
| 15 | * @var Array |
| 16 | */ |
| 17 | public static $context = array(); |
| 18 | |
| 19 | /** |
| 20 | * All contexts |
| 21 | * |
| 22 | * @return Array $context - all context |
| 23 | */ |
| 24 | public static function all() { |
| 25 | return self::$context; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Get the context value |
| 30 | * |
| 31 | * @param String $name - the name of the context to get |
| 32 | * @param String $default - the default value if not defined |
| 33 | * @return Array $context - value of the named context |
| 34 | */ |
| 35 | public static function get( $name, $default = null ) { |
| 36 | return dataGet( self::$context, $name, $default ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Set a context value |
| 41 | * |
| 42 | * @param String $name - the name of the context to set |
| 43 | * @param String $value - the value to set |
| 44 | */ |
| 45 | public static function set( $name, $value ) { |
| 46 | dataSet( self::$context, $name, $value ); |
| 47 | } |
| 48 | } |