]> git.mxchange.org Git - friendica.git/commitdiff
Move setupContainerForLogger() and determine log channel into App class
authorArt4 <art4@wlabs.de>
Thu, 9 Jan 2025 10:13:33 +0000 (10:13 +0000)
committerArt4 <art4@wlabs.de>
Thu, 9 Jan 2025 10:13:33 +0000 (10:13 +0000)
src/App.php
src/Core/Console.php
src/Core/Container.php
src/Core/DiceContainer.php

index aa6dc5123442d3923291d234956e455f59ead658..17254bb96684eced1399ac44bd736343788868c9 100644 (file)
@@ -138,7 +138,9 @@ class App
 
                $this->setupContainerForAddons();
 
-               $this->container->setup(LogChannel::APP);
+               $this->setupContainerForLogger(LogChannel::APP);
+
+               $this->container->setup();
 
                $this->registerErrorHandler();
 
@@ -178,6 +180,10 @@ class App
        {
                $this->setupContainerForAddons();
 
+               $this->setupContainerForLogger($this->determineLogChannel($argv));
+
+               $this->container->setup();
+
                $this->registerErrorHandler();
 
                $this->registerTemplateEngine();
@@ -189,7 +195,9 @@ class App
        {
                $this->setupContainerForAddons();
 
-               $this->container->setup(LogChannel::AUTH_JABBERED);
+               $this->setupContainerForLogger(LogChannel::AUTH_JABBERED);
+
+               $this->container->setup();
 
                $this->registerErrorHandler();
 
@@ -218,6 +226,30 @@ class App
                }
        }
 
+       private function determineLogChannel(array $argv): string
+       {
+               $command = strtolower($argv[1]) ?? '';
+
+               if ($command === 'daemon' || $command === 'jetstream') {
+                       return LogChannel::DAEMON;
+               }
+
+               if ($command === 'worker') {
+                       return LogChannel::WORKER;
+               }
+
+               // @TODO Add support for jetstream
+
+               return LogChannel::CONSOLE;
+       }
+
+       private function setupContainerForLogger(string $logChannel): void
+       {
+               $this->container->addRule(LoggerInterface::class, [
+                       'constructParams' => [$logChannel],
+               ]);
+       }
+
        private function registerErrorHandler(): void
        {
                ErrorHandler::register($this->container->create(LoggerInterface::class));
index d138a9dfa98e1552e744c546711e361318b1fa11..67844f60332c3f6411125164defece60cead7959 100644 (file)
@@ -187,12 +187,6 @@ HELP;
 
                $className = $this->subConsoles[$command];
 
-               if (is_subclass_of($className, Friendica\Console\AbstractConsole::class)) {
-                       $this->container->setup($className::LOG_CHANNEL);
-               } else {
-                       $this->container->setup(LogChannel::CONSOLE);
-               }
-
                /** @var Console $subconsole */
                $subconsole = $this->container->create($className, [$subargs]);
 
index 84f8564a8755c9ead79a7b5635d5ca197d2b1f49..8d697991221f8030193151a3621216ef12a69f7c 100644 (file)
@@ -19,11 +19,9 @@ interface Container
         *
         * @deprecated
         *
-        * @param string $logChannel The Log Channel of this call
-        *
         * @return void
         */
-       public function setup(string $logChannel): void;
+       public function setup(): void;
 
        /**
         * Returns a fully constructed object based on $name using $args and $share as constructor arguments if supplied
index 2c1f5faba7030b90410c6addf93f33cd22acd573..778192388b1521fe1953408d177d2ea75dc466df 100644 (file)
@@ -11,7 +11,6 @@ namespace Friendica\Core;
 
 use Dice\Dice;
 use Friendica\DI;
-use Psr\Log\LoggerInterface;
 
 /**
  * Wrapper for the Dice class to make some basic setups
@@ -39,13 +38,10 @@ final class DiceContainer implements Container
         *
         * @deprecated
         *
-        * @param string $logChannel The Log Channel of this call
-        *
         * @return void
         */
-       public function setup(string $logChannel): void
+       public function setup(): void
        {
-               $this->setupContainerForLogger($logChannel);
                $this->setupLegacyServiceLocator();
        }
 
@@ -75,13 +71,6 @@ final class DiceContainer implements Container
                $this->container = $this->container->addRule($name, $rule);
        }
 
-       private function setupContainerForLogger(string $logChannel): void
-       {
-               $this->container = $this->container->addRule(LoggerInterface::class, [
-                       'constructParams' => [$logChannel],
-               ]);
-       }
-
        private function setupLegacyServiceLocator(): void
        {
                DI::init($this->container);