static-constructors

Loader
in package

FinalYes

Singleton responsible for calling static constructors on classes that provide them.

Uses and to determine valid classes and methods.

Table of Contents

Constants

DEFAULT_CLASS_POLICIES  = [\NxtLvlSoftware\StaticConstructors\Policy\Class\SameNameAsClassPolicy::class, \NxtLvlSoftware\StaticConstructors\Policy\Class\PhpStyleConstructorPolicy::class]
The default class policies for finding static constructor methods.
DEFAULT_METHOD_POLICIES  = [\NxtLvlSoftware\StaticConstructors\Policy\Method\NoArgumentsMethodPolicy::class, \NxtLvlSoftware\StaticConstructors\Policy\Method\Visibility\PrivateVisibilityPolicy::class]
The default method policies for determining validity of static constructor candidate methods.

Properties

$classPolicies  : array<string|int, mixed>
$instance  : self|null
$methodPolicies  : array<string|int, mixed>
$proxiedLoaders  : array<int, callable(class-string): void>

Methods

autoload()  : void
Our custom autoload function. We loop over the registered loaders to load the class then call the static constructor on the class if it was loaded.
init()  : void
Start the loader if an instance does not already exist.
started()  : bool
Check if {@link \NxtLvlSoftware\StaticConstructors\Loader::init()} has been called.
__construct()  : mixed
The entry to static class constructors.
callStaticConstructor()  : void
Look for a suitable static constructor on a class and call it.
checkLoadedClasses()  : void
Check classes already declared in the runtime for static constructor methods and call them.
overrideSplLoaders()  : void
Store all the currently registered autoload functions and register this class as the primary autoloader.

Constants

DEFAULT_CLASS_POLICIES

The default class policies for finding static constructor methods.

public mixed DEFAULT_CLASS_POLICIES = [\NxtLvlSoftware\StaticConstructors\Policy\Class\SameNameAsClassPolicy::class, \NxtLvlSoftware\StaticConstructors\Policy\Class\PhpStyleConstructorPolicy::class]

DEFAULT_METHOD_POLICIES

The default method policies for determining validity of static constructor candidate methods.

public mixed DEFAULT_METHOD_POLICIES = [\NxtLvlSoftware\StaticConstructors\Policy\Method\NoArgumentsMethodPolicy::class, \NxtLvlSoftware\StaticConstructors\Policy\Method\Visibility\PrivateVisibilityPolicy::class]

Properties

$classPolicies read-only

private array<string|int, mixed> $classPolicies

$instance

private static self|null $instance = null

$methodPolicies read-only

private array<string|int, mixed> $methodPolicies

$proxiedLoaders

private array<int, callable(class-string): void> $proxiedLoaders = []

Methods

autoload()

Our custom autoload function. We loop over the registered loaders to load the class then call the static constructor on the class if it was loaded.

public autoload(class-string $className) : void
Parameters
$className : class-string

init()

Start the loader if an instance does not already exist.

public static init([array<int, StaticConstructorClassPolicy>$classPolicies = self::DEFAULT_CLASS_POLICIES ][, array<int, StaticConstructorMethodPolicy>$methodPolicies = self::DEFAULT_METHOD_POLICIES ][, bool $checkLoadedClasses = true ]) : void
Parameters
$classPolicies : array<int, StaticConstructorClassPolicy>> = self::DEFAULT_CLASS_POLICIES

Policy class names for determining if a class has a valid static constructor method defined.

$methodPolicies : array<int, StaticConstructorMethodPolicy>> = self::DEFAULT_METHOD_POLICIES

Policy class names for determining validity of candidate static constructor methods.

$checkLoadedClasses : bool = true

Should the loader check for a static constructor on classes that are already declared in the runtime?

started()

Check if {@link \NxtLvlSoftware\StaticConstructors\Loader::init()} has been called.

public static started() : bool
Return values
bool

__construct()

The entry to static class constructors.

private __construct(array<int, StaticConstructorClassPolicy>$classPolicies, array<int, StaticConstructorMethodPolicy>$methodPolicies, bool $checkLoadedClasses) : mixed

This class can only exist as a singleton so that we only override the existing autoloader's if this is the first instance constructed.

Parameters
$classPolicies : array<int, StaticConstructorClassPolicy>>
$methodPolicies : array<int, StaticConstructorMethodPolicy>>
$checkLoadedClasses : bool

callStaticConstructor()

Look for a suitable static constructor on a class and call it.

private callStaticConstructor(class-string $className) : void
Parameters
$className : class-string

checkLoadedClasses()

Check classes already declared in the runtime for static constructor methods and call them.

private checkLoadedClasses() : void

overrideSplLoaders()

Store all the currently registered autoload functions and register this class as the primary autoloader.

private overrideSplLoaders() : void

        
On this page

Search results