From 2cd65d0f20873b5b0e59bceaebf3770928859a7c Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 7 Jun 2019 22:58:38 +0300 Subject: [PATCH] Site Plugin: fixes and refactoring #117 --- .../site/app/Controllers/SiteController.php | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/site/plugins/site/app/Controllers/SiteController.php b/site/plugins/site/app/Controllers/SiteController.php index 0169a11c..159ac121 100644 --- a/site/plugins/site/app/Controllers/SiteController.php +++ b/site/plugins/site/app/Controllers/SiteController.php @@ -3,23 +3,33 @@ namespace Flextype; use Flextype\Component\Arr\Arr; +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; class SiteController extends Controller { - public function index($request, $response, $args) { + /** + * Index page + * + * @param Request $request PSR7 request + * @param Response $response PSR7 response + * @param array $args Args + * @return Response + */ + public function index(Request $request, Response $response, array $args) { // Get uri $uri = $args['uri']; // If uri is empty then it is main page else use entry uri if ($uri === '/') { - $entry_uri = $this->container->get('registry')->get('settings.entries.main'); + $entry_uri = $this->registry->get('settings.entries.main'); } else { $entry_uri = ltrim($uri, '/'); } // Get entry body - $entry_body = $this->container->get('entries')->fetch($entry_uri); + $entry_body = $this->entries->fetch($entry_uri); // is entry not found $is_entry_not_found = false; @@ -30,10 +40,10 @@ class SiteController extends Controller // Get 404 page if entry is not published if (isset($entry_body['visibility']) && ($entry_body['visibility'] === 'draft' || $entry_body['visibility'] === 'hidden')) { - $entry['title'] = $this->container->get('registry')->get('settings.entries.error404.title'); - $entry['description'] = $this->container->get('registry')->get('settings.entries.error404.description'); - $entry['content'] = $this->container->get('registry')->get('settings.entries.error404.content'); - $entry['template'] = $this->container->get('registry')->get('settings.entries.error404.template'); + $entry['title'] = $this->registry->get('settings.entries.error404.title'); + $entry['description'] = $this->registry->get('settings.entries.error404.description'); + $entry['content'] = $this->registry->get('settings.entries.error404.content'); + $entry['template'] = $this->registry->get('settings.entries.error404.template'); $is_entry_not_found = true; @@ -42,15 +52,15 @@ class SiteController extends Controller } } else { - $entry['title'] = $this->container->get('registry')->get('settings.entries.error404.title'); - $entry['description'] = $this->container->get('registry')->get('settings.entries.error404.description'); - $entry['content'] = $this->container->get('registry')->get('settings.entries.error404.content'); - $entry['template'] = $this->container->get('registry')->get('settings.entries.error404.template'); + $entry['title'] = $this->registry->get('settings.entries.error404.title'); + $entry['description'] = $this->registry->get('settings.entries.error404.description'); + $entry['content'] = $this->registry->get('settings.entries.error404.content'); + $entry['template'] = $this->registry->get('settings.entries.error404.template'); $is_entry_not_found = true; } - $path = 'themes/' . $this->container->get('registry')->get('settings.theme') . '/' . (empty($entry['template']) ? 'templates/default' : 'templates/' . $entry['template']) . '.html'; + $path = 'themes/' . $this->registry->get('settings.theme') . '/' . (empty($entry['template']) ? 'templates/default' : 'templates/' . $entry['template']) . '.html'; if ($is_entry_not_found) { return $this->view->render($response->withStatus(404), $path, ['entry' => $entry]);