Guide
Technical / Architecture

Dependencies and Auto-Discovery

4min

The PHP-SDK is designed to be as interoperable as possible. As such, dependencies on third party libraries - especially where alternatives exist - is kept to a minimum, and required versions kept as loose as possible.

Existing Dependencies

Package

Details

php

ext-libxml ext-simplexml

XML handling libraries are required to process the response payload of some Klevu APIs

psr/log

Allows hooking in PSR-3 compliant logging

psr/http-client psr/http-message

Allows hooking in PSR-17 compliant HTTP factories and PSR-18 compliant HTTP clients to communicate with Klevu APIs

php-http/discovery

Provides auto-discovery functionality for compatible HTTP clients and factories already installed in your application

Auto-Discovery

HTTP Client, Request and Response Factories

In order to reduce installation time in applications which already have a PSR-18 compliant HTTP client, such as Guzzle, any class which needs to communicate with the Klevu APIs will attempt to automatically discover a suitable client for transport. This action occurs during object instantiation and will throw an exception if a class cannot be found. If your application uses a non-PSR-18 compliant library or PHP's curl functions directly, you will need to install or create a client which implements Psr\Http\Client\ClientInterface and ensure they are available to your autoloader.

The HTTP Discovery package will also attempt to locate factory classes responsible for creating PSR-17-compliant Request and Response objects. If your application does not contain these factories, you will need to install or create classes which implement Psr\Http\Message\RequestFactoryInterface and Psr\Http\Message\ResponseFactoryInterface and ensure they are available to your autoloader.

If automatic discovery cannot locate implementations of any of the above classes, or you wish to use a different class to the one found, all service classes will allow injection of the relevant classes through the constructor.

For more information and examples, please see the Configure HTTP Transport How-To article.

Logging

As logging is not an integral component of the SDK, it will not attempt auto-discovery for implementations of Psr\Log\LoggerInterface . In this scenario, no errors will be raised - logging will be silently skipped.

To enable logging, you should install or create an implementation of a PSR-3 compliant logger and inject it manually into the applicable classes.

For more information and examples, please see the Logging How-To article.