Enhance Hook package and boot pipeline to support bootstrap-time stage lifecycle events for optional integrations
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 42/100
Direzione di ricerca
Inizia da src/Hook/HookManager.php, src/Hook/Helpers/hook.php e dai relativi test unitari per comprendere il comportamento attuale di registrazione e dispatch. Poi esamina src/App/BootPipeline.php e gli stages elencati per tracciare l’esecuzione del bootstrap. Il lavoro è completo quando i listener durante il bootstrap e gli hook BEFORE/AFTER degli stages funzionano con payload denominati stabili, la compatibilità viene preservata ove necessario e i test e la documentazione pertinenti vengono aggiornati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Enhance the current Hook package and boot pipeline so optional integrations can subscribe to stage lifecycle events during bootstrap.
The goal is to support stage-owned BEFORE / AFTER hook points, allowing optional integrations such as debugbar to initialize at precise boot boundaries without being hardcoded into the core pipeline.
Why
The current Hook package is close to usable for this direction, but it still needs framework-level support for bootstrap-time stage events.
Current needs:
- optional integrations should be able to initialize during boot without hardcoded stages in core
- boot lifecycle points should be attached to meaningful stage boundaries
- the framework should not need special-purpose stages such as
InitDebuggerStagefor optional tooling - the current Hook mechanism should be strengthened rather than replaced
A better model is:
- each boot stage can define
BEFOREandAFTERhook names BootPipelinedispatches those hook points automatically around stage execution- optional integrations subscribe to the stage boundary they care about
For example, debugbar should be able to initialize at:
LoadModulesStage::BEFORE
instead of requiring a dedicated hardcoded debugger stage in core.
Goals
- keep the current Hook-style mechanism and evolve it
- make hook registration available during bootstrap
- allow boot stages to define
BEFORE/AFTERhook names - make
BootPipelinedispatch those hook points automatically - support optional integrations without hardcoded core dependencies
- keep the mechanism usable for user-defined application and module events, not only framework lifecycle hooks
Proposed Changes
- enhance the Hook package so listener registration is safe early in bootstrap
- introduce clearer API naming:
listen()instead ofon()dispatch()instead offire()
- keep
on()/fire()as compatibility aliases if needed - avoid positional payload arrays for framework-defined hook payloads and use stable named payloads
- allow boot stages to define lifecycle hook names such as
BEFOREandAFTER - update
BootPipelineto dispatch those hooks automatically around stage execution when present
Architectural Constraint
The mechanism introduced here must remain extensible for future event sources beyond boot stages, including:
- route-level events
- request/response events
- console lifecycle events
- user-defined business/domain events
Stage lifecycle hooks are the first concrete use case for this mechanism, but they must not lock the design into a stage-only event model.
Example Direction
Stage definition:
final class LoadModulesStage implements BootStageInterface
{
public const BEFORE = 'boot.modules.before';
public const AFTER = 'boot.modules.after';
public function process(AppContext $context): void
{
// existing stage logic
}
}
Pipeline behavior:
foreach ($this->stages as $stage) {
if (defined(get_class($stage) . '::BEFORE')) {
event()->dispatch($stage::BEFORE, [
'context' => $context,
]);
}
$stage->process($context);
if (defined(get_class($stage) . '::AFTER')) {
event()->dispatch($stage::AFTER, [
'context' => $context,
]);
}
}
Optional integration subscription:
event()->listen(LoadModulesStage::BEFORE, function (array $payload): void {
$context = $payload['context'];
debugbar()->boot($context);
});
Acceptance Criteria
- hook/event listener registration is safe during bootstrap
- boot stages can define
BEFORE/AFTERlifecycle hook names BootPipelinedispatches those lifecycle hooks automatically when defined- framework-defined hook payloads use stable named payloads rather than positional arrays
- clearer method names such as
listen()anddispatch()are introduced - existing
on()/fire()usage remains compatible if aliasing is chosen - optional integrations can subscribe to boot stage boundaries without hardcoded core stages
- the design remains extensible for non-stage framework events and user-defined business events
- tests cover bootstrap-time registration and stage lifecycle hook dispatch
- docs are updated as needed
Notes
Relevant code:
src/Hook/HookManager.phpsrc/Hook/Helpers/hook.phpsrc/App/BootPipeline.phpsrc/App/Stages/InitHttpStage.phpsrc/App/Stages/LoadModulesStage.phptests/Unit/Hook/HookManagerTest.phptests/Unit/Hook/Helpers/HookHelperTest.php
This ticket should be treated as the foundation for:
- lifecycle hooks
- debugbar via lifecycle hooks
- Lingua principale
- PHP
- Stelle
- 36
- Fork
- 22
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di quantum-php/framework
-
routing testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
quantum-php/framework#547 ·
-
view
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
quantum-php/framework#542 ·
-
enhancement http
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
quantum-php/framework#565 · 1 commento ·
-
components view
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
quantum-php/framework#551 ·
-
Add explicit @version special route token support for API major versioning within a single module Apertarouting
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
quantum-php/framework#550 ·
Tutte le issue di quantum-php/framework
Issue simili
-
sync-en
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
-
sync-en
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
-
Перевод устарел
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
-
[6.x]: "Cannot use object of type stdClass as array" loading Users index (regression of #19182) Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100