This commit is contained in:
2025-05-12 14:25:25 +02:00
parent ab2db755ef
commit 9e378ca2b7
2719 changed files with 46505 additions and 60181 deletions

View File

@@ -13,6 +13,7 @@ namespace Symfony\Polyfill\Php83;
/**
* @author Ion Bazan <ion.bazan@gmail.com>
* @author Pierre Ambroise <pierre27.ambroise@gmail.com>
*
* @internal
*/
@@ -39,7 +40,7 @@ final class Php83
return \JSON_ERROR_NONE === json_last_error();
}
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, string $encoding = null): string
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null): string
{
if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], true)) {
throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH');
@@ -82,4 +83,115 @@ final class Php83
return mb_substr(str_repeat($pad_string, $leftPaddingLength), 0, $leftPaddingLength, $encoding).$string.mb_substr(str_repeat($pad_string, $rightPaddingLength), 0, $rightPaddingLength, $encoding);
}
}
public static function str_increment(string $string): string
{
if ('' === $string) {
throw new \ValueError('str_increment(): Argument #1 ($string) cannot be empty');
}
if (!preg_match('/^[a-zA-Z0-9]+$/', $string)) {
throw new \ValueError('str_increment(): Argument #1 ($string) must be composed only of alphanumeric ASCII characters');
}
if (is_numeric($string)) {
$offset = stripos($string, 'e');
if (false !== $offset) {
$char = $string[$offset];
++$char;
$string[$offset] = $char;
++$string;
switch ($string[$offset]) {
case 'f':
$string[$offset] = 'e';
break;
case 'F':
$string[$offset] = 'E';
break;
case 'g':
$string[$offset] = 'f';
break;
case 'G':
$string[$offset] = 'F';
break;
}
return $string;
}
}
return ++$string;
}
public static function str_decrement(string $string): string
{
if ('' === $string) {
throw new \ValueError('str_decrement(): Argument #1 ($string) cannot be empty');
}
if (!preg_match('/^[a-zA-Z0-9]+$/', $string)) {
throw new \ValueError('str_decrement(): Argument #1 ($string) must be composed only of alphanumeric ASCII characters');
}
if (preg_match('/\A(?:0[aA0]?|[aA])\z/', $string)) {
throw new \ValueError(sprintf('str_decrement(): Argument #1 ($string) "%s" is out of decrement range', $string));
}
if (!\in_array(substr($string, -1), ['A', 'a', '0'], true)) {
return implode('', \array_slice(str_split($string), 0, -1)).\chr(\ord(substr($string, -1)) - 1);
}
$carry = '';
$decremented = '';
for ($i = \strlen($string) - 1; $i >= 0; --$i) {
$char = $string[$i];
switch ($char) {
case 'A':
if ('' !== $carry) {
$decremented = $carry.$decremented;
$carry = '';
}
$carry = 'Z';
break;
case 'a':
if ('' !== $carry) {
$decremented = $carry.$decremented;
$carry = '';
}
$carry = 'z';
break;
case '0':
if ('' !== $carry) {
$decremented = $carry.$decremented;
$carry = '';
}
$carry = '9';
break;
case '1':
if ('' !== $carry) {
$decremented = $carry.$decremented;
$carry = '';
}
break;
default:
if ('' !== $carry) {
$decremented = $carry.$decremented;
$carry = '';
}
if (!\in_array($char, ['A', 'a', '0'], true)) {
$decremented = \chr(\ord($char) - 1).$decremented;
}
}
}
return $decremented;
}
}

View File

@@ -9,7 +9,9 @@ This component provides features added to PHP 8.3 core:
- [`ldap_exop_sync`](https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures)
- [`ldap_connect_wallet`](https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures)
- [`stream_context_set_options`](https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures)
- [`str_increment` and `str_decrement`](https://wiki.php.net/rfc/saner-inc-dec-operators)
- [`Date*Exception/Error classes`](https://wiki.php.net/rfc/datetime-exceptions)
- [`SQLite3Exception`](https://wiki.php.net/rfc/sqlite3_exceptions)
More information can be found in the
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (\PHP_VERSION_ID < 80300) {
class SQLite3Exception extends Exception
{
}
}

View File

@@ -19,20 +19,30 @@ if (!function_exists('json_validate')) {
function json_validate(string $json, int $depth = 512, int $flags = 0): bool { return p\Php83::json_validate($json, $depth, $flags); }
}
if (!function_exists('mb_str_pad') && function_exists('mb_substr')) {
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); }
if (extension_loaded('mbstring')) {
if (!function_exists('mb_str_pad')) {
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); }
}
}
if (!function_exists('stream_context_set_options')) {
function stream_context_set_options($context, array $options): bool { return stream_context_set_option($context, $options); }
}
if (!function_exists('str_increment')) {
function str_increment(string $string): string { return p\Php83::str_increment($string); }
}
if (!function_exists('str_decrement')) {
function str_decrement(string $string): string { return p\Php83::str_decrement($string); }
}
if (\PHP_VERSION_ID >= 80100) {
return require __DIR__.'/bootstrap81.php';
}
if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) {
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); }
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); }
}
if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) {

View File

@@ -14,7 +14,7 @@ if (\PHP_VERSION_ID >= 80300) {
}
if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) {
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); }
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); }
}
if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) {

View File

@@ -16,8 +16,7 @@
}
],
"require": {
"php": ">=7.1",
"symfony/polyfill-php80": "^1.14"
"php": ">=7.2"
},
"autoload": {
"psr-4": { "Symfony\\Polyfill\\Php83\\": "" },
@@ -26,9 +25,6 @@
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"