From 3ead8dd4587a5db019c637c8a1f5389beaa9db40 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 30 May 2017 23:49:38 +0200 Subject: [PATCH] Undeclared properties --- classes/LocaleManager.php | 7 +++++++ classes/LocaleMiddleware.php | 18 +++++++++++++----- controllers/FrontController.php | 23 +++++++++++++++-------- tests/LocaleMiddlewareTest.php | 15 +++++++++++---- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/classes/LocaleManager.php b/classes/LocaleManager.php index d031dcc..60d799b 100644 --- a/classes/LocaleManager.php +++ b/classes/LocaleManager.php @@ -24,6 +24,13 @@ class LocaleManager */ private $curLocale; + /** + * Session segment used to store session variables. + * + * @var \Aura\Session\Segment + */ + private $sessionSegment; + /** * LocaleManager constructor. * diff --git a/classes/LocaleMiddleware.php b/classes/LocaleMiddleware.php index 8084ea8..146c4b4 100644 --- a/classes/LocaleMiddleware.php +++ b/classes/LocaleMiddleware.php @@ -15,6 +15,14 @@ use Teto\HTTP\AcceptLanguage; */ class LocaleMiddleware { + + /** + * LocaleManager instance. + * + * @var LocaleManager + */ + private $localeManager; + /** * LocaleMiddleware constructor. * @@ -22,7 +30,7 @@ class LocaleMiddleware */ public function __construct(ContainerInterface $container) { - $this->locale = $container->get('locale'); + $this->localeManager = $container->get('locale'); } /** @@ -34,7 +42,7 @@ class LocaleMiddleware */ public function testLocale(array $proposedLocale) { - foreach ($this->locale->getSupportedLocales() as $locale) { + foreach ($this->localeManager->getSupportedLocales() as $locale) { $parsedLocale = AcceptLanguage::parse($locale); if (isset($proposedLocale['language']) && $parsedLocale[1]['language'] == $proposedLocale['language'] @@ -57,14 +65,14 @@ class LocaleMiddleware public function __invoke(Request $request, Response $response, callable $next) { $headers = $request->getHeader('Accept-Language'); - $curLocale = $this->locale->getLocale(); + $curLocale = $this->localeManager->getLocale(); if (!isset($curLocale)) { if (isset($headers[0])) { - $this->locale->setLocale( + $this->localeManager->setLocale( AcceptLanguage::detect([$this, 'testLocale'], new Locale('en_US'), $headers[0]) ); } else { - $this->locale->setLocale(new Locale('en_US')); + $this->localeManager->setLocale(new Locale('en_US')); } } diff --git a/controllers/FrontController.php b/controllers/FrontController.php index fb5de9f..82eb827 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -62,6 +62,13 @@ class FrontController */ private $defaultFormat = 'best[protocol^=http]'; + /** + * LocaleManager instance. + * + * @var LocaleManager + */ + private $localeManager; + /** * FrontController constructor. * @@ -79,7 +86,7 @@ class FrontController $this->download = new VideoDownload(); $this->container = $container; $this->view = $this->container->get('view'); - $this->locale = $this->container->get('locale'); + $this->localeManager = $this->container->get('locale'); $session_factory = new \Aura\Session\SessionFactory(); $session = $session_factory->newInstance($cookies); $this->sessionSegment = $session->getSegment('Alltube\Controller\FrontController'); @@ -108,8 +115,8 @@ class FrontController 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.', 'domain' => $uri->getScheme().'://'.$uri->getAuthority(), 'canonical' => $this->getCanonicalUrl($request), - 'locales' => $this->locale->getSupportedLocales(), - 'locale' => $this->locale->getLocale(), + 'locales' => $this->localeManager->getSupportedLocales(), + 'locale' => $this->localeManager->getLocale(), ] ); @@ -127,7 +134,7 @@ class FrontController */ public function locale(Request $request, Response $response, array $data) { - $this->locale->setLocale(new Locale($data['locale'])); + $this->localeManager->setLocale(new Locale($data['locale'])); return $response->withRedirect($this->container->get('router')->pathFor('index')); } @@ -152,7 +159,7 @@ class FrontController 'description' => 'List of all supported websites from which Alltube Download '. 'can extract video or audio files', 'canonical' => $this->getCanonicalUrl($request), - 'locale' => $this->locale->getLocale(), + 'locale' => $this->localeManager->getLocale(), ] ); @@ -177,7 +184,7 @@ class FrontController 'title' => 'Password prompt', 'description' => 'You need a password in order to download this video with Alltube Download', 'canonical' => $this->getCanonicalUrl($request), - 'locale' => $this->locale->getLocale(), + 'locale' => $this->localeManager->getLocale(), ] ); @@ -268,7 +275,7 @@ class FrontController 'protocol' => $protocol, 'config' => $this->config, 'canonical' => $this->getCanonicalUrl($request), - 'locale' => $this->locale->getLocale(), + 'locale' => $this->localeManager->getLocale(), ] ); @@ -320,7 +327,7 @@ class FrontController 'class' => 'video', 'title' => 'Error', 'canonical' => $this->getCanonicalUrl($request), - 'locale' => $this->locale->getLocale(), + 'locale' => $this->localeManager->getLocale(), ] ); diff --git a/tests/LocaleMiddlewareTest.php b/tests/LocaleMiddlewareTest.php index 275ff39..2b5352d 100644 --- a/tests/LocaleMiddlewareTest.php +++ b/tests/LocaleMiddlewareTest.php @@ -22,14 +22,21 @@ class LocaleMiddlewareTest extends \PHPUnit_Framework_TestCase * * @var string */ - private $locale; + private $origlocale; + + /** + * LocaleMiddleware instance. + * + * @var LocaleMiddleware + */ + private $middleware; /** * Prepare tests. */ protected function setUp() { - $this->locale = getenv('LANG'); + $this->origlocale = getenv('LANG'); $container = new Container(); $container['locale'] = new LocaleManager(); $this->middleware = new LocaleMiddleware($container); @@ -42,8 +49,8 @@ class LocaleMiddlewareTest extends \PHPUnit_Framework_TestCase */ protected function tearDown() { - putenv('LANG='.$this->locale); - setlocale(LC_ALL, $this->locale); + putenv('LANG='.$this->origlocale); + setlocale(LC_ALL, $this->origlocale); } /**