Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SimpleWebRequest | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getVal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * SimpleWebRequest.php |
4 | * |
5 | * This file is part of the Codex design system, the official design system |
6 | * for Wikimedia projects. It provides the `SimpleWebRequest` class, which |
7 | * implements the `IWebRequest` interface. This class serves as a simple wrapper |
8 | * around an associative array, providing standardized access to web request data |
9 | * for Codex components. |
10 | * |
11 | * The `SimpleWebRequest` class enables Codex to interact with request data in a consistent |
12 | * manner without being tightly coupled to a specific web framework. |
13 | * |
14 | * @category Utility |
15 | * @package Codex\Utility |
16 | * @since 0.1.0 |
17 | * @author Doğu Abaris <abaris@null.net> |
18 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
19 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
20 | */ |
21 | |
22 | namespace Wikimedia\Codex\Utility; |
23 | |
24 | use Wikimedia\Codex\Contract\IWebRequest; |
25 | |
26 | /** |
27 | * SimpleWebRequest provides access to web request data using an array structure. |
28 | * |
29 | * The `SimpleWebRequest` class implements the `IWebRequest` interface, allowing it |
30 | * to provide a simple, array-based mechanism for accessing request parameters. |
31 | * It adapts an associative array of request data, allowing Codex components to |
32 | * retrieve values in a standardized way. |
33 | * |
34 | * @category Utility |
35 | * @package Codex\Utility |
36 | * @since 0.1.0 |
37 | * @author Doğu Abaris <abaris@null.net> |
38 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
39 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
40 | */ |
41 | class SimpleWebRequest implements IWebRequest { |
42 | |
43 | /** |
44 | * The array containing request data. |
45 | */ |
46 | protected array $data; |
47 | |
48 | /** |
49 | * Constructor for SimpleWebRequest. |
50 | * |
51 | * @param array $data The array containing request data. |
52 | */ |
53 | public function __construct( array $data ) { |
54 | $this->data = $data; |
55 | } |
56 | |
57 | /** |
58 | * Fetch a value from the request data. |
59 | * |
60 | * This method retrieves the value of a specific parameter from the data array. |
61 | * If the parameter is not present, the provided default value will be returned. |
62 | * |
63 | * @since 1.0.0 |
64 | * @param string $name The name of the parameter to fetch. |
65 | * @param mixed $default The default value to return if the parameter is not |
66 | * set in the request data. Defaults to null. |
67 | * @return mixed The value of the parameter, or the `$default` value if the |
68 | * parameter is not set. |
69 | */ |
70 | public function getVal( string $name, $default = null ) { |
71 | return $this->data[$name] ?? $default; |
72 | } |
73 | } |