Harden template rendering and improve cache behavior - #7
Open
beobles wants to merge 2 commits into
Open
Conversation
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.
Motivation
Description
templates_dirinresolveTemplatePath, and make the cache key sensitive tofilemtime/filesizeviagenerateCacheKey.evaluateExpressionandisTruthy(dot-path lookup,??, filters, truthiness), and adaptCompilerto emit calls to these evaluators instead of raw PHP.ElseNode/EndNodeand emit balanced PHP blocks forIf/Foreachwith validation of foreach variable names in theCompiler.FileCacheAdapterto use SHA-256 keyed.cachefiles, store serialized entries withexpires_at, perform atomic writes to a temp file withLOCK_EXandrename, useunserialize(..., ['allowed_classes'=>false]), and restrictclear()to.cachefiles.Renderer::renderby running compiled code in an anonymous function with local extracted data and catchThrowablewhile preserving output buffering.uppercase/lowercaseusemb_*when available) and makereversebehave sensibly for strings and arrays.Testing
php -l $(rg --files -g '*.php')was run and returned no syntax errors. (passed)rm -rf cache && php examples/index.php > /tmp/rendered.htmland verified expected output tokensJOÃO SILVA,#0: Maria,#2: Ana. (passed)../index.phpagainstexamples/templates, which produced the expected "Template path is outside templates directory" error. (expected behavior)FileCacheAdapterTTL/clear behavior with a small program that created a temp cache, wrote/read entries with TTL, verified expiry and infinite TTL behavior, and confirmedcache-okon success. (passed)Codex Task