RegistrySource
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.
Methods
__construct()
final public function __construct()cloneResults()
public function cloneResults() : boolOverride this to return true if the registry members are mutable. Supersedes CloningRegistryTrait
getTargetClassDocComment()
public function getTargetClassDocComment() : arrayReturns information to be prepended to the doc comment on the generated class. Do not include any PHPDoc formatting (e.g. comment tags) in here.
getTargetClassName()
abstract public function getTargetClassName() : stringReturns the short name (without namespace) of the class to be generated. The generated class will have the same namespace as your source class.
preprocessMember()
public static function preprocessMember(object $member) : objectOverride this if you need to, for example, clone a registry member before returning it to the caller
registerDelayed() protected
final protected function registerDelayed(string $name, \Closure $valueFactory) : voidAdds 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.
registerValue() protected
final protected function registerValue(string $name, mixed $value) : mixedAdds 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.
setup() protected
abstract protected function setup() : voidImplement this to add members to the registry.
