custom/plugins/EasyCreditRatenkauf/src/Logger/LoggerConfigurator.php line 54

Open in your IDE?
  1. <?php
  2. /*
  3.  * (c) NETZKOLLEKTIV GmbH <kontakt@netzkollektiv.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Netzkollektiv\EasyCredit\Logger;
  8. use Psr\Log\LogLevel;
  9. use Monolog\Handler\AbstractHandler;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\HttpKernel\KernelEvents;
  13. use Shopware\Core\PlatformRequest;
  14. use Netzkollektiv\EasyCredit\Setting\Service\SettingsServiceInterface;
  15. class LoggerConfigurator implements EventSubscriberInterface
  16. {
  17.     private SettingsServiceInterface $settings;
  18.     protected $requestStack;
  19.     private $handler;
  20.     public function __construct(
  21.         SettingsServiceInterface $settingsService,
  22.         RequestStack $requestStack,
  23.         AbstractHandler $handler
  24.     ) {
  25.         $this->settings $settingsService;
  26.         $this->requestStack $requestStack;
  27.         $this->handler $handler;
  28.     }
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             KernelEvents::CONTROLLER => [
  33.                 ['configureLoglevel'0],
  34.             ],
  35.         ];
  36.     }
  37.     public function configureLoglevel(): void
  38.     {
  39.         $request $this->requestStack->getCurrentRequest();
  40.         $salesChannelId null;
  41.         if ($request && $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID)) {
  42.             $salesChannelId $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);
  43.         }
  44.         if ($this->settings->getSettings($salesChannelIdfalse)->getDebug()) {
  45.             $this->handler->setLevel(LogLevel::DEBUG);
  46.         }
  47.     }
  48. }