File: /var/www/vhosts/creativefellows.nl/firstbrick.creativefellows.nl/src/Action/View/ViewAction.php
<?php
namespace App\Action\View;
use App\Action\TwigAction;
use App\Domain\Page\Service\PageReader;
use App\Domain\Navigation\Service\NavigationReader;
use App\Domain\Language\LanguageData;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
use App\Handler\DefaultErrorHandler;
//use Psr\Container\ContainerInterface;
final class ViewAction extends TwigAction
{
//protected $container;
private $twig;
private $pageReader;
private $navigationReader;
private $errorHandler;
private $language;
public function __construct(
Twig $twig,
PageReader $pageReader,
NavigationReader $navigationReader,
LanguageData $language,
DefaultErrorHandler $errorHandler
) {
//$this->container = $container;
//$this->breadcrumbs = $breadcrumbs;
$this->twig = $twig;
$this->pageReader = $pageReader;
$this->navigationReader = $navigationReader;
$this->language = $language;
$this->errorHandler = $errorHandler;
}
public function action() : Response
{
$post_name = ($this->args['page'] ?? null);
$post_section = ($this->args['section'] ?? null);
$load_page = $post_name == null ? $post_section : $post_name;
// get data of page
$this->page = $this->pageReader->getPageData($load_page);
// return error page if no result in page
if( !$this->page->hasData() ) return $this->errorHandler->respond($this->response,$this->page,$this->navigationReader->getNavigationData($post_section));
$data = [
"navigation" => $this->navigationReader->getNavigationData($post_section),
"page" => $this->page->twigData(),
"localization" => $this->language->localizedLanguageData()->setting("labels"),
];
return $this->twig->render($this->response, $this->page->getTemplateName(), $data);
}
}