Add regex routing support with constraints and shortcuts#5
Conversation
- Introduced regex-based route constraints in the routing system. - Added support for inline constraints, constraint shortcuts, and full regex patterns. - Implemented built-in shortcuts for common patterns (e.g., int, slug, uuid). - Enhanced RouteCache to compile patterns with regex constraints and validate them for security. - Added tests for various routing scenarios, including backward compatibility and performance. - Documented the new regex routing feature in a dedicated markdown file.
…rões e parâmetros
…pondentes em rotas
…dicionar guias de implementação
…elhorar a validação de rotas
…alidações adicionais
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…es na documentação
…elds
- Update regex pattern to process each {} block individually (non-greedy)
- Fix RouteCache::warmup() to use consistent field names (pattern instead of compiled_pattern)
- Add has_parameters field to cached routes for proper dynamic route identification
- Add comprehensive tests for non-greedy regex behavior
- Improve anchor removal logic to preserve functional $ anchors
…tps://github.com/HelixPHP/helixphp-core into 1-feature-rfc-regex-routing-support-for-pivotphp
- Extract cache retrieval logic into getFromCache() - Create isStaticPath() for static route detection - Split regex block processing into processRegexBlocks() and processRegexBlock() - Extract anchor removal logic into removeRegexAnchors() - Create countCaptureGroups() for capture group counting - Split parameter registration into registerAnonymousParameters() - Extract named parameter processing into processNamedParameters() and processNamedParameter() - Create finalizePattern() for pattern finalization - Extract dot escaping into escapeDots() - Split caching logic into cacheStaticRoute() and cacheDynamicRoute() This refactoring improves code readability, testability, and maintainability while maintaining all existing functionality and performance characteristics.
…ation - Introduced advanced route validation using regex in the routing system. - Added shortcuts for common regex patterns (int, slug, uuid, date, etc.). - Updated documentation to include examples of regex constraints and best practices. - Improved performance metrics and benchmarks in the release notes. - Created a new release overview for v1.0.1 highlighting new features and improvements. - Updated performance analysis and report to reflect the latest optimizations. - Enhanced unit tests for routing to ensure integrity and correctness of regex patterns.
…mizar identificação de rotas
There was a problem hiding this comment.
Pull Request Overview
This PR adds full regex routing support by extending the routing system with inline constraints, full-regex blocks, and predefined shortcuts, while ensuring security against ReDoS. It updates the Router and RouteCache implementations, adds extensive unit and integration tests, and refreshes documentation and validation scripts.
Reviewed Changes
Copilot reviewed 33 out of 36 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Routing/Router.php | Precompiles route patterns and delegates matching to unified methods |
| src/Routing/RouteCache.php | Refactors compilePattern into helper methods with safety checks |
| tests/Unit/Routing/*.php | New tests covering pattern compilation, matching, and safety |
| tests/Integration/Routing/*.php | Integration tests for end-to-end regex routing scenarios |
| docs/technical/routing/router.md | Documents new constraint and regex-block syntax |
| scripts/validate_*.{php,sh} | Updates to reflect renamed documentation paths |
| CHANGELOG.md | Adds new v1.0.1 entry for regex routing feature |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…gex e criar suíte de testes dedicada
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the routing system by introducing full regex support—including inline constraints, predefined shortcuts, and brace-delimited regex blocks—and ensures safe, cached compilation. It updates the router to store compiled patterns and parameters, adds extensive tests for correctness, and documents the new features.
- Introduce regex-based constraints (
:param<…>) and full regex blocks ({^…$}) inRouteCache::compilePattern. - Refactor
Router::addand matching logic to include compiled patterns, parameter metadata, and ReDoS protection. - Add comprehensive unit and integration tests and update documentation/scripts to reflect directory renames and feature additions.
Reviewed Changes
Copilot reviewed 34 out of 37 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Routing/Router.php | Integrated pattern compilation into route registration and optimized matching logic |
| src/Routing/RouteCache.php | Implemented regex block processing, parameter constraints, safety checks, and caching |
| tests/Unit/Routing/RouteCacheRegexTest.php | New unit tests covering regex constraints, shortcuts, and security protections |
| tests/Integration/Routing/RegexRoutingIntegrationTest.php | Integration tests for end-to-end regex routing scenarios |
| docs/regex-routing.md | User guide for regex-based routing, constraints, and best practices |
| scripts/validate_project.php | Updated validation logic for renamed directories and removed benchmarks |
Comments suppressed due to low confidence (1)
src/Routing/Router.php:392
InvalidArgumentExceptionis referenced without a leading backslash or an import, causing a potentialClassNotFoundException. Either prefix it with\or adduse InvalidArgumentException;at the top.
throw new InvalidArgumentException("Invalid regex pattern: $pattern");
Pull Request Template
📋 Descrição
Descreva resumidamente as mudanças feitas neste PR.
🎯 Tipo de Mudança
🧪 Como foi testado?
Descreva os testes que você executou para verificar suas mudanças.
📝 Checklist
🔗 Issues Relacionadas
Fixes #1