ApplicationFactory.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Nacos;
  12. use Hyperf\Contract\ConfigInterface;
  13. use Psr\Container\ContainerInterface;
  14. class ApplicationFactory
  15. {
  16. public function __invoke(ContainerInterface $container)
  17. {
  18. $config = $container->get(ConfigInterface::class)->get('nacos', []);
  19. if (! empty($config['uri'])) {
  20. $baseUri = $config['uri'];
  21. } else {
  22. $baseUri = sprintf('http://%s:%d', $config['host'] ?? '127.0.0.1', $config['port'] ?? 8848);
  23. }
  24. return new Application(new Config([
  25. 'base_uri' => $baseUri,
  26. 'username' => $config['username'] ?? null,
  27. 'password' => $config['password'] ?? null,
  28. 'access_key' => $config['access_key'] ?? null,
  29. 'access_secret' => $config['access_secret'] ?? null,
  30. 'guzzle_config' => $config['guzzle']['config'] ?? null,
  31. 'host' => $config['host'] ?? null,
  32. 'port' => $config['port'] ?? null,
  33. ]));
  34. }
  35. }