X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FDatabase%2FDatabase.php;h=9527fefb0f46310ef2fe49dcab9baa541540361d;hb=f87eeb2f2866f21511069df9adf199bf68610c1d;hp=a5fe7f978a1278eb08dcb4ac49edb9dbd99f4baf;hpb=f609e38600f54fe8465d1194008d823103f41baa;p=friendica.git diff --git a/src/Database/Database.php b/src/Database/Database.php index a5fe7f978a..9527fefb0f 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -36,6 +36,7 @@ use PDO; use PDOException; use PDOStatement; use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; /** * This class is for the low level database stuff that does driver specific things. @@ -54,15 +55,15 @@ class Database /** * @var IManageConfigValues */ - protected $config; + protected $config = null; /** * @var Profiler */ - protected $profiler; + protected $profiler = null; /** * @var LoggerInterface */ - protected $logger; + protected $logger = null; protected $server_info = ''; /** @var PDO|mysqli */ protected $connection; @@ -80,18 +81,36 @@ class Database /** @var ViewDefinition */ protected $viewDefinition; - public function __construct(IManageConfigValues $config, Profiler $profiler, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition, LoggerInterface $logger) + public function __construct(IManageConfigValues $config, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition) { // We are storing these values for being able to perform a reconnect $this->config = $config; - $this->profiler = $profiler; $this->dbaDefinition = $dbaDefinition; $this->viewDefinition = $viewDefinition; - $this->logger = $logger; + + // Use dummy values - necessary for the first factory call of the logger itself + $this->logger = new NullLogger(); + $this->profiler = new Profiler($config); $this->connect(); } + /** + * @param IManageConfigValues $config + * @param Profiler $profiler + * @param LoggerInterface $logger + * + * @return void + * + * @todo Make this method obsolet - use a clean pattern instead ... + */ + public function setDependency(IManageConfigValues $config, Profiler $profiler, LoggerInterface $logger) + { + $this->logger = $logger; + $this->profiler = $profiler; + $this->config = $config; + } + /** * Tries to connect to database *