Skip to content

Conversation

@huangdijia
Copy link
Contributor

Summary

  • Add getGlobalEventProcessors() static method to Scope class
  • Enables testing and introspection of registered global event processors
  • Refactors applyToEvent() to use the new getter method for consistency

Changes

  • src/State/Scope.php:
    • New public static method getGlobalEventProcessors() that returns the array of global event processors
    • Updated applyToEvent() to call self::getGlobalEventProcessors() instead of directly accessing self::$globalEventProcessors

Motivation

This change provides a public API for accessing the global event processors, which is useful for:

  • Testing framework integrations that register global processors
  • Debugging and introspection of registered processors
  • Future enhancements that may need to enumerate or inspect processors

Test plan

  • Code follows existing coding standards
  • Unit tests added/updated (if applicable)
  • No breaking changes to public API

Add a public getter method for global event processors to enable
testing and introspection of registered processors.
Copilot AI review requested due to automatic review settings December 24, 2025 01:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a public getter method getGlobalEventProcessors() to the Scope class to enable testing and introspection of registered global event processors. The change also refactors the applyToEvent() method to use this new getter for consistency.

Key Changes:

  • Added public static method getGlobalEventProcessors() that returns the array of global event processors
  • Refactored applyToEvent() to use the new getter method instead of directly accessing the static property

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 362 to 370
/**
* Get the global event processors {@see Scope::applyToEvent}.
*/
public static function getGlobalEventProcessors(): array
{
return self::$globalEventProcessors;
}

/**
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type annotation is incomplete. The method should include a psalm-var annotation to match the type annotation on the property definition (lines 91-93). This is important for static analysis tools to understand that the returned array contains callables with a specific signature.

Consider adding the psalm annotation:
@psalm-return array<callable(Event, EventHint): ?Event>

Copilot uses AI. Check for mistakes.
Comment on lines +367 to 370
return self::$globalEventProcessors;
}

/**
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new public method getGlobalEventProcessors() lacks test coverage. Since this codebase has comprehensive test coverage for the Scope class (as seen in tests/State/ScopeTest.php), this new public API should include tests to verify it returns the correct array of global event processors, especially after calling addGlobalEventProcessor().

Copilot uses AI. Check for mistakes.
@huangdijia
Copy link
Contributor Author

Additional note for long-lived framework environments:

In long-running, persistent frameworks (such as Swoole, RoadRunner, or similar setups), it is possible to leverage AOP at appropriate lifecycle boundaries (e.g. request start/end, coroutine creation) to capture a snapshot of $globalEventProcessors and store it in a request- or coroutine-scoped Context.

This approach provides several benefits:

  • Prevents unintended cross-request or cross-coroutine state sharing caused by global static data
  • Allows safe, request-level inspection, debugging, or assertions of the active global event processors
  • Gives framework integrators a clearer lifecycle boundary without directly relying on static properties

Exposing getGlobalEventProcessors() as a read-only accessor enables this Context-based management pattern while preserving existing behavior and event processing flow.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant