LoggerServiceProvider.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. declare(strict_types=1);
  3. namespace Yansongda\Pay\Service;
  4. use Yansongda\Pay\Contract\ConfigInterface;
  5. use Yansongda\Pay\Contract\LoggerInterface;
  6. use Yansongda\Pay\Contract\ServiceProviderInterface;
  7. use Yansongda\Pay\Exception\ContainerException;
  8. use Yansongda\Pay\Exception\ServiceNotFoundException;
  9. use Yansongda\Pay\Pay;
  10. use Yansongda\Supports\Logger;
  11. class LoggerServiceProvider implements ServiceProviderInterface
  12. {
  13. /**
  14. * @param mixed $data
  15. *
  16. * @throws ContainerException
  17. * @throws ServiceNotFoundException
  18. */
  19. public function register($data = null): void
  20. {
  21. /* @var ConfigInterface $config */
  22. $config = Pay::get(ConfigInterface::class);
  23. if (class_exists(\Monolog\Logger::class) && true === $config->get('logger.enable', false)) {
  24. $logger = new Logger(array_merge(
  25. ['identify' => 'yansongda.pay'],
  26. $config->get('logger', [])
  27. ));
  28. Pay::set(LoggerInterface::class, $logger);
  29. }
  30. }
  31. }