mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
feat: add request() and response()
This commit is contained in:
parent
bf55cde458
commit
57ab3de4f8
@ -18,10 +18,12 @@ use CodeIgniter\Database\BaseConnection;
|
||||
use CodeIgniter\Database\ConnectionInterface;
|
||||
use CodeIgniter\Debug\Timer;
|
||||
use CodeIgniter\Files\Exceptions\FileNotFoundException;
|
||||
use CodeIgniter\HTTP\CLIRequest;
|
||||
use CodeIgniter\HTTP\Exceptions\HTTPException;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\Response;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\HTTP\URI;
|
||||
use CodeIgniter\Model;
|
||||
@ -882,6 +884,28 @@ if (! function_exists('remove_invisible_characters')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('request')) {
|
||||
/**
|
||||
* Returns the shared Request.
|
||||
*
|
||||
* @return CLIRequest|IncomingRequest
|
||||
*/
|
||||
function request()
|
||||
{
|
||||
return Services::request();
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('response')) {
|
||||
/**
|
||||
* Returns the shared Response.
|
||||
*/
|
||||
function response(): Response
|
||||
{
|
||||
return Services::response();
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('route_to')) {
|
||||
/**
|
||||
* Given a controller/method string and any params,
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace CodeIgniter;
|
||||
|
||||
use CodeIgniter\Config\BaseService;
|
||||
use CodeIgniter\HTTP\CLIRequest;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use CodeIgniter\HTTP\Response;
|
||||
@ -137,6 +138,31 @@ final class CommonFunctionsTest extends CIUnitTestCase
|
||||
$this->assertInstanceOf(RedirectResponse::class, redirect());
|
||||
}
|
||||
|
||||
public function testRequestIncomingRequest()
|
||||
{
|
||||
Services::createRequest(new App());
|
||||
|
||||
$request = request();
|
||||
|
||||
$this->assertInstanceOf(IncomingRequest::class, $request);
|
||||
}
|
||||
|
||||
public function testRequestCLIRequest()
|
||||
{
|
||||
Services::createRequest(new App(), true);
|
||||
|
||||
$request = request();
|
||||
|
||||
$this->assertInstanceOf(CLIRequest::class, $request);
|
||||
}
|
||||
|
||||
public function testResponse()
|
||||
{
|
||||
$response = response();
|
||||
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
}
|
||||
|
||||
public function testView()
|
||||
{
|
||||
$data = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user