RetailCRM API Client

ClientFactory
in package
implements ClientFactoryInterface, EventDispatcherAwareInterface Uses EventDispatcherAwareTrait

Class ClientFactory.

ClientFactory will create any amount of clients with provided credentials. The cache will be used if it was provided before instantiating any client.

This factory should be instantiated using DI, like symfony/dependency-injection. Cache implementation can be injected during factory instantiation (it's optional, but should be used if you care about performance).

FormEncoder instance with all underlying dependencies and ResponseTransformer will be shared between Client instances. RequestTransformer with handlers pipeline will not be shared between clients because one of the handlers will be authenticator, which is supposed to be unique between Clients.

Service configuration example for Symfony (symfony/dependency-injection):

RetailCrm\Api\Interfaces\ClientFactoryInterface:
  class: 'RetailCrm\Api\Factory\ClientFactory'
  calls:
    - setCacheDir: ['%kernel.cache_dir%']
    - setEventDispatcher: ['@event_dispatcher']

You also can set a LoggerInterface instance for debug purposes:

RetailCrm\Api\Interfaces\ClientFactoryInterface:
  class: 'RetailCrm\Api\Factory\ClientFactory'
  calls:
    - setCacheDir: ['%kernel.cache_dir%']
    - setEventDispatcher: ['@event_dispatcher']
    - setDebugLogger: ['@logger']
Tags
category

ClientFactory

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Interfaces

ClientFactoryInterface
Interface ClientFactoryInterface
EventDispatcherAwareInterface
Interface EventDispatcherAwareInterface

Methods

appendRequestHandler()  : ClientFactory
Appends an additional request handler into the request processing chain.
appendRequestHandlers()  : ClientFactory
Appends additional request handlers into the request processing chain.
appendResponseHandler()  : ClientFactory
Appends an additional handler into the response processing chain.
appendResponseHandlers()  : ClientFactory
Appends additional response handlers into the response processing chain.
createClient()  : Client
Instantiates a new instance of Client.
setCache()  : ClientFactory
Sets cache implementation which will be used to store metadata cache.
setCacheDir()  : ClientFactory
Sets cache directory which will be used to store metadata cache.
setDebugLogger()  : ClientFactory
Sets debug logger
setEventDispatcher()  : object
Sets PSR-14 compatible event dispatcher. Useful if you want to handle specific errors in one place.
setHttpClient()  : ClientFactory
Set your PSR-18 HTTP client.
setRequestFactory()  : ClientFactory
Sets PSR-17 compatible request factory. You can skip this step if you want to use service discovery.
setStreamFactory()  : ClientFactory
Sets PSR-17 compatible stream factory. You can skip this step if you want to use service discovery.
setUriFactory()  : ClientFactory
Sets PSR-17 compatible URI factory. You can skip this step if you want to use service discovery.

Methods

createClient()

Instantiates a new instance of Client.

public createClient(string $apiUrl, string $apiKey) : Client
Parameters
$apiUrl : string
$apiKey : string
Tags
throws
BuilderException
Return values
Client

setCache()

Sets cache implementation which will be used to store metadata cache.

public setCache(CacheItemPoolInterface $cache) : ClientFactory
Parameters
$cache : CacheItemPoolInterface
Return values
ClientFactory

setCacheDir()

Sets cache directory which will be used to store metadata cache.

public setCacheDir(string $cacheDir) : ClientFactory
Parameters
$cacheDir : string
Return values
ClientFactory

setEventDispatcher()

Sets PSR-14 compatible event dispatcher. Useful if you want to handle specific errors in one place.

public setEventDispatcher(EventDispatcherInterface|null $eventDispatcher) : object
Parameters
$eventDispatcher : EventDispatcherInterface|null
Return values
object

setHttpClient()

Set your PSR-18 HTTP client.

public setHttpClient(ClientInterface $httpClient) : ClientFactory

Service discovery will be used if no client has been provided.

Parameters
$httpClient : ClientInterface
Return values
ClientFactory

setRequestFactory()

Sets PSR-17 compatible request factory. You can skip this step if you want to use service discovery.

public setRequestFactory(RequestFactoryInterface|null $requestFactory) : ClientFactory
Parameters
$requestFactory : RequestFactoryInterface|null
Return values
ClientFactory

setStreamFactory()

Sets PSR-17 compatible stream factory. You can skip this step if you want to use service discovery.

public setStreamFactory(StreamFactoryInterface|null $streamFactory) : ClientFactory
Parameters
$streamFactory : StreamFactoryInterface|null
Return values
ClientFactory

setUriFactory()

Sets PSR-17 compatible URI factory. You can skip this step if you want to use service discovery.

public setUriFactory(UriFactoryInterface|null $uriFactory) : ClientFactory
Parameters
$uriFactory : UriFactoryInterface|null
Return values
ClientFactory

        
On this page

Search results