You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spiral provides an efficient way to bootstrap applications, allowing developers to register container bindings and configure applications effectively. However, this process can be further enhanced by introducing PHP attributes for the bootloader methods.
Motivation
Currently, Spiral utilizes methods such as defineBindings, defineSingletons, init, and boot for container bindings and application configuration. While this approach is functional, PHP attributes can make the process more intuitive and less verbose, improving readability and maintainability.
Proposed PHP Attributes
InitMethod: Used to mark methods that are involved in the initialization process.
BootMethod: Used to mark methods that are part of the bootstrapping sequence.
SingletonMethod: Used to define singleton services within the application.
BindMethod: Used for binding services in the container.
Purpose: This attribute designates methods that are part of the application's bootstrapping process.
Example:
#[BootMethod]
publicfunctionprepareServices(SomeService$service): void
{
// Perform actions necessary to prepare the service for use$service->initialize();
$service->loadData();
$service->boot();
}
#[BootMethod]
publicfunctionsomeService(): void
{
// Perform actions necessary to prepare the service for use ...
}
3. SingletonMethod Attribute
Purpose: Used to define singleton services within the application, ensuring only one instance exists.
In summary, these attributes (InitMethod, BootMethod, SingletonMethod, BindMethod) aim to simplify and clarify the definition of methods within the Spiral Framework's bootloader, enhancing readability and maintainability. Each attribute plays a distinct role in organizing the bootstrapping and initialization process of the application.
The text was updated successfully, but these errors were encountered:
Spiral provides an efficient way to bootstrap applications, allowing developers to register container bindings and configure applications effectively. However, this process can be further enhanced by introducing PHP attributes for the bootloader methods.
Motivation
Currently, Spiral utilizes methods such as
defineBindings
,defineSingletons
,init
, andboot
for container bindings and application configuration. While this approach is functional, PHP attributes can make the process more intuitive and less verbose, improving readability and maintainability.Proposed PHP Attributes
Examples of Usage
1.
InitMethod
AttributeCurrent approach
Purpose: This attribute is used to mark methods that are involved in the initialization process of the application.
Example:
2.
BootMethod
AttributeCurrent approach
Purpose: This attribute designates methods that are part of the application's bootstrapping process.
Example:
3.
SingletonMethod
AttributePurpose: Used to define singleton services within the application, ensuring only one instance exists.
Example:
4.
BindMethod
AttributePurpose: Used for defining methods that bind services or implementations to interfaces in the dependency injection container.
Example:
In summary, these attributes (
InitMethod
,BootMethod
,SingletonMethod
,BindMethod
) aim to simplify and clarify the definition of methods within the Spiral Framework's bootloader, enhancing readability and maintainability. Each attribute plays a distinct role in organizing the bootstrapping and initialization process of the application.The text was updated successfully, but these errors were encountered: