Skip to content

Detect recursion in scheme extension - #944

Merged
giuscris merged 2 commits into
2.xfrom
bug/detect-scheme-extension-recursion
Aug 27, 2026
Merged

Detect recursion in scheme extension#944
giuscris merged 2 commits into
2.xfrom
bug/detect-scheme-extension-recursion

Conversation

@giuscris

Copy link
Copy Markdown
Member

This pull request improves the scheme extension mechanism in the Scheme class by adding recursion protection and allowing schemes to be extended by ID as well as by instance. The main changes focus on preventing infinite loops when schemes extend each other, directly or indirectly, and improving error handling.

Scheme extension improvements:

  • Added a static property self::$extending to track currently extending scheme IDs and detect recursion during extension, throwing a new RecursionException if a recursive extension is detected. [1] [2]
  • Updated the extend method to accept either a Scheme instance or a scheme ID (string), improving flexibility when extending schemes.
  • Modified the constructor to pass the scheme ID instead of the instance to the extend method, aligning with the new method signature.
  • Improved exception handling by throwing RecursionException when recursion is detected and updating docblocks to reflect new exception types. [1] [2]
  • Added the import for the new RecursionException class.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 hardens the Formwork\Schemes\Scheme extension mechanism by preventing recursive extension chains and by allowing extension to be triggered using either a Scheme instance or a scheme ID string.

Changes:

  • Added recursion protection for scheme extension via a static in-progress ID tracker and a new RecursionException.
  • Updated Scheme::extend() to accept Scheme|string and adjusted the constructor to pass the configured extend ID directly.
  • Updated docblocks/imports to reflect the new exception and signature changes.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread formwork/src/Schemes/Scheme.php
@giuscris
giuscris merged commit 79a4c76 into 2.x Aug 27, 2026
1 check passed
@giuscris
giuscris deleted the bug/detect-scheme-extension-recursion branch August 27, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants