Jarves\Configuration\SystemConfig::getClient PHP Method

getClient() public method

public getClient ( boolean $orCreate = false ) : Client
$orCreate boolean creates the value of not exists.
return Client
    public function getClient($orCreate = false)
    {
        if ($orCreate && null === $this->client) {
            $this->client = new Client(null, $this->getJarves());
        }
        return $this->client;
    }

Usage Example

Beispiel #1
0
    public function testSystemConfigClient()
    {
        $xml = '<config>
  <client service="vendor.custom.client_handling">
    <options>
      <option key="server">127.0.0.1</option>
      <option key="cert">false</option>
    </options>
    <sessionStorage service="vendor.own.storage"/>
  </client>
</config>';
        $config = new SystemConfig();
        $client = new Client();
        $client->setService('vendor.custom.client_handling');
        $client->setOption('server', '127.0.0.1');
        $client->setOption('cert', 'false');
        $config->setClient($client);
        $sessionStorage = new SessionStorage();
        $sessionStorage->setService('vendor.own.storage');
        $client->setSessionStorage($sessionStorage);
        $this->assertEquals($xml, $config->toXml());
        $reverse = new SystemConfig($xml);
        $this->assertInstanceOf('Jarves\\Configuration\\Client', $reverse->getClient());
        $this->assertEquals('vendor.custom.client_handling', $reverse->getClient()->getService());
        $this->assertEquals('127.0.0.1', $reverse->getClient()->getOption('server'));
        $this->assertEquals('false', $reverse->getClient()->getOption('cert'));
        $this->assertInstanceOf('Jarves\\Configuration\\SessionStorage', $reverse->getClient()->getSessionStorage());
        $this->assertEquals('vendor.own.storage', $reverse->getClient()->getSessionStorage()->getService());
        $this->assertEquals($xml, $reverse->toXml());
    }