Skip to content

Commit 2b18ad0

Browse files
feature #437 [PHP 8.3] Polyfill new non-overloaded variants of functions (IonBazan)
This PR was squashed before being merged into the 1.29-dev branch. Discussion ---------- [PHP 8.3] Polyfill new non-overloaded variants of functions This PR aims to add new PHP 8.3 functions introduced with RFC: https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures Comments and feedback welcome 🙏🏻 - [x] ~array_keys_filter~ (rejected) - [x] ldap_connect_wallet - [x] ldap_exop_sync - [x] stream_context_set_options Fixes #436 Commits ------- 8066764 [PHP 8.3] Polyfill new non-overloaded variants of functions
2 parents 45728c2 + 8066764 commit 2b18ad0

File tree

6 files changed

+54
-0
lines changed

6 files changed

+54
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 1.29.0
22

3+
* Polyfill `ldap_exop_sync()`
4+
* Polyfill `ldap_connect_wallet()`
5+
* Polyfill `stream_context_set_options()`
36
* Polyfill `odbc_connection_string_is_quoted()`
47
* Polyfill `odbc_connection_string_should_quote()`
58
* Polyfill `odbc_connection_string_quote()`

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Polyfills are provided for:
7575
- the `json_validate` function introduced in PHP 8.3;
7676
- the `Override` attribute introduced in PHP 8.3;
7777
- the `mb_str_pad` function introduced in PHP 8.3;
78+
- the `ldap_exop_sync` function introduced in PHP 8.3;
79+
- the `ldap_connect_wallet` function introduced in PHP 8.3;
80+
- the `stream_context_set_options` function introduced in PHP 8.3;
7881

7982
It is strongly recommended to upgrade your PHP version and/or install the missing
8083
extensions whenever possible. This polyfill should be used only when there is no

src/Php83/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This component provides features added to PHP 8.3 core:
66
- [`json_validate`](https://wiki.php.net/rfc/json_validate)
77
- [`Override`](https://wiki.php.net/rfc/marking_overriden_methods)
88
- [`mb_str_pad`](https://wiki.php.net/rfc/mb_str_pad)
9+
- [`ldap_exop_sync`](https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures)
10+
- [`ldap_connect_wallet`](https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures)
11+
- [`stream_context_set_options`](https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures)
912

1013
More information can be found in the
1114
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).

src/Php83/bootstrap.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ function json_validate(string $json, int $depth = 512, int $flags = 0): bool { r
2222
if (!function_exists('mb_str_pad') && function_exists('mb_substr')) {
2323
function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, ?string $encoding = null): string { return p\Php83::mb_str_pad($string, $length, $pad_string, $pad_type, $encoding); }
2424
}
25+
26+
if (!function_exists('stream_context_set_options')) {
27+
function stream_context_set_options($context, array $options): bool { return stream_context_set_option($context, $options); }
28+
}
29+
30+
if (\PHP_VERSION_ID >= 80100) {
31+
return require __DIR__.'/bootstrap81.php';
32+
}
33+
34+
if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) {
35+
function ldap_exop_sync($ldap, string $request_oid, string $request_data = null, array $controls = null, &$response_data = null, &$response_oid = null): bool { return ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid); }
36+
}
37+
38+
if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) {
39+
function ldap_connect_wallet(?string $uri, string $wallet, string $password, int $auth_mode = \GSLC_SSL_NO_AUTH) { return ldap_connect($uri, $wallet, $password, $auth_mode); }
40+
}

src/Php83/bootstrap81.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
if (\PHP_VERSION_ID >= 80300) {
13+
return;
14+
}
15+
16+
if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) {
17+
function ldap_exop_sync(\LDAP\Connection $ldap, string $request_oid, string $request_data = null, array $controls = null, &$response_data = null, &$response_oid = null): bool { return ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid); }
18+
}
19+
20+
if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) {
21+
function ldap_connect_wallet(?string $uri, string $wallet, #[\SensitiveParameter] string $password, int $auth_mode = \GSLC_SSL_NO_AUTH): \LDAP\Connection|false { return ldap_connect($uri, $wallet, $password, $auth_mode); }
22+
}

tests/Php83/Php83Test.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,11 @@ public static function jsonInvalidOptionsProvider(): iterable
182182
];
183183
}
184184
}
185+
186+
public function testStreamContextSetOptions()
187+
{
188+
$context = stream_context_create();
189+
$this->assertTrue(stream_context_set_options($context, ['http' => ['method' => 'POST']]));
190+
$this->assertSame(['http' => ['method' => 'POST']], stream_context_get_options($context));
191+
}
185192
}

0 commit comments

Comments
 (0)