Split PHP polyfills from include.php

This commit is contained in:
the-djmaze 2023-12-03 22:09:56 +01:00
parent cabc652aa2
commit be70870b72
2 changed files with 31 additions and 18 deletions

View file

@ -4,24 +4,8 @@ if (defined('APP_VERSION_ROOT_PATH')) {
}
// PHP 8
if (!function_exists('str_contains')) {
function str_contains(string $haystack, string $needle) : bool
{
return false !== strpos($haystack, $needle);
}
}
if (!function_exists('str_starts_with')) {
function str_starts_with(string $haystack, string $needle) : bool
{
return 0 === strncmp($haystack, $needle, strlen($needle));
}
}
if (!function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle) : bool
{
$length = strlen($needle);
return $length ? substr($haystack, -$length) === $needle : true;
}
if (\PHP_VERSION_ID < 80000) {
require __DIR__ . '/php8.php';
}
if (!defined('APP_VERSION')) {

View file

@ -0,0 +1,29 @@
<?php
if (\PHP_VERSION_ID < 80000)
{
interface Stringable
{
public function __toString() : string;
}
class ValueError extends Error
{
}
function str_contains(string $haystack, string $needle) : bool
{
return false !== strpos($haystack, $needle);
}
function str_starts_with(string $haystack, string $needle) : bool
{
return 0 === strncmp($haystack, $needle, strlen($needle));
}
function str_ends_with(string $haystack, string $needle) : bool
{
$length = strlen($needle);
return $length ? substr($haystack, -$length) === $needle : true;
}
}