Файловый менеджер - Редактировать - /home/infrafs/INFRABIKEIT/wp-content/plugins/Utilities.tar
Назад
NumberUtil.php 0000644 00000002230 15133220005 0007327 0 ustar 00 <?php /** * A class of utilities for dealing with numbers. */ namespace Automattic\WooCommerce\Utilities; /** * A class of utilities for dealing with numbers. */ final class NumberUtil { /** * Round a number using the built-in `round` function, but unless the value to round is numeric * (a number or a string that can be parsed as a number), apply 'floatval' first to it * (so it will convert it to 0 in most cases). * * This is needed because in PHP 7 applying `round` to a non-numeric value returns 0, * but in PHP 8 it throws an error. Specifically, in WooCommerce we have a few places where * round('') is often executed. * * @param mixed $val The value to round. * @param int $precision The optional number of decimal digits to round to. * @param int $mode A constant to specify the mode in which rounding occurs. * * @return float The value rounded to the given precision as a float, or the supplied default value. */ public static function round( $val, int $precision = 0, int $mode = PHP_ROUND_HALF_UP ) : float { if ( ! is_numeric( $val ) ) { $val = floatval( $val ); } return round( $val, $precision, $mode ); } } ArrayUtil.php 0000644 00000004351 15133220005 0007163 0 ustar 00 <?php /** * A class of utilities for dealing with arrays. */ namespace Automattic\WooCommerce\Utilities; /** * A class of utilities for dealing with arrays. */ class ArrayUtil { /** * Get a value from an nested array by specifying the entire key hierarchy with '::' as separator. * * E.g. for [ 'foo' => [ 'bar' => [ 'fizz' => 'buzz' ] ] ] the value for key 'foo::bar::fizz' would be 'buzz'. * * @param array $array The array to get the value from. * @param string $key The complete key hierarchy, using '::' as separator. * @param mixed $default The value to return if the key doesn't exist in the array. * * @return mixed The retrieved value, or the supplied default value. * @throws \Exception $array is not an array. */ public static function get_nested_value( array $array, string $key, $default = null ) { $key_stack = explode( '::', $key ); $subkey = array_shift( $key_stack ); if ( isset( $array[ $subkey ] ) ) { $value = $array[ $subkey ]; if ( count( $key_stack ) ) { foreach ( $key_stack as $subkey ) { if ( is_array( $value ) && isset( $value[ $subkey ] ) ) { $value = $value[ $subkey ]; } else { $value = $default; break; } } } } else { $value = $default; } return $value; } /** * Checks if a given key exists in an array and its value can be evaluated as 'true'. * * @param array $array The array to check. * @param string $key The key for the value to check. * @return bool True if the key exists in the array and the value can be evaluated as 'true'. */ public static function is_truthy( array $array, string $key ) { return isset( $array[ $key ] ) && $array[ $key ]; } /** * Gets the value for a given key from an array, or a default value if the key doesn't exist in the array. * * @param array $array The array to get the value from. * @param string $key The key to use to retrieve the value. * @param null $default The default value to return if the key doesn't exist in the array. * @return mixed|null The value for the key, or the default value passed. */ public static function get_value_or_default( array $array, string $key, $default = null ) { return isset( $array[ $key ] ) ? $array[ $key ] : $default; } } StringUtil.php 0000644 00000003273 15133220005 0007355 0 ustar 00 <?php /** * A class of utilities for dealing with strings. */ namespace Automattic\WooCommerce\Utilities; /** * A class of utilities for dealing with strings. */ final class StringUtil { /** * Checks to see whether or not a string starts with another. * * @param string $string The string we want to check. * @param string $starts_with The string we're looking for at the start of $string. * @param bool $case_sensitive Indicates whether the comparison should be case-sensitive. * * @return bool True if the $string starts with $starts_with, false otherwise. */ public static function starts_with( string $string, string $starts_with, bool $case_sensitive = true ): bool { $len = strlen( $starts_with ); if ( $len > strlen( $string ) ) { return false; } $string = substr( $string, 0, $len ); if ( $case_sensitive ) { return strcmp( $string, $starts_with ) === 0; } return strcasecmp( $string, $starts_with ) === 0; } /** * Checks to see whether or not a string ends with another. * * @param string $string The string we want to check. * @param string $ends_with The string we're looking for at the end of $string. * @param bool $case_sensitive Indicates whether the comparison should be case-sensitive. * * @return bool True if the $string ends with $ends_with, false otherwise. */ public static function ends_with( string $string, string $ends_with, bool $case_sensitive = true ): bool { $len = strlen( $ends_with ); if ( $len > strlen( $string ) ) { return false; } $string = substr( $string, -$len ); if ( $case_sensitive ) { return strcmp( $string, $ends_with ) === 0; } return strcasecmp( $string, $ends_with ) === 0; } }
| ver. 1.4 |
Github
|
.
| PHP 8.2.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка