HEX
Server: Apache
System: Linux v38079.2is.nl 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: democfellows (10015)
PHP: 8.1.34
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/creativefellows.nl/fvr.creativefellows.nl/src/Middleware/NotFoundMiddleware.php
<?php

namespace App\Middleware;

use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Slim\Exception\HttpNotFoundException;

use App\Handler\DefaultErrorHandler;
use App\Domain\Navigation\Service\NavigationReader;
use App\Domain\Page\Service\PageReader;
	
	
/**
 * Not Found middleware.
 */
final class NotFoundMiddleware implements MiddlewareInterface
{
    public function __construct(
		ResponseFactoryInterface $responseFactory,
		DefaultErrorHandler $errorHandler,
		NavigationReader $navigationReader,
		PageReader $pageReader
	){
		$this->responseFactory 	= $responseFactory;
		$this->errorHandler 	= $errorHandler;
		$this->navigationReader = $navigationReader;
		$this->pageReader 		= $pageReader;
    }
	
    public function process(
        ServerRequestInterface $request, 
        RequestHandlerInterface $handler
    ): ResponseInterface {
      	
		try{
			return $handler->handle($request);
		} 
		catch (HttpNotFoundException $httpException) {
			
			$response = $this->responseFactory->createResponse();
			$response = $response->withStatus(404);

			// empty page
			$page = $this->pageReader->getPageData("");
			
			// get menu elements
			$navigation = $this->navigationReader->getNavigationData("");	
			
			// return error page
			return $this->errorHandler->respond($response,$page,$navigation);
			
		}
    }
}