To use external libraries that employ contracts based on PSR recommendations, you may need to convert your own framework entities into the appropriate PSR objects.
Due to the framework's principle of self-sufficiency and initial rejection of external dependencies, the framework's system classes are similar to standard ones, but have their own interface. To adhere to the standards, this is addressed by using the Converter adapter, implemented as a Service.
The Converter service provides methods to obtain objects according to PSR interfaces, derived from the system objects of the HLEB2 framework.
Methods of using Converter in controllers (and all classes inherited from Hleb\Base\Container) exemplified by retrieving an object for logging using PSR-3:
Example of retrieving a logger object from the Converter service within application code:
The Converter service can also be obtained through dependency injection via the interface Hleb\Reference\Interface\Converter.
The toPsr3Logger() method returns a logging object with the PSR-3 interface (Psr\Log\LoggerInterface).
The toPsr11Container() method returns a container object with the PSR-11 interface (Psr\Container\ContainerInterface).
The toPsr16SimpleCache() method returns a caching object with the PSR-16 interface (Psr\SimpleCache\CacheInterface).
There are a sufficient number of third-party libraries for handling PSR-7 objects, so including another implementation in the framework is unnecessary. For example, they can be created using the popular Nyholm\Psr7 library:
The set of parameters in the constructor depends on the chosen library.
To avoid initializing this way each time, the implementation can be delegated to a separate class or service.