ConfigServiceProvider.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. namespace Yansongda\Pay\Service;
  4. use Yansongda\Pay\Contract\ConfigInterface;
  5. use Yansongda\Pay\Contract\ServiceProviderInterface;
  6. use Yansongda\Pay\Exception\ContainerException;
  7. use Yansongda\Pay\Pay;
  8. use Yansongda\Supports\Config;
  9. class ConfigServiceProvider implements ServiceProviderInterface
  10. {
  11. private array $config = [
  12. 'logger' => [
  13. 'enable' => false,
  14. 'file' => null,
  15. 'identify' => 'yansongda.pay',
  16. 'level' => 'debug',
  17. 'type' => 'daily',
  18. 'max_files' => 30,
  19. ],
  20. 'http' => [
  21. 'timeout' => 5.0,
  22. 'connect_timeout' => 3.0,
  23. 'headers' => [
  24. 'User-Agent' => 'yansongda/pay-v3',
  25. ],
  26. ],
  27. 'mode' => Pay::MODE_NORMAL,
  28. ];
  29. /**
  30. * @param mixed $data
  31. *
  32. * @throws ContainerException
  33. */
  34. public function register($data = null): void
  35. {
  36. $config = new Config(array_replace_recursive($this->config, $data ?? []));
  37. Pay::set(ConfigInterface::class, $config);
  38. }
  39. }