vendor/ibexa/http-cache/src/lib/ProxyClient/HttpDispatcherFactory.php line 62

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\HttpCache\ProxyClient;
  8. use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\DynamicSettingParserInterface;
  9. use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
  10. class HttpDispatcherFactory
  11. {
  12. /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
  13. private $configResolver;
  14. /** @var \Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\DynamicSettingParserInterface */
  15. private $dynamicSettingParser;
  16. /** @var string */
  17. private $httpDispatcherClass;
  18. public function __construct(
  19. ConfigResolverInterface $configResolver,
  20. DynamicSettingParserInterface $dynamicSettingParser,
  21. string $httpDispatcherClass
  22. ) {
  23. $this->configResolver = $configResolver;
  24. $this->dynamicSettingParser = $dynamicSettingParser;
  25. $this->httpDispatcherClass = $httpDispatcherClass;
  26. }
  27. public function buildHttpDispatcher(array $servers, string $baseUrl = '')
  28. {
  29. $allServers = [];
  30. foreach ($servers as $server) {
  31. if (!$this->dynamicSettingParser->isDynamicSetting($server)) {
  32. $allServers[] = $server;
  33. continue;
  34. }
  35. $settings = $this->dynamicSettingParser->parseDynamicSetting($server);
  36. $configuredServers = $this->configResolver->getParameter(
  37. $settings['param'],
  38. $settings['namespace'],
  39. $settings['scope']
  40. );
  41. $allServers = array_merge($allServers, (array)$configuredServers);
  42. }
  43. if ($this->dynamicSettingParser->isDynamicSetting($baseUrl)) {
  44. $baseUrlSettings = $this->dynamicSettingParser->parseDynamicSetting($baseUrl);
  45. $baseUrl = $this->configResolver->getParameter(
  46. $baseUrlSettings['param'],
  47. $baseUrlSettings['namespace'],
  48. $baseUrlSettings['scope']
  49. );
  50. }
  51. return new $this->httpDispatcherClass($allServers, $baseUrl);
  52. }
  53. }
  54. class_alias(HttpDispatcherFactory::class, 'EzSystems\PlatformHttpCacheBundle\ProxyClient\HttpDispatcherFactory');