Skip to content

Commit 3fe2ca1

Browse files
committed
remove v2_output_buffering
1 parent 50075ab commit 3fe2ca1

5 files changed

Lines changed: 6 additions & 174 deletions

File tree

src/Engine.php

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ public function init(): void
170170
$this->set('flight.views.path', './views');
171171
$this->set('flight.views.extension', '.php');
172172
$this->set('flight.content_length', true);
173-
$this->set('flight.v2.output_buffering', false);
174173

175174
// Startup configuration
176175
$this->before('start', function (): void {
@@ -185,11 +184,6 @@ public function init(): void
185184

186185
// Set Content-Length
187186
$this->response()->content_length = $this->get('flight.content_length');
188-
189-
// This is to maintain legacy handling of output buffering
190-
// which causes a lot of problems. This will be removed
191-
// in v4
192-
$this->response()->v2_output_buffering = $this->get('flight.v2.output_buffering');
193187
});
194188

195189
$this->initialized = true;
@@ -431,9 +425,7 @@ protected function processMiddleware(Route $route, string $eventName): bool
431425
}
432426

433427
// This is the way that v3 handles output buffering (which captures output correctly)
434-
$useV3OutputBuffering =
435-
$this->response()->v2_output_buffering === false &&
436-
$route->is_streamed === false;
428+
$useV3OutputBuffering = !$route->is_streamed;
437429

438430
if ($useV3OutputBuffering === true) {
439431
ob_start();
@@ -505,17 +497,6 @@ public function _start(): void
505497
$response = $this->response();
506498
$router = $this->router();
507499

508-
if ($response->v2_output_buffering === true) {
509-
// Flush any existing output
510-
if (ob_get_length() > 0) {
511-
$response->write(ob_get_clean()); // @codeCoverageIgnore
512-
}
513-
514-
// Enable output buffering
515-
// This is closed in the Engine->_stop() method
516-
ob_start();
517-
}
518-
519500
// Route the request
520501
$failedMiddlewareCheck = false;
521502
while ($route = $router->route($request)) {
@@ -565,9 +546,7 @@ public function _start(): void
565546
$this->triggerEvent('flight.middleware.before', $route);
566547
}
567548

568-
$useV3OutputBuffering =
569-
$this->response()->v2_output_buffering === false &&
570-
$route->is_streamed === false;
549+
$useV3OutputBuffering = !$route->is_streamed;
571550

572551
if ($useV3OutputBuffering === true) {
573552
ob_start();
@@ -675,10 +654,6 @@ public function _stop(?int $code = null): void
675654
$response->status($code);
676655
}
677656

678-
if ($response->v2_output_buffering === true && ob_get_length() > 0) {
679-
$response->write(ob_get_clean());
680-
}
681-
682657
$response->send();
683658
}
684659
}
@@ -903,9 +878,6 @@ public function _json(
903878
->status($code)
904879
->header('Content-Type', 'application/json')
905880
->write($json);
906-
if ($this->response()->v2_output_buffering === true) {
907-
$this->response()->send();
908-
}
909881
}
910882

911883
/**
@@ -928,10 +900,8 @@ public function _jsonHalt(
928900
): void {
929901
$this->json($data, $code, $encode, $charset, $option);
930902
$jsonBody = $this->response()->getBody();
931-
if ($this->response()->v2_output_buffering === false) {
932-
$this->response()->clearBody();
933-
$this->response()->send();
934-
}
903+
$this->response()->clearBody();
904+
$this->response()->send();
935905
$this->halt($code, $jsonBody, empty(getenv('PHPUNIT_TEST')));
936906
}
937907

@@ -962,9 +932,6 @@ public function _jsonp(
962932
->status($code)
963933
->header('Content-Type', 'application/javascript; charset=' . $charset)
964934
->write($callback . '(' . $json . ');');
965-
if ($this->response()->v2_output_buffering === true) {
966-
$this->response()->send();
967-
}
968935
}
969936

970937
/**

src/net/Response.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ class Response
2222
*/
2323
public bool $content_length = true;
2424

25-
/**
26-
* This is to maintain legacy handling of output buffering
27-
* which causes a lot of problems. This will be removed
28-
* in v4
29-
*
30-
* @var boolean
31-
*/
32-
public bool $v2_output_buffering = false;
33-
3425
/**
3526
* HTTP status codes
3627
*
@@ -271,7 +262,7 @@ public function clear(): self
271262
$this->clearBody();
272263

273264
// This needs to clear the output buffer if it's on
274-
if ($this->v2_output_buffering === false && ob_get_length() > 0) {
265+
if (ob_get_length() > 0) {
275266
ob_clean();
276267
}
277268

@@ -421,18 +412,8 @@ public function markAsSent(): void
421412
*/
422413
public function send(): void
423414
{
424-
// legacy way of handling this
425-
if ($this->v2_output_buffering === true) {
426-
if (ob_get_length() > 0) {
427-
ob_end_clean(); // @codeCoverageIgnore
428-
}
429-
}
430-
431415
$start = microtime(true);
432-
// Only for the v3 output buffering.
433-
if ($this->v2_output_buffering === false) {
434-
$this->processResponseCallbacks();
435-
}
416+
$this->processResponseCallbacks();
436417

437418
if ($this->headersSent() === false) {
438419
$this->sendHeaders();

tests/DocExamplesTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,6 @@ public function testMapNotFoundMethod(): void
4545
$this->assertEquals('[]', Flight::response()->getBody());
4646
}
4747

48-
public function testMapNotFoundMethodV2OutputBuffering(): void
49-
{
50-
Flight::map('notFound', function () {
51-
Flight::json([], 404);
52-
});
53-
54-
Flight::request()->url = '/not-found';
55-
56-
Flight::route('/', function () {
57-
echo 'hello world!';
58-
});
59-
60-
Flight::set('flight.v2.output_buffering', true);
61-
Flight::start();
62-
ob_get_clean();
63-
$this->assertEquals(404, Flight::response()->status());
64-
$this->assertEquals('[]', Flight::response()->getBody());
65-
}
66-
6748
public function testMapErrorMethod(): void
6849
{
6950
Flight::map('error', function (Throwable $error) {

tests/EngineTest.php

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,6 @@ public function getInitializedVar()
4949
$this->assertTrue($engine->response()->content_length);
5050
}
5151

52-
public function testInitBeforeStartV2OutputBuffering(): void
53-
{
54-
$engine = new class extends Engine {
55-
public function getInitializedVar(): bool
56-
{
57-
return $this->initialized;
58-
}
59-
};
60-
$engine->set('flight.v2.output_buffering', true);
61-
$this->assertTrue($engine->getInitializedVar());
62-
$engine->start();
63-
64-
// This is a necessary evil because of how the v2 output buffer works.
65-
ob_end_clean();
66-
67-
$this->assertFalse($engine->router()->caseSensitive);
68-
$this->assertTrue($engine->response()->content_length);
69-
}
70-
7152
public function testHandleErrorNoErrorNumber(): void
7253
{
7354
$engine = new Engine();
@@ -322,34 +303,6 @@ public function setRealHeader(string $header_string, bool $replace = true, int $
322303
$this->assertEquals(500, $engine->response()->status());
323304
}
324305

325-
public function testStopWithCodeV2OutputBuffering(): void
326-
{
327-
$engine = new class extends Engine {
328-
public function getLoader()
329-
{
330-
return $this->loader;
331-
}
332-
};
333-
// doing this so we can overwrite some parts of the response
334-
$engine->getLoader()->register('response', function () {
335-
return new class extends Response {
336-
public function setRealHeader(string $header_string, bool $replace = true, int $response_code = 0): self
337-
{
338-
return $this;
339-
}
340-
};
341-
});
342-
$engine->set('flight.v2.output_buffering', true);
343-
$engine->route('/testRoute', function () use ($engine) {
344-
echo 'I am a teapot';
345-
$engine->stop(500);
346-
});
347-
$engine->request()->url = '/testRoute';
348-
$engine->start();
349-
$this->expectOutputString('I am a teapot');
350-
$this->assertEquals(500, $engine->response()->status());
351-
}
352-
353306
public function testPostRoute(): void
354307
{
355308
$engine = new Engine();
@@ -519,16 +472,6 @@ public function testJsonThrowOnErrorByDefault(): void
519472
$engine->json(['key1' => 'value1', 'key2' => 'value2', 'utf8_emoji' => "\xB1\x31"]);
520473
}
521474

522-
public function testJsonV2OutputBuffering(): void
523-
{
524-
$engine = new Engine();
525-
$engine->response()->v2_output_buffering = true;
526-
$engine->json(['key1' => 'value1', 'key2' => 'value2']);
527-
$this->expectOutputString('{"key1":"value1","key2":"value2"}');
528-
$this->assertEquals('application/json', $engine->response()->headers()['Content-Type']);
529-
$this->assertEquals(200, $engine->response()->status());
530-
}
531-
532475
public function testJsonHalt(): void
533476
{
534477
$engine = new Engine();
@@ -549,17 +492,6 @@ public function testJsonP(): void
549492
$this->assertEquals('whatever({"key1":"value1","key2":"value2"});', $engine->response()->getBody());
550493
}
551494

552-
public function testJsonPV2OutputBuffering(): void
553-
{
554-
$engine = new Engine();
555-
$engine->response()->v2_output_buffering = true;
556-
$engine->request()->query['jsonp'] = 'whatever';
557-
$engine->jsonp(['key1' => 'value1', 'key2' => 'value2']);
558-
$this->expectOutputString('whatever({"key1":"value1","key2":"value2"});');
559-
$this->assertEquals('application/javascript; charset=utf-8', $engine->response()->headers()['Content-Type']);
560-
$this->assertEquals(200, $engine->response()->status());
561-
}
562-
563495
public function testJsonpBadParam(): void
564496
{
565497
$engine = new Engine();
@@ -569,16 +501,6 @@ public function testJsonpBadParam(): void
569501
$this->assertEquals(200, $engine->response()->status());
570502
}
571503

572-
public function testJsonpBadParamV2OutputBuffering(): void
573-
{
574-
$engine = new Engine();
575-
$engine->response()->v2_output_buffering = true;
576-
$engine->jsonp(['key1' => 'value1', 'key2' => 'value2']);
577-
$this->expectOutputString('({"key1":"value1","key2":"value2"});');
578-
$this->assertEquals('application/javascript; charset=utf-8', $engine->response()->headers()['Content-Type']);
579-
$this->assertEquals(200, $engine->response()->status());
580-
}
581-
582504
public function testEtagSimple(): void
583505
{
584506
$engine = new Engine();

tests/FlightTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,6 @@ public function testHookOutputBuffering(): void
275275
$this->assertEquals('test', Flight::response()->getBody());
276276
}
277277

278-
public function testHookOutputBufferingV2OutputBuffering(): void
279-
{
280-
Flight::route('/test', function () {
281-
echo 'test';
282-
});
283-
284-
Flight::before('start', function ($output) {
285-
echo 'hooked before start';
286-
});
287-
288-
Flight::set('flight.v2.output_buffering', true);
289-
Flight::request()->url = '/test';
290-
291-
$this->expectOutputString('hooked before starttest');
292-
ob_start();
293-
Flight::start();
294-
$this->assertEquals('hooked before starttest', Flight::response()->getBody());
295-
}
296-
297278
public function testStreamRoute(): void
298279
{
299280
$response_mock = new class extends Response {

0 commit comments

Comments
 (0)