fix: improve templator component variable extraction and cache invalidation#505
Conversation
…dation
- Add support for variable extraction in components using {{ }} syntax
- Implement dependency-aware cache invalidation to recompile templates when components change
- Enhance parameter parsing to support commas in strings and flexible whitespace
- Protect existing PHP blocks from being parsed by NameTemplator
- Support multiline comments and ensure they are processed first
- Introduce custom exceptions YieldSectionNotFound and RequiredVariableNotFound
- Add .dep file generation to track template dependencies (includes, components, etc.) - Implement automatic cache invalidation when any dependency is modified - Add `isFresh()` method to Templator for efficient stale cache detection - Introduce `$use_dep` parameter to `render()` and `compile()` for optional validation - Refactor `ViewCommand` to handle .dep files in `view:clear` and improve `watch` efficiency - Fix typos and logic in `Templator::prependDependency` - Update tests to ensure .dep files are properly managed and cleaned up - Fix PHPStan issues and exclude internal vendor directories from analysis
PR Documentation: Smart Dependency Tracking for TemplatorOverviewThis update introduces robust dependency tracking to solve the long-standing issue where changes to included files (headers, footers, components) don't trigger cache updates. The core philosophy: "Performance First, Smart Features as Opt-In." By default, the library remains as fast as raw PHP with intelligent invalidation available on demand. Key Features1. Dependency Mapping (.dep files)Every compiled template now generates a companion
2. Intelligent Cache InvalidationThe new 3. Refined API
Usage StrategiesDevelopment Mode// Option A: Reactive (Smart Check)
$templator->render('home', $data, cache: true, use_dep: true);
// Option B: Proactive (CLI Watcher)
// Terminal: php cli view:watch
$templator->render('home', $data, cache: true, use_dep: false);Production Mode// 1. Deployment: php cli view:cache
// 2. Runtime:
$templator->render('home', $data, cache: true, use_dep: false);CLI Enhancements
Performance
The Quality Standards✅ DRY principles (logic in |
This PR improves the Templator component by addressing several issues reported in #501: