Skip to content
Snippets Groups Projects
Select Git revision
  • db45845289abeedcd36067a242f1f835b4b811aa
  • master default protected
  • 1.2.3
  • 1.2.2
  • 1.2.1
  • 1.2.0
  • 1.1.0
  • 1.0.2
  • 1.0.1
  • 1.0
10 results

ClientFactory.php

Blame
  • ClientFactory.php 1022 B
    <?php
    
    namespace WPDesk\ApiClient\Client;
    
    use WPDesk\Cache\WordpressCache;
    use WPDesk\HttpClient\HttpClientFactory;
    use WPDesk\ApiClient\Serializer\SerializerFactory;
    
    class ClientFactory
    {
        /**
         * @param ApiClientOptions $options
         * @return Client
         */
        public function createClient(ApiClientOptions $options)
        {
            $httpClientFactory = new HttpClientFactory();
            $serializerFactory = new SerializerFactory();
    
            $className = $options->getApiClientClass();
    
            $client = new $className(
                $httpClientFactory->createClient($options),
                $serializerFactory->createSerializer($options),
                $options->getLogger(),
                $options->getApiUrl(),
                $options->getDefaultRequestHeaders(),
                ($options instanceof ApiClientOptionsTimeout)? $options->getTimeout(): null
            );
    
            if ($options->isCachedClient()) {
                $client = new CachedClient($client, new WordpressCache());
            }
    
            return $client;
        }
    }