PocketMine-MP 5.15.1 git-be6754494fdbbb9dd57c058ba0e33a4a78c4581f
pocketmine\utils\Utils Class Reference
+ Collaboration diagram for pocketmine\utils\Utils:

Static Public Member Functions

static assumeNotFalse (mixed $value, \Closure|string $context="This should never be false")
 
static checkFloatNotInfOrNaN (string $name, float $float)
 
static checkLocationNotInfOrNaN (Location $location)
 
static checkUTF8 (string $string)
 
static checkVector3NotInfOrNaN (Vector3 $vector3)
 
static cloneCallback ()
 
static cloneObjectArray (array $array)
 
static currentTrace (int $skipFrames=0)
 
static getCoreCount (bool $recalculate=false)
 
static getMachineUniqueId (string $extra="")
 
static getNiceClassName (object $obj)
 
static getNiceClosureName (\Closure $closure)
 
static getOpcacheJitMode ()
 
static getOS (bool $recalculate=false)
 
static getReferenceCount (object $value, bool $includeCurrent=true)
 
static hexdump (string $bin)
 
static javaStringHash (string $string)
 
static parseDocComment (string $docComment)
 
static printable (mixed $str)
 
static printableCurrentTrace (int $skipFrames=0)
 
static printableExceptionInfo (\Throwable $e, $trace=null)
 
static printableTrace (array $trace, int $maxStringLength=80)
 
static printableTraceWithMetadata (array $rawTrace, int $maxStringLength=80)
 
static stringifyKeys (array $array)
 
static testValidInstance (string $className, string $baseName)
 
static validateArrayValueType (array $array, \Closure $validator)
 
static validateCallableSignature (callable|CallbackType $signature, callable $subject)
 

Public Attributes

const OS_ANDROID = "android"
 
const OS_BSD = "bsd"
 
const OS_IOS = "ios"
 
const OS_LINUX = "linux"
 
const OS_MACOS = "mac"
 
const OS_UNKNOWN = "other"
 
const OS_WINDOWS = "win"
 

Detailed Description

Big collection of functions

Definition at line 103 of file Utils.php.

Member Function Documentation

◆ assumeNotFalse()

static pocketmine\utils\Utils::assumeNotFalse ( mixed  $value,
\Closure|string  $context = "This should never be false" 
)
static

@phpstan-template TValue @phpstan-param TValue|false $value @phpstan-param string|\Closure() : string $context @phpstan-return TValue

Definition at line 623 of file Utils.php.

Referenced by pocketmine\resourcepacks\ZippedResourcePack\__construct(), and pocketmine\command\defaults\TimingsCommand\execute().

+ Here is the caller graph for this function:

◆ checkFloatNotInfOrNaN()

static pocketmine\utils\Utils::checkFloatNotInfOrNaN ( string  $name,
float  $float 
)
static

Definition at line 630 of file Utils.php.

◆ checkLocationNotInfOrNaN()

static pocketmine\utils\Utils::checkLocationNotInfOrNaN ( Location  $location)
static

Definition at line 649 of file Utils.php.

◆ checkUTF8()

static pocketmine\utils\Utils::checkUTF8 ( string  $string)
static

Definition at line 611 of file Utils.php.

◆ checkVector3NotInfOrNaN()

static pocketmine\utils\Utils::checkVector3NotInfOrNaN ( Vector3  $vector3)
static

Definition at line 639 of file Utils.php.

◆ cloneCallback()

static pocketmine\utils\Utils::cloneCallback ( )
static

@phpstan-return \Closure(object) : object

Definition at line 169 of file Utils.php.

◆ cloneObjectArray()

static pocketmine\utils\Utils::cloneObjectArray ( array  $array)
static

@phpstan-template TKey of array-key @phpstan-template TValue of object

Parameters
object[]$array@phpstan-param array<TKey, TValue> $array
Returns
object[] @phpstan-return array<TKey, TValue>

Definition at line 185 of file Utils.php.

Referenced by pocketmine\crafting\ShapelessRecipe\__construct(), and pocketmine\crafting\ShapedRecipe\__construct().

+ Here is the caller graph for this function:

◆ currentTrace()

static pocketmine\utils\Utils::currentTrace ( int  $skipFrames = 0)
static
Returns
mixed[][] @phpstan-return list<array<string, mixed>>

Definition at line 502 of file Utils.php.

◆ getCoreCount()

static pocketmine\utils\Utils::getCoreCount ( bool  $recalculate = false)
static

Definition at line 302 of file Utils.php.

◆ getMachineUniqueId()

static pocketmine\utils\Utils::getMachineUniqueId ( string  $extra = "")
static

Gets 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.

Parameters
string$extraoptional, additional data to identify the machine

Definition at line 199 of file Utils.php.

Referenced by pocketmine\stats\SendUsageTask\__construct().

+ Here is the caller graph for this function:

◆ getNiceClassName()

static pocketmine\utils\Utils::getNiceClassName ( object  $obj)
static

Returns a readable identifier for the class of the given object. Sanitizes class names for anonymous classes.

Exceptions

ReflectionException

Definition at line 152 of file Utils.php.

◆ getNiceClosureName()

static pocketmine\utils\Utils::getNiceClosureName ( \Closure  $closure)
static

Returns a readable identifier for the given Closure, including file and line.

@phpstan-param anyClosure $closure

Exceptions

ReflectionException

Definition at line 122 of file Utils.php.

◆ getOpcacheJitMode()

static pocketmine\utils\Utils::getOpcacheJitMode ( )
static

Returns an integer describing the current OPcache JIT setting.

See also
https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit

Definition at line 657 of file Utils.php.

Referenced by pocketmine\command\defaults\VersionCommand\execute().

+ Here is the caller graph for this function:

◆ getOS()

static pocketmine\utils\Utils::getOS ( bool  $recalculate = false)
static

Returns the current Operating System Windows => win MacOS => mac iOS => ios Android => android Linux => Linux BSD => bsd Other => other

Definition at line 275 of file Utils.php.

Referenced by pocketmine\stats\SendUsageTask\__construct(), pocketmine\command\defaults\VersionCommand\execute(), and pocketmine\utils\Process\getAdvancedMemoryUsage().

+ Here is the caller graph for this function:

◆ getReferenceCount()

static pocketmine\utils\Utils::getReferenceCount ( object  $value,
bool  $includeCurrent = true 
)
static

Definition at line 373 of file Utils.php.

◆ hexdump()

static pocketmine\utils\Utils::hexdump ( string  $bin)
static

Returns a prettified hexdump

Definition at line 337 of file Utils.php.

◆ javaStringHash()

static pocketmine\utils\Utils::javaStringHash ( string  $string)
static

Definition at line 360 of file Utils.php.

◆ parseDocComment()

static pocketmine\utils\Utils::parseDocComment ( string  $docComment)
static

Extracts one-line tags from the doc-comment

Returns
string[] an array of tagName => tag value. If the tag has no value, an empty string is used as the value.

Definition at line 528 of file Utils.php.

◆ printable()

static pocketmine\utils\Utils::printable ( mixed  $str)
static

Returns a string that can be printed, replaces non-printable characters

Definition at line 352 of file Utils.php.

◆ printableCurrentTrace()

static pocketmine\utils\Utils::printableCurrentTrace ( int  $skipFrames = 0)
static
Returns
string[]

Definition at line 519 of file Utils.php.

◆ printableExceptionInfo()

static pocketmine\utils\Utils::printableExceptionInfo ( \Throwable  $e,
  $trace = null 
)
static
Parameters
mixed[]$trace
Returns
string[]

Definition at line 409 of file Utils.php.

◆ printableTrace()

static pocketmine\utils\Utils::printableTrace ( array  $trace,
int  $maxStringLength = 80 
)
static
Parameters
mixed[][]$trace@phpstan-param list<array<string, mixed>> $trace
Returns
string[]

Definition at line 449 of file Utils.php.

◆ printableTraceWithMetadata()

static pocketmine\utils\Utils::printableTraceWithMetadata ( array  $rawTrace,
int  $maxStringLength = 80 
)
static

Similar 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.

Parameters
mixed[][]$rawTrace@phpstan-param list<array<string, mixed>> $rawTrace
Returns
ThreadCrashInfoFrame[]

Definition at line 483 of file Utils.php.

◆ stringifyKeys()

static pocketmine\utils\Utils::stringifyKeys ( array  $array)
static

Generator 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.

@phpstan-template TKeyType of string @phpstan-template TValueType @phpstan-param array<TKeyType, TValueType> $array @phpstan-return \Generator<TKeyType, TValueType, void, void>

Definition at line 605 of file Utils.php.

Referenced by pocketmine\data\bedrock\item\upgrade\R12ItemIdToBlockIdMap\__construct(), pocketmine\data\bedrock\ItemTagToIdMap\__construct(), and pocketmine\network\mcpe\convert\BlockStateDictionary\__construct().

+ Here is the caller graph for this function:

◆ testValidInstance()

static pocketmine\utils\Utils::testValidInstance ( string  $className,
string  $baseName 
)
static

@phpstan-param class-string $className @phpstan-param class-string $baseName

Definition at line 539 of file Utils.php.

Referenced by pocketmine\block\BlockIdentifier\__construct(), pocketmine\entity\EntityFactory\register(), and pocketmine\block\tile\TileFactory\register().

+ Here is the caller graph for this function:

◆ validateArrayValueType()

static pocketmine\utils\Utils::validateArrayValueType ( array  $array,
\Closure  $validator 
)
static

@phpstan-template TMemberType @phpstan-param array<mixed, TMemberType> $array @phpstan-param \Closure(TMemberType) : void $validator

Definition at line 585 of file Utils.php.

◆ validateCallableSignature()

static pocketmine\utils\Utils::validateCallableSignature ( callable|CallbackType  $signature,
callable  $subject 
)
static

Verifies that the given callable is compatible with the desired signature. Throws a TypeError if they are incompatible.

Parameters
callable | CallbackType$signatureDummy callable with the required parameters and return type
callable$subjectCallable to check the signature of @phpstan-param anyCallable|CallbackType $signature @phpstan-param anyCallable $subject
Exceptions

DaveRandom\CallbackValidator\InvalidCallbackException

Exceptions

TypeError

Definition at line 571 of file Utils.php.

Referenced by pocketmine\inventory\CallbackInventoryListener\__construct(), pocketmine\scheduler\ClosureTask\__construct(), pocketmine\item\enchantment\Enchantment\__construct(), and pocketmine\entity\EntityFactory\register().

+ Here is the caller graph for this function:

Member Data Documentation

◆ OS_ANDROID

const pocketmine\utils\Utils::OS_ANDROID = "android"

Definition at line 107 of file Utils.php.

◆ OS_BSD

const pocketmine\utils\Utils::OS_BSD = "bsd"

Definition at line 109 of file Utils.php.

◆ OS_IOS

const pocketmine\utils\Utils::OS_IOS = "ios"

Definition at line 105 of file Utils.php.

◆ OS_LINUX

const pocketmine\utils\Utils::OS_LINUX = "linux"

Definition at line 108 of file Utils.php.

◆ OS_MACOS

const pocketmine\utils\Utils::OS_MACOS = "mac"

Definition at line 106 of file Utils.php.

◆ OS_UNKNOWN

const pocketmine\utils\Utils::OS_UNKNOWN = "other"

Definition at line 110 of file Utils.php.

◆ OS_WINDOWS

const pocketmine\utils\Utils::OS_WINDOWS = "win"

Definition at line 104 of file Utils.php.


The documentation for this class was generated from the following file: