From 8505a7e99fccf139311b028b09a5d3f2f496aacf Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 23 Oct 2016 22:59:37 +0200 Subject: [PATCH 1/2] Better container handling --- controllers/FrontController.php | 113 ++++++++++++++++---------------- 1 file changed, 55 insertions(+), 58 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index fe5e813..0c82751 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -46,6 +46,12 @@ class FrontController */ private $sessionSegment; + /** + * Smarty view + * @var \Slim\Views\Smarty + */ + private $view; + /** * FrontController constructor. * @@ -56,6 +62,7 @@ class FrontController $this->config = Config::getInstance(); $this->download = new VideoDownload(); $this->container = $container; + $this->view = $this->container->get('view'); $session_factory = new \Aura\Session\SessionFactory(); $session = $session_factory->newInstance($_COOKIE); $this->sessionSegment = $session->getSegment('Alltube\Controller\FrontController'); @@ -71,17 +78,15 @@ class FrontController */ public function index(Request $request, Response $response) { - if ($this->container instanceof Container) { - $this->container->view->render( - $response, - 'index.tpl', - [ - 'convert' => $this->config->convert, - 'class' => 'index', - 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.', - ] - ); - } + $this->view->render( + $response, + 'index.tpl', + [ + 'convert' => $this->config->convert, + 'class' => 'index', + 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.', + ] + ); } /** @@ -94,19 +99,17 @@ class FrontController */ public function extractors(Request $request, Response $response) { - if ($this->container instanceof Container) { - $this->container->view->render( - $response, - 'extractors.tpl', - [ - 'extractors' => $this->download->listExtractors(), - 'class' => 'extractors', - 'title' => 'Supported websites', - 'description' => 'List of all supported websites from which Alltube Download '. - 'can extract video or audio files', - ] - ); - } + $this->view->render( + $response, + 'extractors.tpl', + [ + 'extractors' => $this->download->listExtractors(), + 'class' => 'extractors', + 'title' => 'Supported websites', + 'description' => 'List of all supported websites from which Alltube Download '. + 'can extract video or audio files', + ] + ); } /** @@ -119,17 +122,15 @@ class FrontController */ public function password(Request $request, Response $response) { - if ($this->container instanceof Container) { - $this->container->view->render( - $response, - 'password.tpl', - [ - 'class' => 'password', - 'title' => 'Password prompt', - 'description' => 'You need a password in order to download this video with Alltube Download', - ] - ); - } + $this->view->render( + $response, + 'password.tpl', + [ + 'class' => 'password', + 'title' => 'Password prompt', + 'description' => 'You need a password in order to download this video with Alltube Download', + ] + ); } /** @@ -176,18 +177,16 @@ class FrontController } catch (PasswordException $e) { return $this->password($request, $response); } - if ($this->container instanceof Container) { - $this->container->view->render( - $response, - 'video.tpl', - [ - 'video' => $video, - 'class' => 'video', - 'title' => $video->title, - 'description' => 'Download "'.$video->title.'" from '.$video->extractor_key, - ] - ); - } + $this->view->render( + $response, + 'video.tpl', + [ + 'video' => $video, + 'class' => 'video', + 'title' => $video->title, + 'description' => 'Download "'.$video->title.'" from '.$video->extractor_key, + ] + ); } } else { return $response->withRedirect($this->container->get('router')->pathFor('index')); @@ -205,17 +204,15 @@ class FrontController */ public function error(Request $request, Response $response, \Exception $exception) { - if ($this->container instanceof Container) { - $this->container->view->render( - $response, - 'error.tpl', - [ - 'errors' => $exception->getMessage(), - 'class' => 'video', - 'title' => 'Error', - ] - ); - } + $this->view->render( + $response, + 'error.tpl', + [ + 'errors' => $exception->getMessage(), + 'class' => 'video', + 'title' => 'Error', + ] + ); return $response->withStatus(500); } From df88f515e63e6f6df831b34c6175e5a01b02948c Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 23 Oct 2016 21:08:32 +0000 Subject: [PATCH 2/2] Applied fixes from StyleCI --- controllers/FrontController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 0c82751..bfe93a8 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -47,7 +47,8 @@ class FrontController private $sessionSegment; /** - * Smarty view + * Smarty view. + * * @var \Slim\Views\Smarty */ private $view;