Utils
Big collection of functions
Constants
OS_ANDROID
public const OS_ANDROID = "android"OS_BSD
public const OS_BSD = "bsd"OS_IOS
public const OS_IOS = "ios"OS_LINUX
public const OS_LINUX = "linux"OS_MACOS
public const OS_MACOS = "mac"OS_UNKNOWN
public const OS_UNKNOWN = "other"OS_WINDOWS
public const OS_WINDOWS = "win"Methods
assumeNotFalse()
public static function assumeNotFalse(mixed $value, \Closure|string $context = "This should never be false") : mixedcheckFloatNotInfOrNaN()
public static function checkFloatNotInfOrNaN(string $name, float $float) : voidcheckLocationNotInfOrNaN()
public static function checkLocationNotInfOrNaN(\pocketmine\entity\Location $location) : voidcheckUTF8()
public static function checkUTF8(string $string) : voidcheckVector3NotInfOrNaN()
public static function checkVector3NotInfOrNaN(\pocketmine\math\Vector3 $vector3) : voidcloneCallback()
public static function cloneCallback() : \ClosureDeprecated
Deprecated.
cloneObjectArray()
public static function cloneObjectArray(array $array) : arraycurrentTrace()
public static function currentTrace(int $skipFrames = 0) : arraygetCoreCount()
public static function getCoreCount(bool $recalculate = false) : intgetMachineUniqueId()
public static function getMachineUniqueId(string $extra = "") : \Ramsey\Uuid\UuidInterfaceGets this machine / server instance unique ID Returns a hash, the first 32 characters (or 16 if raw) will be an identifier that won't change frequently. The rest of the hash will change depending on other factors.
getNiceClassName()
public static function getNiceClassName(object $obj) : stringReturns a readable identifier for the class of the given object. Sanitizes class names for anonymous classes.
getNiceClosureName()
public static function getNiceClosureName(\Closure $closure) : stringReturns a readable identifier for the given Closure, including file and line.
getOS()
public static function getOS(bool $recalculate = false) : stringgetOpcacheJitMode()
public static function getOpcacheJitMode() : ?intReturns an integer describing the current OPcache JIT setting.
getRandomFloat()
public static function getRandomFloat() : floatReturns a random float between 0.0 and 1.0 Drop-in replacement for lcg_value()
getReferenceCount()
public static function getReferenceCount(object $value, bool $includeCurrent = true) : inthexdump()
public static function hexdump(string $bin) : stringReturns a prettified hexdump
javaStringHash()
public static function javaStringHash(string $string) : intparseDocComment()
public static function parseDocComment(string $docComment) : arrayExtracts one-line tags from the doc-comment
printable()
public static function printable(mixed $str) : stringReturns a string that can be printed, replaces non-printable characters
printableCurrentTrace()
public static function printableCurrentTrace(int $skipFrames = 0) : arrayprintableExceptionInfo()
public static function printableExceptionInfo(\Throwable $e, $trace = null) : arrayprintableTrace()
public static function printableTrace(array $trace, int $maxStringLength = 80) : arrayprintableTraceWithMetadata()
public static function printableTraceWithMetadata(array $rawTrace, int $maxStringLength = 80) : arraySimilar to Utils::printableTrace(), but associates metadata such as file and line number with each frame. This is used to transmit thread-safe information about crash traces to the main thread when a thread crashes.
promoteKeys()
public static function promoteKeys(array $array) : arrayGets rid of PHPStan BenevolentUnionType on array keys, so that wrong type errors get reported properly Use this if you don't care what the key type is and just want proper PHPStan error reporting
stringifyKeys()
public static function stringifyKeys(array $array) : \GeneratorGenerator which forces array keys to string during iteration. This is necessary because PHP has an anti-feature where it casts numeric string keys to integers, leading to various crashes.
testValidInstance()
public static function testValidInstance(string $className, string $baseName) : voidvalidateArrayValueType()
public static function validateArrayValueType(array $array, \Closure $validator) : voidvalidateCallableSignature()
public static function validateCallableSignature(callable|\DaveRandom\CallbackValidator\CallbackType $signature, callable $subject) : voidVerifies that the given callable is compatible with the desired signature. Throws a TypeError if they are incompatible.
