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
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
appendRequestHandler()
Appends an additional request handler into the request processing chain.
public
appendRequestHandler(HandlerInterface $handler) : ClientFactory
Parameters
- $handler : HandlerInterface
Return values
ClientFactoryappendRequestHandlers()
Appends additional request handlers into the request processing chain.
public
appendRequestHandlers(array<string|int, HandlerInterface> $handlers) : ClientFactory
Parameters
- $handlers : array<string|int, HandlerInterface>
Return values
ClientFactoryappendResponseHandler()
Appends an additional handler into the response processing chain.
public
appendResponseHandler(HandlerInterface $handler) : ClientFactory
Parameters
- $handler : HandlerInterface
Return values
ClientFactoryappendResponseHandlers()
Appends additional response handlers into the response processing chain.
public
appendResponseHandlers(array<string|int, HandlerInterface> $handlers) : ClientFactory
Parameters
- $handlers : array<string|int, HandlerInterface>
Return values
ClientFactorycreateClient()
Instantiates a new instance of Client.
public
createClient(string $apiUrl, string $apiKey) : Client
Parameters
- $apiUrl : string
- $apiKey : string
Tags
Return values
ClientsetCache()
Sets cache implementation which will be used to store metadata cache.
public
setCache(CacheItemPoolInterface $cache) : ClientFactory
Parameters
- $cache : CacheItemPoolInterface
Return values
ClientFactorysetCacheDir()
Sets cache directory which will be used to store metadata cache.
public
setCacheDir(string $cacheDir) : ClientFactory
Parameters
- $cacheDir : string
Return values
ClientFactorysetDebugLogger()
Sets debug logger
public
setDebugLogger(LoggerInterface $debugLogger) : ClientFactory
Parameters
- $debugLogger : LoggerInterface
Return values
ClientFactorysetEventDispatcher()
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
objectsetHttpClient()
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
ClientFactorysetRequestFactory()
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
ClientFactorysetStreamFactory()
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
ClientFactorysetUriFactory()
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