HttpServiceProvider.php 904 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. namespace Yansongda\Pay\Service;
  4. use GuzzleHttp\Client;
  5. use Yansongda\Pay\Contract\ConfigInterface;
  6. use Yansongda\Pay\Contract\HttpClientInterface;
  7. use Yansongda\Pay\Contract\ServiceProviderInterface;
  8. use Yansongda\Pay\Exception\ContainerException;
  9. use Yansongda\Pay\Exception\ServiceNotFoundException;
  10. use Yansongda\Pay\Pay;
  11. use Yansongda\Supports\Config;
  12. class HttpServiceProvider implements ServiceProviderInterface
  13. {
  14. /**
  15. * @param mixed $data
  16. *
  17. * @throws ContainerException
  18. * @throws ServiceNotFoundException
  19. */
  20. public function register($data = null): void
  21. {
  22. /* @var Config $config */
  23. $config = Pay::get(ConfigInterface::class);
  24. if (class_exists(Client::class)) {
  25. $service = new Client($config->get('http', []));
  26. Pay::set(HttpClientInterface::class, $service);
  27. }
  28. }
  29. }