Skip to content

Commit 1e03681

Browse files
authored
Merge pull request #17 from preprocess/contrib-master
Improve encoding in deferred execution
2 parents 860c244 + 0697c8d commit 1e03681

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

source/Parser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ public function parse($code)
131131
{
132132
$code = $this->getCodeWithMacros($code);
133133
$code = $this->getCodeWithCompilers($code);
134-
$code = base64_encode($code);
134+
$code = base64_encode(gzencode($code));
135135

136136
return defer("
137-
\$code = base64_decode('{$code}');
137+
\$code = gzdecode(base64_decode('{$code}'));
138138
\$engine = new \Yay\Engine;
139139
140140
gc_disable();
@@ -151,7 +151,7 @@ private function getCodeWithCompilers($code)
151151
$this->getCompilers(),
152152
$this->getDiscoveredCompilers()
153153
);
154-
154+
155155
foreach ($compilers as $compiler) {
156156
if (is_callable($compiler)) {
157157
$code = $compiler($code);
@@ -167,7 +167,7 @@ private function getCodeWithMacros($code)
167167
$this->getMacros(),
168168
$this->getDiscoveredMacros()
169169
);
170-
170+
171171
foreach ($macros as $macro) {
172172
if (file_exists($macro)) {
173173
$code = str_replace(

source/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ function defer($code) {
4848
{$code};
4949
};
5050
51-
print base64_encode(serialize(\$function()));
51+
print base64_encode(gzencode(\$function()));
5252
";
5353

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

58-
return unserialize(base64_decode($result));
58+
return gzdecode(base64_decode($result));
5959
}
6060
}
6161

0 commit comments

Comments
 (0)