diff --git a/flight/Engine.php b/flight/Engine.php index fdbdfa6..52f0c98 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -27,7 +27,7 @@ use flight\net\Route; * # Core methods * @method void start() Starts engine * @method void stop() Stops framework and outputs current response - * @method void halt(int $code = 200, string $message = '', bool $actually_exit = true) Stops processing and returns a given response. + * @method void halt(int $code = 200, string $message = '', bool $actuallyExit = true) Stops processing and returns a given response. * * # Routing * @method Route route(string $pattern, callable $callback, bool $pass_route = false, string $alias = '') @@ -647,16 +647,16 @@ class Engine * * @param int $code HTTP status code * @param string $message Response message - * @param bool $actually_exit Whether to actually exit the script or just send response + * @param bool $actuallyExit Whether to actually exit the script or just send response */ - public function _halt(int $code = 200, string $message = '', bool $actually_exit = true): void + public function _halt(int $code = 200, string $message = '', bool $actuallyExit = true): void { $this->response() ->clear() ->status($code) ->write($message) ->send(); - if ($actually_exit === true) { + if ($actuallyExit === true) { exit(); // @codeCoverageIgnore } } diff --git a/flight/Flight.php b/flight/Flight.php index 955ee87..6e29781 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -22,7 +22,7 @@ require_once __DIR__ . '/autoload.php'; * @method static void start() Starts the framework. * @method static void path(string $path) Adds a path for autoloading classes. * @method static void stop(?int $code = null) Stops the framework and sends a response. - * @method static void halt(int $code = 200, string $message = '', bool $actually_exit = true) + * @method static void halt(int $code = 200, string $message = '', bool $actuallyExit = true) * Stop the framework with an optional status code and message. * * # Routing diff --git a/tests/FlightTest.php b/tests/FlightTest.php index c37a8fa..c82caff 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -242,4 +242,38 @@ class FlightTest extends TestCase $this->assertEquals('/user/all_users/check_user/check_one/normalpath', $url); } + + public function testHookOutputBuffering() { + Flight::route('/test', function () { + echo 'test'; + }); + + Flight::before('start', function ($output) { + echo 'hooked before start'; + }); + + Flight::request()->url = '/test'; + + $this->expectOutputString('hooked before starttest'); + Flight::start(); + $this->assertEquals('test', Flight::response()->getBody()); + } + + public function testHookOutputBufferingV2OutputBuffering() { + Flight::route('/test', function () { + echo 'test'; + }); + + Flight::before('start', function ($output) { + echo 'hooked before start'; + }); + + Flight::set('flight.v2.output_buffering', true); + Flight::request()->url = '/test'; + + $this->expectOutputString('hooked before starttest'); + ob_start(); + Flight::start(); + $this->assertEquals('hooked before starttest', Flight::response()->getBody()); + } } diff --git a/tests/server-v2/index.php b/tests/server-v2/index.php index 547a1f9..240313e 100644 --- a/tests/server-v2/index.php +++ b/tests/server-v2/index.php @@ -11,6 +11,7 @@ require file_exists(__DIR__ . '/../../vendor/autoload.php') ? __DIR__ . '/../../ Flight::set('flight.content_length', false); Flight::set('flight.views.path', './'); +// This enables the old functionality of Flight output buffering Flight::set('flight.v2.output_buffering', true); // Test 1: Root route