Skip to content

Commit 4ec9dc2

Browse files
committed
fix(http): resolve dynamic property deprecation in Mock client
Add #[AllowDynamicProperties] to legacy Horde_Http_Response_Base for PHP 8.2+ compatibility. Fix TypeError in PSR-4 Mock client when constructed without Options argument. Closes issue #4
1 parent b92ab58 commit 4ec9dc2

20 files changed

Lines changed: 163 additions & 131 deletions

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ composer.lock
4949
/phpstan.neon
5050
# PHPStan cache directory
5151
/.phpstan.cache/
52+
53+
# Added by horde-components QC --fix-qc-issues
54+
# Horde installer plugin runtime data
55+
/var/
56+
# Horde installer plugin web-accessible directory
57+
/web/

.horde.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ vendor: horde
5252
quality:
5353
phpstan:
5454
level: 9
55+
keywords: []

lib/Horde/Http.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
23
/**
3-
* Copyright 2007-2017 Horde LLC (http://www.horde.org/)
4+
* Copyright 2007-2026 Horde LLC (http://www.horde.org/)
45
*
56
* See the enclosed file LICENSE for license information (BSD). If you
67
* did not receive this file, see http://www.horde.org/licenses/bsd.
@@ -25,16 +26,16 @@ class Horde_Http
2526
/**
2627
* Authentication schemes
2728
*/
28-
const AUTH_ANY = 'ANY';
29-
const AUTH_BASIC = 'BASIC';
30-
const AUTH_DIGEST = 'DIGEST';
31-
const AUTH_NTLM = 'NTLM';
32-
const AUTH_GSSNEGOTIATE = 'GSSNEGOTIATE';
29+
public const AUTH_ANY = 'ANY';
30+
public const AUTH_BASIC = 'BASIC';
31+
public const AUTH_DIGEST = 'DIGEST';
32+
public const AUTH_NTLM = 'NTLM';
33+
public const AUTH_GSSNEGOTIATE = 'GSSNEGOTIATE';
3334

3435
/**
3536
* Proxy types
3637
*/
37-
const PROXY_HTTP = 0;
38-
const PROXY_SOCKS4 = 1;
39-
const PROXY_SOCKS5 = 2;
38+
public const PROXY_HTTP = 0;
39+
public const PROXY_SOCKS4 = 1;
40+
public const PROXY_SOCKS5 = 2;
4041
}

lib/Horde/Http/Client.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
23
/**
3-
* Copyright 2007-2017 Horde LLC (http://www.horde.org/)
4+
* Copyright 2007-2026 Horde LLC (http://www.horde.org/)
45
*
56
* See the enclosed file LICENSE for license information (BSD). If you
67
* did not receive this file, see http://www.horde.org/licenses/bsd.
@@ -99,7 +100,7 @@ class Horde_Http_Client
99100
* constructor. See the class properties for available
100101
* settings.
101102
*/
102-
public function __construct($args = array())
103+
public function __construct($args = [])
103104
{
104105
// Set or create request object
105106
if (isset($args['request'])) {
@@ -124,7 +125,7 @@ public function __construct($args = array())
124125
* @throws Horde_Http_Exception
125126
* @return Horde_Http_Response_Base
126127
*/
127-
public function get($uri = null, $headers = array())
128+
public function get($uri = null, $headers = [])
128129
{
129130
return $this->request('GET', $uri, null, $headers);
130131
}
@@ -139,7 +140,7 @@ public function get($uri = null, $headers = array())
139140
* @throws Horde_Http_Exception
140141
* @return Horde_Http_Response_Base
141142
*/
142-
public function post($uri = null, $data = null, $headers = array())
143+
public function post($uri = null, $data = null, $headers = [])
143144
{
144145
return $this->request('POST', $uri, $data, $headers);
145146
}
@@ -154,11 +155,11 @@ public function post($uri = null, $data = null, $headers = array())
154155
* @throws Horde_Http_Exception
155156
* @return Horde_Http_Response_Base
156157
*/
157-
public function put($uri = null, $data = null, $headers = array())
158+
public function put($uri = null, $data = null, $headers = [])
158159
{
159160
if ($this->_httpMethodOverride) {
160161
$headers = array_merge(
161-
array('X-HTTP-Method-Override' => 'PUT'),
162+
['X-HTTP-Method-Override' => 'PUT'],
162163
$headers
163164
);
164165
return $this->post($uri, $data, $headers);
@@ -176,11 +177,11 @@ public function put($uri = null, $data = null, $headers = array())
176177
* @throws Horde_Http_Exception
177178
* @return Horde_Http_Response_Base
178179
*/
179-
public function delete($uri = null, $headers = array())
180+
public function delete($uri = null, $headers = [])
180181
{
181182
if ($this->_httpMethodOverride) {
182183
$headers = array_merge(
183-
array('X-HTTP-Method-Override' => 'DELETE'),
184+
['X-HTTP-Method-Override' => 'DELETE'],
184185
$headers
185186
);
186187
return $this->post($uri, null, $headers);
@@ -198,7 +199,7 @@ public function delete($uri = null, $headers = array())
198199
* @throws Horde_Http_Exception
199200
* @return Horde_Http_Response_Base
200201
*/
201-
public function head($uri = null, $headers = array())
202+
public function head($uri = null, $headers = [])
202203
{
203204
return $this->request('HEAD', $uri, null, $headers);
204205
}
@@ -220,9 +221,11 @@ public function head($uri = null, $headers = array())
220221
* @return Horde_Http_Response_Base
221222
*/
222223
public function request(
223-
$method, $uri = null, $data = null, $headers = array()
224-
)
225-
{
224+
$method,
225+
$uri = null,
226+
$data = null,
227+
$headers = []
228+
) {
226229
if ($method !== null) {
227230
$this->request->method = $method;
228231
}
@@ -251,7 +254,7 @@ public function request(
251254
*/
252255
public function __get($name)
253256
{
254-
return isset($this->{'_' . $name}) ? $this->{'_' . $name} : null;
257+
return $this->{'_' . $name} ?? null;
255258
}
256259

257260
/**
@@ -271,7 +274,7 @@ public function __set($name, $value)
271274
}
272275
}
273276

274-
list($object, $objectkey) = explode('.', $name, 2);
277+
[$object, $objectkey] = explode('.', $name, 2);
275278
if ($object == 'request') {
276279
$this->$object->$objectkey = $value;
277280
return true;

lib/Horde/Http/Exception.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
23
/**
3-
* Copyright 2007-2017 Horde LLC (http://www.horde.org/)
4+
* Copyright 2007-2026 Horde LLC (http://www.horde.org/)
45
*
56
* See the enclosed file LICENSE for license information (BSD). If you
67
* did not receive this file, see http://www.horde.org/licenses/bsd.
@@ -20,6 +21,4 @@
2021
* @license http://www.horde.org/licenses/bsd BSD
2122
* @package Http
2223
*/
23-
class Horde_Http_Exception extends Horde_Exception_Wrapped
24-
{
25-
}
24+
class Horde_Http_Exception extends Horde_Exception_Wrapped {}

lib/Horde/Http/Request/Base.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
23
/**
3-
* Copyright 2007-2017 Horde LLC (http://www.horde.org/)
4+
* Copyright 2007-2026 Horde LLC (http://www.horde.org/)
45
*
56
* See the enclosed file LICENSE for license information (BSD). If you
67
* did not receive this file, see http://www.horde.org/licenses/bsd.
@@ -49,29 +50,29 @@ abstract class Horde_Http_Request_Base
4950
* Request headers
5051
* @var array
5152
*/
52-
protected $_headers = array();
53+
protected $_headers = [];
5354

5455
/**
5556
* @var array
5657
*/
57-
protected $_options = array();
58+
protected $_options = [];
5859

5960
/**
6061
* Constructor
6162
*/
62-
public function __construct($options = array())
63+
public function __construct($options = [])
6364
{
6465
$this->setOptions($options);
6566
}
6667

67-
public function setOptions($options = array())
68+
public function setOptions($options = [])
6869
{
6970
$this->_options = array_merge($this->getDefaultOptions(), $options);
7071
}
7172

7273
public function getDefaultOptions()
7374
{
74-
return array(
75+
return [
7576
'uri' => null,
7677
'method' => 'GET',
7778
'data' => null,
@@ -88,7 +89,7 @@ public function getDefaultOptions()
8889
'timeout' => 5,
8990
'userAgent' => str_replace(' @' . 'version@', '', 'Horde_Http @version@'),
9091
'verifyPeer' => true,
91-
);
92+
];
9293
}
9394

9495
/**
@@ -108,11 +109,11 @@ abstract public function send();
108109
public function __get($name)
109110
{
110111
switch ($name) {
111-
case 'headers':
112-
return $this->_headers;
112+
case 'headers':
113+
return $this->_headers;
113114
}
114115

115-
return isset($this->_options[$name]) ? $this->_options[$name] : null;
116+
return $this->_options[$name] ?? null;
116117
}
117118

118119
/**
@@ -124,9 +125,9 @@ public function __get($name)
124125
public function __set($name, $value)
125126
{
126127
switch ($name) {
127-
case 'headers':
128-
$this->setHeaders($value);
129-
break;
128+
case 'headers':
129+
$this->setHeaders($value);
130+
break;
130131
}
131132

132133
$this->_options[$name] = $value;
@@ -141,7 +142,7 @@ public function __set($name, $value)
141142
public function setHeaders($headers, $value = null)
142143
{
143144
if (!is_array($headers)) {
144-
$headers = array($headers => $value);
145+
$headers = [$headers => $value];
145146
}
146147

147148
foreach ($headers as $header => $value) {
@@ -157,6 +158,6 @@ public function setHeaders($headers, $value = null)
157158
*/
158159
public function getHeader($header)
159160
{
160-
return isset($this->_headers[$header]) ? $this->_headers[$header] : null;
161+
return $this->_headers[$header] ?? null;
161162
}
162163
}

lib/Horde/Http/Request/Curl.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
23
/**
3-
* Copyright 2007-2017 Horde LLC (http://www.horde.org/)
4+
* Copyright 2007-2026 Horde LLC (http://www.horde.org/)
45
*
56
* See the enclosed file LICENSE for license information (BSD). If you
67
* did not receive this file, see http://www.horde.org/licenses/bsd.
@@ -28,20 +29,20 @@ class Horde_Http_Request_Curl extends Horde_Http_Request_Base
2829
*
2930
* @var array
3031
*/
31-
protected $_httpAuthSchemes = array(
32+
protected $_httpAuthSchemes = [
3233
Horde_Http::AUTH_ANY => CURLAUTH_ANY,
3334
Horde_Http::AUTH_BASIC => CURLAUTH_BASIC,
3435
Horde_Http::AUTH_DIGEST => CURLAUTH_DIGEST,
3536
Horde_Http::AUTH_GSSNEGOTIATE => CURLAUTH_GSSNEGOTIATE,
3637
Horde_Http::AUTH_NTLM => CURLAUTH_NTLM,
37-
);
38+
];
3839

3940
/**
4041
* Constructor
4142
*
4243
* @throws Horde_Http_Exception
4344
*/
44-
public function __construct($args = array())
45+
public function __construct($args = [])
4546
{
4647
if (!extension_loaded('curl')) {
4748
throw new Horde_Http_Exception('The curl extension is not installed. See http://php.net/curl.installation');
@@ -59,7 +60,7 @@ public function __construct($args = array())
5960
public function send()
6061
{
6162
$curl = curl_init();
62-
curl_setopt($curl, CURLOPT_URL, (string)$this->uri);
63+
curl_setopt($curl, CURLOPT_URL, (string) $this->uri);
6364
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
6465
curl_setopt($curl, CURLOPT_HEADER, true);
6566
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->method);
@@ -102,7 +103,7 @@ public function send()
102103
}
103104
if ($this->proxyType == Horde_Http::PROXY_SOCKS5) {
104105
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
105-
} else if ($this->proxyType != Horde_Http::PROXY_HTTP) {
106+
} elseif ($this->proxyType != Horde_Http::PROXY_HTTP) {
106107
throw new Horde_Http_Exception(sprintf('Proxy type %s not supported by this request type!', $this->proxyType));
107108
}
108109
}
@@ -114,7 +115,7 @@ public function send()
114115
}
115116

116117
// Concatenate the headers
117-
$hdr = array();
118+
$hdr = [];
118119
$headers = $this->headers;
119120
if (empty($headers['Expect'])) {
120121
$headers['Expect'] = '';
@@ -130,7 +131,7 @@ public function send()
130131
throw new Horde_Http_Exception(curl_error($curl), curl_errno($curl));
131132
}
132133
$info = curl_getinfo($curl);
133-
return new Horde_Http_Response_Curl((string)$this->uri, $result, $info);
134+
return new Horde_Http_Response_Curl((string) $this->uri, $result, $info);
134135
}
135136

136137
/**

lib/Horde/Http/Request/Factory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
23
/**
3-
* Copyright 2007-2017 Horde LLC (http://www.horde.org/)
4+
* Copyright 2007-2026 Horde LLC (http://www.horde.org/)
45
*
56
* See the enclosed file LICENSE for license information (BSD). If you
67
* did not receive this file, see http://www.horde.org/licenses/bsd.

0 commit comments

Comments
 (0)