ConfigServiceProvider.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare(strict_types=1);
  3. namespace Yansongda\Artful\Service;
  4. use Yansongda\Artful\Artful;
  5. use Yansongda\Artful\Contract\ConfigInterface;
  6. use Yansongda\Artful\Contract\ServiceProviderInterface;
  7. use Yansongda\Artful\Exception\ContainerException;
  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.artful',
  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/artful-v1',
  25. ],
  26. ],
  27. ];
  28. /**
  29. * @throws ContainerException
  30. */
  31. public function register(mixed $data = null): void
  32. {
  33. $config = new Config(array_replace_recursive($this->config, $data ?? []));
  34. Artful::set(ConfigInterface::class, $config);
  35. }
  36. }