Skip to content

Commit

Permalink
Merge pull request #17 from preprocess/contrib-master
Browse files Browse the repository at this point in the history
Improve encoding in deferred execution
  • Loading branch information
assertchris authored Jan 20, 2019
2 parents 860c244 + 0697c8d commit 1e03681
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions source/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public function parse($code)
{
$code = $this->getCodeWithMacros($code);
$code = $this->getCodeWithCompilers($code);
$code = base64_encode($code);
$code = base64_encode(gzencode($code));

return defer("
\$code = base64_decode('{$code}');
\$code = gzdecode(base64_decode('{$code}'));
\$engine = new \Yay\Engine;
gc_disable();
Expand All @@ -151,7 +151,7 @@ private function getCodeWithCompilers($code)
$this->getCompilers(),
$this->getDiscoveredCompilers()
);

foreach ($compilers as $compiler) {
if (is_callable($compiler)) {
$code = $compiler($code);
Expand All @@ -167,7 +167,7 @@ private function getCodeWithMacros($code)
$this->getMacros(),
$this->getDiscoveredMacros()
);

foreach ($macros as $macro) {
if (file_exists($macro)) {
$code = str_replace(
Expand Down
4 changes: 2 additions & 2 deletions source/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ function defer($code) {
{$code};
};
print base64_encode(serialize(\$function()));
print base64_encode(gzencode(\$function()));
";

$result = exec(
"php -r 'eval(base64_decode(\"" . base64_encode($defer) . "\"));'"
);

return unserialize(base64_decode($result));
return gzdecode(base64_decode($result));
}
}

Expand Down

0 comments on commit 1e03681

Please sign in to comment.