-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData_Request.php
More file actions
165 lines (149 loc) · 3.22 KB
/
Copy pathData_Request.php
File metadata and controls
165 lines (149 loc) · 3.22 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* Data_Request
*
* @package Google\Site_Kit\Core\REST_API
* @copyright 2021 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\REST_API;
/**
* Class Data_Request
*
* @since 1.0.0
*
* @property-read string $method Request method.
* @property-read string $type Request type.
* @property-read string $identifier Request identifier.
* @property-read string $datapoint Request datapoint.
* @property-read array $data Request data parameters.
* @property-read string $key Request key.
*/
class Data_Request implements \ArrayAccess {
/**
* Request method.
*
* @var string
*/
protected $method;
/**
* Request type.
*
* @var string
*/
protected $type;
/**
* Request identifier.
*
* @var string
*/
protected $identifier;
/**
* Request datapoint.
*
* @var string
*/
protected $datapoint;
/**
* Request data parameters.
*
* @var array
*/
protected $data;
/**
* Request key.
*
* @var string
*/
protected $key;
/**
* Data_Request constructor.
*
* @param string $method Request method.
* @param string $type Request type.
* @param string $identifier Request identifier.
* @param string $datapoint Request datapoint.
* @param array|self $data Request data parameters.
* @param string $key Request cache key.
*/
public function __construct(
$method = null,
$type = null,
$identifier = null,
$datapoint = null,
$data = array(),
$key = null
) {
$this->method = strtoupper( $method );
$this->type = $type;
$this->identifier = $identifier;
$this->datapoint = $datapoint;
$this->data = $data instanceof self ? $data->data : (array) $data;
$this->key = $key;
}
/**
* Gets the accessed property by the given name.
*
* @param string $name Property name.
*
* @return mixed
*/
public function __get( $name ) {
return isset( $this->$name ) ? $this->$name : null;
}
/**
* Checks whether or not the given magic property is set.
*
* @param string $name Property name.
*
* @return bool
*/
public function __isset( $name ) {
return isset( $this->$name );
}
/**
* Checks whether the given key exists.
*
* @param string|int $key Key to check.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists( $key ) {
return array_key_exists( $key, $this->data );
}
/**
* Gets the value at the given key.
*
* @param string|int $key Key to return the value for.
*
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet( $key ) {
if ( $this->offsetExists( $key ) ) {
return $this->data[ $key ];
}
return null;
}
/**
* Sets the given key to the given value.
*
* @param string|int $key Key to set the value for.
* @param mixed $value New value for the given key.
*/
#[\ReturnTypeWillChange]
public function offsetSet( $key, $value ) {
// Data is immutable.
}
/**
* Unsets the given key.
*
* @param string|int $key Key to unset.
*/
#[\ReturnTypeWillChange]
public function offsetUnset( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment
// Data is immutable.
}
}