Skip to content

Commit 627be8f

Browse files
committed
Merge pull request #795 from LearningLocker/develop
v1.12.1
2 parents be336bf + 33028cd commit 627be8f

File tree

10 files changed

+57
-43
lines changed

10 files changed

+57
-43
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.12.0
1+
1.12.1

app/controllers/api/Exports.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function showJson($id) {
3030
$model = $this->repo->show($id, $opts);
3131

3232
return IlluminateResponse::stream(function () use ($model, $opts) {
33+
if (ob_get_level() == 0) ob_start();
3334
echo '[';
3435
$this->repo->export($model, array_merge($opts, [
3536
'next' => function () {
@@ -56,6 +57,7 @@ public function showCsv($id) {
5657
$model = $this->repo->show($id, $opts);
5758

5859
return IlluminateResponse::stream(function () use ($model, $opts) {
60+
if (ob_get_level() == 0) ob_start();
5961
// Outputs the field names (column headers).
6062
echo implode(',', array_map(function ($field) {
6163
return $field['to'];

app/controllers/xapi/DocumentController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public function documentResponse($data) {
240240
default:
241241
$stream = FileFactory::create()->stream($document->getFilePath(), []);
242242
return \Response::stream(function () use ($stream) {
243+
if (ob_get_level() == 0) ob_start();
243244
while (!feof($stream)) {
244245
echo fread($stream, 8192); flush();ob_flush();
245246
}

app/controllers/xapi/StatementIndexController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class StatementIndexController {
99

10-
const BOUNDARY = 'abcABC0123\'()+_,-./:=?';
1110
const EOL = "\r\n";
1211

1312
/**
@@ -48,7 +47,7 @@ public function index($options) {
4847

4948
// Defines the content type and body of the response.
5049
if ($opts['attachments'] === true) {
51-
$content_type = 'multipart/mixed; boundary='.static::BOUNDARY;
50+
$content_type = Helpers::mixedMultipartContentType();
5251
$body = function () use ($statements, $count, $opts) {
5352
return $this->makeAttachmentsResult($statements, $count, $opts);
5453
};
@@ -97,9 +96,8 @@ private function makeStatementsResult(array $statements, $count, array $opts) {
9796
* @return \stdClass
9897
*/
9998
private function makeAttachmentsResult(array $statements, $count, array $opts) {
100-
$boundary = static::BOUNDARY;
99+
$boundary = Helpers::MULTIPART_BOUNDARY;
101100
$eol = static::EOL;
102-
$content_type = 'multipart/mixed; boundary='.$boundary;
103101

104102
$this->emit("--$boundary$eol");
105103
$this->emit("Content-Type:application/json$eol$eol");
@@ -128,6 +126,7 @@ private function makeAttachmentsResult(array $statements, $count, array $opts) {
128126
}
129127

130128
private function emit($value) {
129+
if (ob_get_level() == 0) ob_start();
131130
echo $value;
132131
flush();
133132
ob_flush();

app/locker/helpers/Attachments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private static function getHeaders($raw_headers, $delim) {
7676
* @return String
7777
*/
7878
private static function getBoundary($content_type) {
79-
preg_match('/boundary=(.*)$/', $content_type, $matches);
79+
preg_match('/boundary="?(.+?)"?$/', $content_type, $matches);
8080
if (!isset($matches[1])) throw new Exceptions\Exception(
8181
'You need to set a boundary if submitting attachments.'
8282
);

app/locker/helpers/Helpers.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
class Helpers {
1515

16+
const MULTIPART_BOUNDARY = 'abcABC0123\'()+_,-./:=?';
17+
1618
/*
1719
|----------------------------------------------------------------------------
1820
| scan array and replace &46; with . (This is a result of . being
@@ -252,4 +254,9 @@ public static function convertIds( $models = [] ) {
252254
return $model;
253255
}, $models);
254256
}
257+
258+
public static function mixedMultipartContentType( $boundary = null ){
259+
$boundary = $boundary ?: static::MULTIPART_BOUNDARY;
260+
return 'multipart/mixed; boundary="' . $boundary . '"';
261+
}
255262
}

app/locker/repository/Statement/Options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getOpt($opt) {
2929
*/
3030
protected function validate($opts) {
3131
foreach ($opts as $key => $value) {
32-
if ($value !== null && $this->types[$key] !== null) {
32+
if ($value !== null && isset($this->types[$key]) && $this->types[$key] !== null) {
3333
if (is_array($this->types[$key])) {
3434
$class = '\Locker\XApi\\'.$this->types[$key][0];
3535
if (!is_array($value)) {

app/tests/routes/StatementAttachmentTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
class StatementAttachmentTest extends StatementsTestCase {
66
use RouteTestTrait;
7-
protected $boundary = 'abcABC0123\'()+_,-./:=?';
7+
protected $boundary;
88

99
public function setup() {
1010
parent::setup();
11+
$this->boundary = Helpers::MULTIPART_BOUNDARY;
1112
$this->statements[0]->delete();
1213
}
1314

@@ -58,10 +59,11 @@ private function storeAttachments() {
5859
$attachment = $this->getAttachment($attachment_location);
5960
$statement = $this->generateStatementWithAttachment($attachment);
6061
$request_content = $this->generateContent(json_encode($statement), $attachment);
62+
$content_type = Helpers::mixedMultipartContentType();
6163

6264
// Sends request.
6365
$response = $this->requestStatements('POST', [], [
64-
'CONTENT_TYPE' => "multipart/mixed; boundary=$this->boundary"
66+
'CONTENT_TYPE' => $content_type
6567
], $request_content);
6668

6769
// Checks that the response is correct.

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"url": "https://github.com/LearningLocker/laravel-mongodb"
3636
}
3737
],
38+
"config":{
39+
"secure-http": false
40+
},
3841
"require": {
3942
"php": ">=5.5.0",
4043
"ext-mongo": "*",

composer.lock

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)