Resources
2 years ago
LICENSE
2 years ago
Php80.php
1 year ago
PhpToken.php
1 year ago
README.md
2 years ago
bootstrap.php
2 years ago
Php80.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace Symfony\Polyfill\Php80; |
| 12 | |
| 13 | /** |
| 14 | * @author Ion Bazan <ion.bazan@gmail.com> |
| 15 | * @author Nico Oelgart <nicoswd@gmail.com> |
| 16 | * @author Nicolas Grekas <p@tchwork.com> |
| 17 | * |
| 18 | * @internal |
| 19 | */ |
| 20 | final class Php80 |
| 21 | { |
| 22 | public static function fdiv(float $dividend, float $divisor) : float |
| 23 | { |
| 24 | return @($dividend / $divisor); |
| 25 | } |
| 26 | public static function get_debug_type($value) : string |
| 27 | { |
| 28 | switch (\true) { |
| 29 | case null === $value: |
| 30 | return 'null'; |
| 31 | case \is_bool($value): |
| 32 | return 'bool'; |
| 33 | case \is_string($value): |
| 34 | return 'string'; |
| 35 | case \is_array($value): |
| 36 | return 'array'; |
| 37 | case \is_int($value): |
| 38 | return 'int'; |
| 39 | case \is_float($value): |
| 40 | return 'float'; |
| 41 | case \is_object($value): |
| 42 | break; |
| 43 | case $value instanceof \__PHP_Incomplete_Class: |
| 44 | return '__PHP_Incomplete_Class'; |
| 45 | default: |
| 46 | if (null === ($type = @get_resource_type($value))) { |
| 47 | return 'unknown'; |
| 48 | } |
| 49 | if ('Unknown' === $type) { |
| 50 | $type = 'closed'; |
| 51 | } |
| 52 | return "resource ({$type})"; |
| 53 | } |
| 54 | $class = \get_class($value); |
| 55 | if (\false === strpos($class, '@')) { |
| 56 | return $class; |
| 57 | } |
| 58 | return ((get_parent_class($class) ?: key(class_implements($class))) ?: 'class') . '@anonymous'; |
| 59 | } |
| 60 | public static function get_resource_id($res) : int |
| 61 | { |
| 62 | if (!\is_resource($res) && null === @get_resource_type($res)) { |
| 63 | throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res))); |
| 64 | } |
| 65 | return (int) $res; |
| 66 | } |
| 67 | public static function preg_last_error_msg() : string |
| 68 | { |
| 69 | switch (preg_last_error()) { |
| 70 | case \PREG_INTERNAL_ERROR: |
| 71 | return 'Internal error'; |
| 72 | case \PREG_BAD_UTF8_ERROR: |
| 73 | return 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
| 74 | case \PREG_BAD_UTF8_OFFSET_ERROR: |
| 75 | return 'The offset did not correspond to the beginning of a valid UTF-8 code point'; |
| 76 | case \PREG_BACKTRACK_LIMIT_ERROR: |
| 77 | return 'Backtrack limit exhausted'; |
| 78 | case \PREG_RECURSION_LIMIT_ERROR: |
| 79 | return 'Recursion limit exhausted'; |
| 80 | case \PREG_JIT_STACKLIMIT_ERROR: |
| 81 | return 'JIT stack limit exhausted'; |
| 82 | case \PREG_NO_ERROR: |
| 83 | return 'No error'; |
| 84 | default: |
| 85 | return 'Unknown error'; |
| 86 | } |
| 87 | } |
| 88 | public static function str_contains(string $haystack, string $needle) : bool |
| 89 | { |
| 90 | return '' === $needle || \false !== strpos($haystack, $needle); |
| 91 | } |
| 92 | public static function str_starts_with(string $haystack, string $needle) : bool |
| 93 | { |
| 94 | return 0 === strncmp($haystack, $needle, \strlen($needle)); |
| 95 | } |
| 96 | public static function str_ends_with(string $haystack, string $needle) : bool |
| 97 | { |
| 98 | if ('' === $needle || $needle === $haystack) { |
| 99 | return \true; |
| 100 | } |
| 101 | if ('' === $haystack) { |
| 102 | return \false; |
| 103 | } |
| 104 | $needleLength = \strlen($needle); |
| 105 | return $needleLength <= \strlen($haystack) && 0 === substr_compare($haystack, $needle, -$needleLength); |
| 106 | } |
| 107 | } |
| 108 |