Refactor View Engine into modular pipeline with typed AST, directives, scoped runtime, and secure rendering#2
Draft
Copilot wants to merge 3 commits into
Draft
Conversation
Copilot
AI
changed the title
[WIP] Refactor architectural improvements for master view engine
Refactor View Engine into modular pipeline with typed AST, directives, scoped runtime, and secure rendering
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR reshapes the current View engine into a clearer, extensible architecture without changing the public usage model (
Engineorchestration and render flow). It introduces explicit boundaries across parse/compile/runtime concerns while adding safer rendering and stronger template semantics.Architecture split: Lexer → Parser → Compiler → Renderer
Enginenow orchestrates specialized modules instead of embedding parsing/compilation concerns.TemplateResolver,LayoutManager,TemplateValidator,MiddlewarePipeline,CacheKey, andFileWatcherto isolate core responsibilities.AST foundation and node hierarchy
AbstractNode+ upgradedNodeInterfaceto a compile-capable contract.TextNode,ExpressionNode,RawNode,ComponentNode,IfNode,ForeachNode,BlockNode,SetNode,IncludeNode.$node->compile(...)), enabling custom node extensibility.Directive system and parser validation
DirectiveRegistrywith directives forIf,Foreach,Block,Set,Include.Runtime scope, expressions, and filters
Scope,ScopeStack,Variable) and path resolution for dot notation.StringFilters,NumberFilters,DateFilters,ArrayFilters) viaFilterRegistry.Security and robustness
evalwith compiled-file include execution inRenderer.Escaper,HtmlEscaper,JavaScriptEscaper,UriEscaper).CompileException,RuntimeException,CircularReferenceException) and debug scaffolding (SourceMap,RuntimeContext,TemplateDebugger,ErrorFormatter).Docs alignment
README.mdto reflect the new modular layout.Original prompt
Refatoração Arquitetural - View Engine de Maestria
Seu PHP Template Engine tem uma base sólida, mas precisa de melhorias estruturais para ser um sistema robusto, extensível e profissional. Esta PR implementa as seguintes melhorias sem quebrar compatibilidade.
🎯 Objetivos
Separação de Responsabilidades Clara
Robustez & Segurança
Performance & Caching Inteligente
Extensibilidade
Developer Experience
📁 Nova Estrutura
🔧 Implementações Chave
1. AbstractNode (Base para todos os nós)
2. ScopeManager (Contexto de variáveis)
Gerencia escopo local/global com pilha de escopos
3. LayoutManager (Herança de templates)
Implementa
extendse<Block>corretamente4. DirectiveRegistry
Padrão Registry para directives customizadas
5. ContextAwareEscaper
Escape inteligente baseado em contexto (HTML, JS, CSS, URI)
6. SourceMap
Mapeia erro no código compilado para linha original
7. MiddlewarePipeline
Permite interceptação de requests/responses
📊 Benefíci...
This pull request was created from Copilot chat.