From f8ccb1b06a51c553cbb85d21e7966ade42501f39 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 16 Sep 2018 01:32:18 +0200 Subject: [PATCH] good bye ApplicationBase! --- src/Application.php | 23 ++++++++++++++++++++-- src/ApplicationBase.php | 42 ----------------------------------------- 2 files changed, 21 insertions(+), 44 deletions(-) delete mode 100644 src/ApplicationBase.php diff --git a/src/Application.php b/src/Application.php index 0b54c8ac..95e57b11 100644 --- a/src/Application.php +++ b/src/Application.php @@ -17,8 +17,10 @@ use GeoIp2\Database\Reader as GeoIP; * Handles the set up procedures. * @package Misuzu */ -class Application extends ApplicationBase +final class Application { + private static $instance = null; + /** * Whether the application is in debug mode, this should only be set in the constructor and never altered. * @var bool @@ -71,8 +73,12 @@ class Application extends ApplicationBase */ public function __construct(?string $configFile = null, bool $debug = false) { + if (!empty(self::$instance)) { + throw new UnexpectedValueException('An Application has already been set up.'); + } + + self::$instance = $this; $this->startupTime = microtime(true); - parent::__construct(); $this->debugMode = $debug; $this->config = parse_ini_file($configFile, true, INI_SCANNER_TYPED); @@ -423,4 +429,17 @@ class Application extends ApplicationBase { return $this->getPath($this->config['Avatar']['default_path'] ?? 'public/images/no-avatar.png'); } + + /** + * Gets the currently active instance of Application + * @return Application + */ + public static function getInstance(): Application + { + if (empty(self::$instance)) { + throw new UnexpectedValueException('No instances.'); + } + + return self::$instance; + } } diff --git a/src/ApplicationBase.php b/src/ApplicationBase.php deleted file mode 100644 index ea5d7ef5..00000000 --- a/src/ApplicationBase.php +++ /dev/null @@ -1,42 +0,0 @@ -