eZ\Bundle\EzPublishCoreBundle\Cache\Http\VarnishProxyClientFactory::buildProxyClient PHP Метод

buildProxyClient() публичный Метод

Builds the proxy client, taking dynamically defined servers into account.
public buildProxyClient ( array $servers, string $baseUrl ) : FOS\HttpCache\ProxyClient\Varnish
$servers array
$baseUrl string
Результат FOS\HttpCache\ProxyClient\Varnish
    public function buildProxyClient(array $servers, $baseUrl)
    {
        $allServers = array();
        foreach ($servers as $server) {
            if (!$this->dynamicSettingParser->isDynamicSetting($server)) {
                $allServers[] = $server;
                continue;
            }
            $settings = $this->dynamicSettingParser->parseDynamicSetting($server);
            $configuredServers = $this->configResolver->getParameter($settings['param'], $settings['namespace'], $settings['scope']);
            $allServers = array_merge($allServers, (array) $configuredServers);
        }
        $class = $this->proxyClientClass;
        return new $class($allServers, $baseUrl);
    }

Usage Example

 public function testBuildProxyClientWithDynamicSettings()
 {
     $servers = array('$http_cache.purge_servers$', 'http://varnish2');
     $configuredServers = array('http://varnishconfigured1', 'http://varnishconfigured2');
     $expectedServers = array('http://varnishconfigured1', 'http://varnishconfigured2', 'http://varnish2');
     $baseUrl = 'http://phoenix-rises.fm/rapmm';
     $this->configResolver->expects($this->once())->method('getParameter')->with('http_cache.purge_servers')->will($this->returnValue($configuredServers));
     $proxyClient = $this->factory->buildProxyClient($servers, $baseUrl);
     $this->assertInstanceOf($this->proxyClientClass, $proxyClient);
     $refProxy = new ReflectionObject($proxyClient);
     $refServers = $refProxy->getParentClass()->getProperty('servers');
     $refServers->setAccessible(true);
     $this->assertSame($expectedServers, $refServers->getValue($proxyClient));
 }
VarnishProxyClientFactory