Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deterministic function prefixes for FLAG_STANDALONEPHP #362

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

schuhwerk
Copy link

@schuhwerk schuhwerk commented Jul 27, 2022

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:

'funcprefix' => uniqid('lcr'),

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 issue Serialization 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant