- md5
- e2a874de0de72df4a45a7dda9c1e9eeb
- sha1
- 51b55ce6874f506bb4748937c77795f56038f7cd
- sha256
- 04bcfc058f697627c5c85e19c04b5ab9f03ebe904804fd5a612934dc4fe735dd
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
<?php
/**
* Polyfills for PHP functions that may not be available in older versions.
*
* @since 0.1.0
*/
declare (strict_types=1);
namespace WordPress\AiClientDependencies;
if (!\function_exists('array_is_list') && !\function_exists('WordPress\AiClientDependencies\array_is_list')) {
/**
* Checks whether a given array is a list.
*
* An array is considered a list if its keys consist of consecutive numbers from 0 to count($array)-1.
*
* @since 0.1.0
*
* @param array<mixed> $array The array to check.
* @return bool True if the array is a list, false otherwise.
*/
function array_is_list(array $array): bool
{
if ($array === []) {
return \true;
}
$expectedKey = 0;
foreach (\array_keys($array) as $key) {
if ($key !== $expectedKey) {
return \false;
}
$expectedKey++;
}
return \true;
}
}
if (!\function_exists('str_starts_with') && !\function_exists('WordPress\AiClientDependencies\str_starts_with')) {
/**
* Checks if a string starts with a given substring.
*
* @since 0.1.0
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for.
* @return bool True if $haystack starts with $needle, false otherwise.
*/
function str_starts_with(string $haystack, string $needle): bool
{
if ('' === $needle) {
return \true;
}
return 0 === \strpos($haystack, $needle);
}
}
if (!\function_exists('str_contains') && !\function_exists('WordPress\AiClientDependencies\str_contains')) {
/**
* Checks if a string contains a given substring.
*
* @since 0.1.0
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for.
* @return bool True if $haystack contains $needle, false otherwise.
*/
function str_contains(string $haystack, string $needle): bool
{
if ('' === $needle) {
return \true;
}
return \false !== \strpos($haystack, $needle);
}
}
if (!\function_exists('str_ends_with') && !\function_exists('WordPress\AiClientDependencies\str_ends_with')) {
/**
* Checks if a string ends with a given substring.
*
* @since 0.1.0
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for.
* @return bool True if $haystack ends with $needle, false otherwise.
*/
function str_ends_with(string $haystack, string $needle): bool
{
if ('' === $haystack) {
return '' === $needle;
}
$len = \strlen($needle);
return \substr($haystack, -$len, $len) === $needle;
}
}
The same content is in 2 releases, WordPress 7.0-beta1 to 7.0-beta2. See them all, or every version of this file.