Skip to content

Commit

Permalink
Merge pull request #131 from mychidarko/v3.x-dev
Browse files Browse the repository at this point in the history
Extend request & response
  • Loading branch information
mychidarko authored Aug 11, 2022
2 parents db12ff0 + 1a9ee7f commit 67713a4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*******************************************************************************/
Expand Down
15 changes: 15 additions & 0 deletions tests/app.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 67713a4

Please sign in to comment.