Skip to content

Commit 58fb2af

Browse files
author
Benjamin Wilson Friedman
authored
Adds HHVM Support (#342)
* testing hhvm support * Adds hhvm build * Added HHVM quirk fixes * lint!! * Tightened up comment
1 parent cbb6301 commit 58fb2af

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ php:
66
- '5.6'
77
- '7.0'
88
- '7.1'
9-
# - hhvm # on Trusty only
9+
- hhvm # on Trusty only
1010
# - nightly
1111

1212
cache:
@@ -18,6 +18,8 @@ matrix:
1818
include:
1919
- php: '5.6'
2020
env: STREAM_CLIENT_ONLY=1
21+
- php: hhvm
22+
env: STREAM_CLIENT_ONLY=1
2123

2224
before_install:
2325
- nvm install 6.11

src/Parse/HttpClients/ParseStreamHttpClient.php

+24-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,15 @@ public function send($url, $method = 'GET', $data = array())
209209
if ($method == "GET") {
210210
// handle GET
211211
$query = http_build_query($data, null, '&');
212-
$this->options['http']['content'] = $query;
212+
213+
if (!defined('HHVM_VERSION')) {
214+
$this->options['http']['content'] = $query;
215+
} else {
216+
// HHVM doesn't reapply 'content' to the url
217+
// have to do it ourselves
218+
$url.='?'.$query;
219+
}
220+
213221
$this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded');
214222
} elseif ($method == "POST") {
215223
// handle POST
@@ -221,7 +229,21 @@ public function send($url, $method = 'GET', $data = array())
221229
}
222230

223231
// set headers
224-
$this->options['http']['header'] = $this->buildRequestHeaders();
232+
if (!defined('HHVM_VERSION')) {
233+
// default
234+
$this->options['http']['header'] = $this->buildRequestHeaders();
235+
} else {
236+
/**
237+
* HHVM bug bypass
238+
* Passing via 'header' ends up duplicating all custom headers submitted due to a bug in HHVM.
239+
* We can bypass this through the separate 'user_agent' field, as it is never sanitized,
240+
* so we can append our desired headers after the initial user-agent string.
241+
* Note that this works in php5 as well (probably 7 and up too),
242+
* but for now we use this only where we need it.
243+
* Source: https://github.com/facebook/hhvm/blob/master/hphp/runtime/base/http-stream-wrapper.cpp#L92
244+
*/
245+
$this->options['http']['user_agent'] = "parse-php-sdk\r\n".$this->buildRequestHeaders();
246+
}
225247

226248
// create a stream context
227249
$this->parseStream->createContext($this->options);

src/Parse/ParsePolygon.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function setCoordinates($coords)
5050
}
5151
$points = [];
5252
foreach ($coords as $coord) {
53-
$geoPoint;
53+
$geoPoint = null;
5454
if ($coord instanceof ParseGeoPoint) {
5555
$geoPoint = $coord;
5656
} elseif (is_array($coord) && count($coord) === 2) {

tests/Parse/ParseStreamHttpClientTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
class ParseStreamHttpClientTest extends \PHPUnit_Framework_TestCase
1616
{
17+
/**
18+
* @group test-get-response
19+
*/
1720
public function testGetResponse()
1821
{
1922
$client = new ParseStreamHttpClient();
@@ -25,7 +28,7 @@ public function testGetResponse()
2528
// get response headers
2629
$headers = $client->getResponseHeaders();
2730

28-
$this->assertEquals('HTTP/1.0 200 OK', $headers['http_code']);
31+
$this->assertTrue(preg_match('|HTTP/1\.\d\s200\sOK|', $headers['http_code']) === 1);
2932
}
3033

3134
public function testInvalidUrl()

0 commit comments

Comments
 (0)