Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Middleware/ErrorRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ public function __construct(
callable $finishCallback,
private Throwable $throwable,
protected Container $serviceContainer,
protected array $getArray,
protected array $postArray,
protected array $filesArray,
protected array $serverArray,
) {
parent::__construct($config, $finishCallback);
parent::__construct(
$config,
$finishCallback,
$this->getArray,
$this->postArray,
$this->filesArray,
$this->serverArray,
);
}

public function handle(
Expand Down
22 changes: 18 additions & 4 deletions src/Middleware/Lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ public function start():void {
// to any area of code will not accidentally send output to the client.
ob_start();

$originalGlobals = [
"get" => $_GET,
"post" => $_POST,
"files" => $_FILES,
"server" => $_SERVER,
];
// A PSR-7 HTTP Request object is created from the current global state, ready
// for processing by the Handler.
$requestFactory = new RequestFactory();
$request = $requestFactory->createServerRequestFromGlobalState(
$_SERVER,
$_FILES,
$_GET,
$_POST,
$originalGlobals["server"],
$originalGlobals["files"],
$originalGlobals["get"],
$originalGlobals["post"],
);

// The handler is an individual component that processes a request and produces
Expand All @@ -75,6 +81,10 @@ public function start():void {
"vendor/phpgt/webengine/config.default.ini"
),
$this->finish(...),
$originalGlobals["get"],
$originalGlobals["post"],
$originalGlobals["files"],
$originalGlobals["server"],
);

// The request and request handler are passed to the PSR-15 process function,
Expand All @@ -93,6 +103,10 @@ public function start():void {
$this->finish(...),
$throwable,
$handler->getServiceContainer(),
$originalGlobals["get"],
$originalGlobals["post"],
$originalGlobals["files"],
$originalGlobals["server"],
);
$response = $this->process($request, $errorHandler);

Expand Down
8 changes: 6 additions & 2 deletions src/Middleware/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class RequestHandler implements RequestHandlerInterface {
public function __construct(
protected readonly Config $config,
callable $finishCallback,
protected array $getArray,
protected array $postArray,
protected array $filesArray,
protected array $serverArray,
) {
$this->finishCallback = $finishCallback;

Expand Down Expand Up @@ -96,15 +100,15 @@ protected function completeRequestHandling(
$this->forceTrailingSlashes($request);
$this->setupServiceContainer();

$input = new Input($_GET, $_POST, $_FILES);
$input = new Input($this->getArray, $this->postArray, $this->filesArray);

$this->serviceContainer->set(
$this->config,
$request,
$this->response,
$this->response->headers,
$input,
new ServerInfo($_SERVER),
new ServerInfo($this->serverArray),
);
$this->injector = new Injector($this->serviceContainer);

Expand Down