mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 12:09:20 +03:00
Move php8.php to /app/libraries/polyfill/
This commit is contained in:
parent
5262e59fdd
commit
c6aad25581
3 changed files with 77 additions and 38 deletions
76
snappymail/v/0.0.0/app/libraries/polyfill/php8.php
Normal file
76
snappymail/v/0.0.0/app/libraries/polyfill/php8.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
if (\PHP_VERSION_ID < 80000)
|
||||
{
|
||||
interface Stringable
|
||||
{
|
||||
public function __toString() : string;
|
||||
}
|
||||
|
||||
if (!class_exists('ValueError')) {
|
||||
class ValueError extends Error
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
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 (!function_exists('get_debug_type')) {
|
||||
function get_debug_type($value): string
|
||||
{
|
||||
$type = gettype($value);
|
||||
switch ($type) {
|
||||
case 'NULL': return 'null';
|
||||
case 'boolean': return 'bool';
|
||||
case 'double': return 'float';
|
||||
case 'integer': return 'int';
|
||||
case 'object':
|
||||
// if ($value instanceof __PHP_Incomplete_Class) return '__PHP_Incomplete_Class';
|
||||
$class = get_class($value);
|
||||
if (false === strpos($class, '@')) {
|
||||
return $class;
|
||||
}
|
||||
$parent = get_parent_class($class);
|
||||
if ($parent) {
|
||||
return $parent . '@anonymous';
|
||||
}
|
||||
$implements = class_implements($class);
|
||||
if ($implements) {
|
||||
return key($implements) . '@anonymous';
|
||||
}
|
||||
return 'class@anonymous';
|
||||
case 'resource':
|
||||
$type = get_resource_type($value);
|
||||
if (null === $type) {
|
||||
return 'unknown';
|
||||
}
|
||||
if ('Unknown' === $type) {
|
||||
$type = 'closed';
|
||||
}
|
||||
return "resource ($type)";
|
||||
default:
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ if (defined('APP_VERSION_ROOT_PATH')) {
|
|||
|
||||
// PHP 8
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
require __DIR__ . '/php8.php';
|
||||
require __DIR__ . '/app/libraries/polyfill/php8.php';
|
||||
}
|
||||
|
||||
if (!defined('APP_VERSION')) {
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
if (\PHP_VERSION_ID < 80000)
|
||||
{
|
||||
interface Stringable
|
||||
{
|
||||
public function __toString() : string;
|
||||
}
|
||||
|
||||
if (!class_exists('ValueError')) {
|
||||
class ValueError extends Error
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue