diff --git a/src/App.php b/src/App.php index fe43189..73c85c6 100755 --- a/src/App.php +++ b/src/App.php @@ -254,6 +254,30 @@ public function config($name, $value = null) $this->setupErrorHandler(); } + /** + * Swap out Leaf request instance + * + * @param mixed $class The new request class to attach + */ + public function setRequestClass($class) + { + $this->container->singleton('request', function () { + return new \Leaf\Http\Request(); + }); + } + + /** + * Swap out Leaf response instance + * + * @param mixed $class The new response class to attach + */ + public function setResponseClass($class) + { + $this->container->singleton('response', function () use ($class) { + return new $class(); + }); + } + /******************************************************************************** * Logging *******************************************************************************/ diff --git a/tests/app.test.php b/tests/app.test.php index e88d157..1512099 100644 --- a/tests/app.test.php +++ b/tests/app.test.php @@ -119,3 +119,18 @@ public function call() expect($app->config('inTest2'))->toBe('false'); }); + +test('swap out leaf response', function () { + class TestResponse extends \Leaf\Http\Response + { + public function customMethod() + { + return 'This is some test response'; + } + } + + $leafInstance1 = new \Leaf\App(); + $leafInstance1->setResponseClass(TestResponse::class); + + expect($leafInstance1->response->customMethod())->toBe('This is some test response'); +});