Skip to content

Commit 8041dd5

Browse files
committed
and more fixes to bring php 5.3 support
1 parent 533265c commit 8041dd5

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

Embed/RequestResolvers/Curl.php

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class Curl implements RequestResolverInterface
88
{
9+
protected $isBinary;
910
protected $content;
1011
protected $result;
1112
protected $url;
@@ -156,41 +157,13 @@ protected function resolve()
156157
));
157158

158159
$this->content = '';
159-
$isBinary = null;
160-
$binaryContentTypes = self::$binaryContentTypes;
160+
$this->isBinary = null;
161161

162-
curl_setopt($connection, CURLOPT_HEADERFUNCTION, function ($connection, $string) use (&$isBinary, $binaryContentTypes) {
163-
if (($isBinary === null) && strpos($string, ':')) {
164-
list($name, $value) = array_map('trim', explode(':', $string, 2));
165-
166-
if (strtolower($name) === 'content-type') {
167-
$isBinary = false;
168-
169-
foreach ($binaryContentTypes as $regex) {
170-
if (preg_match($regex, strtolower($value))) {
171-
$isBinary = true;
172-
break;
173-
}
174-
}
175-
}
176-
}
177-
178-
return strlen($string);
179-
});
180-
181-
$content &= $this->content;
182-
183-
curl_setopt($connection, CURLOPT_WRITEFUNCTION, function ($connection, $string) use (&$isBinary, &$content) {
184-
if ($isBinary) {
185-
return 0;
186-
}
187-
188-
$content .= $string;
189-
190-
return strlen($string);
191-
});
162+
curl_setopt($connection, CURLOPT_HEADERFUNCTION, array($this, 'headerCallback'));
163+
curl_setopt($connection, CURLOPT_WRITEFUNCTION, array($this, 'writeCallback'));
192164

193165
curl_exec($connection);
166+
194167
$this->result = curl_getinfo($connection);
195168

196169
if ($this->content === false) {
@@ -216,4 +189,33 @@ protected function resolve()
216189
}
217190
}
218191
}
192+
193+
protected function headerCallback ($connection, $string) {
194+
if (($this->isBinary === null) && strpos($string, ':')) {
195+
list($name, $value) = array_map('trim', explode(':', $string, 2));
196+
197+
if (strtolower($name) === 'content-type') {
198+
$this->isBinary = false;
199+
200+
foreach (self::$binaryContentTypes as $regex) {
201+
if (preg_match($regex, strtolower($value))) {
202+
$this->isBinary = true;
203+
break;
204+
}
205+
}
206+
}
207+
}
208+
209+
return strlen($string);
210+
}
211+
212+
protected function writeCallback ($connection, $string) {
213+
if ($this->isBinary) {
214+
return 0;
215+
}
216+
217+
$this->content .= $string;
218+
219+
return strlen($string);
220+
}
219221
}

0 commit comments

Comments
 (0)