diff --git a/classes/Config.php b/classes/Config.php index 9aaf695..7fadf7f 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -10,7 +10,6 @@ use Alltube\Exception\ConfigException; use Alltube\Library\Downloader; use Jawira\CaseConverter\CaseConverterException; use Jean85\PrettyVersions; -use PackageVersions\Versions; use Symfony\Component\ErrorHandler\Debug; use Symfony\Component\Yaml\Yaml; use Jawira\CaseConverter\Convert; @@ -159,7 +158,7 @@ class Config $this->applyOptions($options); $this->getEnv(); $this->validateOptions(); - $localeManager = LocaleManager::getInstance(); + $localeManager = new LocaleManager(); if (empty($this->genericFormats)) { // We don't put this in the class definition so it can be detected by xgettext. diff --git a/classes/LocaleManager.php b/classes/LocaleManager.php index b008d8a..01a92a8 100644 --- a/classes/LocaleManager.php +++ b/classes/LocaleManager.php @@ -50,17 +50,10 @@ class LocaleManager */ private $translator; - /** - * Singleton instance. - * - * @var LocaleManager|null - */ - private static $instance; - /** * LocaleManager constructor. */ - private function __construct() + public function __construct() { $session = SessionManager::getSession(); $this->sessionSegment = $session->getSegment(self::class); @@ -171,29 +164,4 @@ class LocaleManager return ''; } - - /** - * Get LocaleManager singleton instance. - * - * @return LocaleManager - * @todo Stop using a singleton. - */ - public static function getInstance() - { - if (!isset(self::$instance)) { - self::$instance = new self(); - } - - return self::$instance; - } - - /** - * Destroy singleton instance. - * - * @return void - */ - public static function destroyInstance() - { - self::$instance = null; - } } diff --git a/classes/LocaleManagerFactory.php b/classes/LocaleManagerFactory.php index 068e512..782eb49 100644 --- a/classes/LocaleManagerFactory.php +++ b/classes/LocaleManagerFactory.php @@ -21,6 +21,6 @@ class LocaleManagerFactory throw new DependencyException('You need to install the intl extension for PHP.'); } - return LocaleManager::getInstance(); + return new LocaleManager(); } } diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index 96b6a68..600345c 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -11,8 +11,7 @@ use Alltube\Controller\BaseController; use Alltube\Controller\DownloadController; use Alltube\Controller\FrontController; use Alltube\Exception\ConfigException; -use Alltube\Exception\DependencyException; -use Alltube\LocaleManagerFactory; +use Alltube\LocaleManager; use Alltube\ViewFactory; use Psr\Log\NullLogger; use Slim\Container; @@ -56,7 +55,6 @@ abstract class ControllerTest extends BaseTest /** * Prepare tests. * @throws ConfigException|SmartyException - * @throws DependencyException */ protected function setUp(): void { @@ -66,7 +64,7 @@ abstract class ControllerTest extends BaseTest $this->request = Request::createFromEnvironment(Environment::mock()); $this->response = new Response(); $this->container['config'] = Config::fromFile($this->getConfigFile()); - $this->container['locale'] = LocaleManagerFactory::create(); + $this->container['locale'] = new LocaleManager(); $this->container['view'] = ViewFactory::create($this->container, $this->request); $this->container['logger'] = new NullLogger(); diff --git a/tests/LocaleManagerTest.php b/tests/LocaleManagerTest.php index 7732880..15b1fcf 100644 --- a/tests/LocaleManagerTest.php +++ b/tests/LocaleManagerTest.php @@ -27,7 +27,7 @@ class LocaleManagerTest extends BaseTest protected function setUp(): void { $_SESSION[LocaleManager::class]['locale'] = 'foo_BAR'; - $this->localeManager = LocaleManager::getInstance(); + $this->localeManager = new LocaleManager(); } /** @@ -38,7 +38,6 @@ class LocaleManagerTest extends BaseTest protected function tearDown(): void { $this->localeManager->unsetLocale(); - LocaleManager::destroyInstance(); } /** diff --git a/tests/LocaleMiddlewareTest.php b/tests/LocaleMiddlewareTest.php index feb05c2..1df6f09 100644 --- a/tests/LocaleMiddlewareTest.php +++ b/tests/LocaleMiddlewareTest.php @@ -38,7 +38,7 @@ class LocaleMiddlewareTest extends BaseTest protected function setUp(): void { $this->container = new Container(); - $this->container['locale'] = LocaleManager::getInstance(); + $this->container['locale'] = new LocaleManager(); $this->middleware = new LocaleMiddleware($this->container); } @@ -50,7 +50,6 @@ class LocaleMiddlewareTest extends BaseTest protected function tearDown(): void { $this->container['locale']->unsetLocale(); - LocaleManager::destroyInstance(); } /** diff --git a/tests/ViewFactoryTest.php b/tests/ViewFactoryTest.php index 1bafff9..5f04a31 100644 --- a/tests/ViewFactoryTest.php +++ b/tests/ViewFactoryTest.php @@ -28,7 +28,7 @@ class ViewFactoryTest extends BaseTest public function testCreate() { $container = new Container(); - $container['locale'] = LocaleManager::getInstance(); + $container['locale'] = new LocaleManager(); $view = ViewFactory::create($container); $this->assertInstanceOf(Smarty::class, $view); } @@ -42,7 +42,7 @@ class ViewFactoryTest extends BaseTest public function testCreateWithXForwardedProto() { $container = new Container(); - $container['locale'] = LocaleManager::getInstance(); + $container['locale'] = new LocaleManager(); $request = Request::createFromEnvironment(Environment::mock()); $view = ViewFactory::create($container, $request->withHeader('X-Forwarded-Proto', 'https')); $this->assertInstanceOf(Smarty::class, $view);