feat: deterministic function prefixes for FLAG_STANDALONEPHP #362
+4
−4
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.
First of all: thank your for this great library!
To better illustrate my request, I'm adding this as a PR (instead of an issue). I'm not sure about all the implications (also regarding performance and compilation of partials), but I don't have any issues with my PR (feel free to decline, this is also meant for better understanding my issue).
I write parsed handlebars-code to a standalone php-file (FLAG_STANDALONEPHP) as you propose in my development-environment (on every page load). Every time the (same) file is rendered, different code is generated (only when FLAG_STANDALONEPHP is used). This causes lot's of changes (when those rendered files are tracked via git) even if nothing actually changed.
Looking at the diffs only the function-names are changing, because
uniqid
is used to prefix functions:lightncandy/src/Context.php
Line 143 in 2beab0f
Instead of using a
uniquid
we could base the function prefixes on the contents of the parsed template (hashed with md5?). This way the prefixes would be deterministic and the prefixes would only change if the contents of the source (handlebars-/mustache-) files change.Thanks!
Running the tests poses some issues, as the same templates are used multiple times (of course) and lead to
Fatal error: Cannot redeclare lcr31a8f7b63d1d5a1b9da615f756a3dbf0v()
. I tried--process-isolation
for phpunit, but that creates another issueSerialization of 'Closure' is not allowed
. Instead of digging deeper I'm looking forward to your thoughts on this.Edit: I made the funcprefix an option which falls back to
uniqid()
, so now there are no issues with the tests.