PocketMine-MP 5.39.1 git-1be3f83620f013523bb4d35535c6c0f842b54a6a
Loading...
Searching...
No Matches
pocketmine\utils\RegistrySource Class Reference
+ Inheritance diagram for pocketmine\utils\RegistrySource:
+ Collaboration diagram for pocketmine\utils\RegistrySource:

Public Member Functions

 getAllDeclarations ()
 
 getAllValues ()
 
 getTargetClassDocComment ()
 
 getTargetClassName ()
 

Static Public Member Functions

static preprocessMember (object $member)
 

Protected Member Functions

 registerDelayed (string $name, \Closure $valueFactory)
 
 registerValue (string $name, mixed $value)
 
 setup ()
 

Detailed Description

Extend this class to define source values for a generated registry class. A registry class has generated functions that simulate object constants.

The values are defined in the self::setup() function. The generated class's name is defined in self::getTargetClassName(). The generated class will belong to the same namespace as your source class.

The generated class will call your source class at runtime, so both the source and generated class must be included in the build.

To create a registry, simply extend this class and implement the abstract methods. Then, run the registry-interface.php script in the build folder to generate the accessor class.

This supersedes the older RegistryTrait, which is slower and less robust than this newer approach, and also required patching source classes. This approach allows the generated code to be fully separate from the source code.

See also
build/codegen/registry-interface.php

@phpstan-template TMember of object

Definition at line 51 of file RegistrySource.php.

Constructor & Destructor Documentation

◆ __construct()

pocketmine\utils\RegistrySource::__construct ( )
final

Definition at line 67 of file RegistrySource.php.

Member Function Documentation

◆ getAllDeclarations()

pocketmine\utils\RegistrySource::getAllDeclarations ( )
final

Definition at line 179 of file RegistrySource.php.

◆ getAllValues()

pocketmine\utils\RegistrySource::getAllValues ( )
final

Definition at line 165 of file RegistrySource.php.

◆ getTargetClassDocComment()

pocketmine\utils\RegistrySource::getTargetClassDocComment ( )

Returns information to be prepended to the doc comment on the generated class. Do not include any PHPDoc formatting (e.g. comment tags) in here.

Returns
string[] @phpstan-return list<string>

Reimplemented in pocketmine\block\VanillaBlocksInputs, pocketmine\entity\effect\VanillaEffectsInputs, pocketmine\item\enchantment\VanillaEnchantmentsInputs, pocketmine\item\VanillaArmorMaterialsInputs, and pocketmine\item\VanillaItemsInputs.

Definition at line 84 of file RegistrySource.php.

◆ getTargetClassName()

pocketmine\utils\RegistrySource::getTargetClassName ( )
abstract

Returns the short name (without namespace) of the class to be generated. The generated class will have the same namespace as your source class.

Reimplemented in pocketmine\block\VanillaBlocksInputs, pocketmine\entity\effect\VanillaEffectsInputs, pocketmine\item\enchantment\VanillaEnchantmentsInputs, pocketmine\item\VanillaArmorMaterialsInputs, and pocketmine\item\VanillaItemsInputs.

◆ preprocessMember()

static pocketmine\utils\RegistrySource::preprocessMember ( object $member)
static

Override this if you need to, for example, clone a registry member before returning it to the caller

@phpstan-template TParam of object

@phpstan-param TParam $member @phpstan-return TParam

Definition at line 119 of file RegistrySource.php.

◆ registerDelayed()

pocketmine\utils\RegistrySource::registerDelayed ( string $name,
\Closure $valueFactory )
finalprotected

Adds a value using a callback, which will be invoked when the registry is first accessed at runtime. The type of the generated registry function will be the same as that of the provided closure.

Use this if the value's initialization depends on generated registry code (i.e. it accesses another registry member, either in this registry or another).

Note: A return type MUST be set on the provided closure, or an error will be thrown.

@phpstan-param \Closure(string $name) : TMember $valueFactory

Definition at line 151 of file RegistrySource.php.

◆ registerValue()

pocketmine\utils\RegistrySource::registerValue ( string $name,
mixed $value )
finalprotected

Adds a plain value to the registry source. You can use this if the value does not depend on any other generated registry code. The type of the generated registry function will be inferred from the value provided.

@phpstan-param TMember $value @phpstan-return TMember

Definition at line 131 of file RegistrySource.php.

◆ setup()

pocketmine\utils\RegistrySource::setup ( )
abstractprotected

Implement this to add members to the registry.

See also
self::registerValue() for simple values which do not depend on any other registry members
self::registerDelayed() for values which depend on other registry members, either in this registry or another

Reimplemented in pocketmine\block\VanillaBlocksInputs, pocketmine\entity\effect\VanillaEffectsInputs, pocketmine\item\enchantment\VanillaEnchantmentsInputs, pocketmine\item\VanillaArmorMaterialsInputs, and pocketmine\item\VanillaItemsInputs.


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