Download the PHP package psr-discovery/discovery without Composer
On this page you can find all versions of the php package psr-discovery/discovery. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download psr-discovery/discovery
More information about psr-discovery/discovery
Files in psr-discovery/discovery
Package discovery
Short Description Lightweight library that discovers available PSR implementations by searching for a list of well-known classes that implement the relevant interfaces, and returning an instance of the first one that is found.
License MIT
Homepage https://github.com/psr-discovery/discovery
Informations about the package discovery
Lightweight library that discovers available PSR implementations by searching for a list of well-known classes that implement the relevant interfaces, and returning an instance of the first one that is found.
The library currently supports PSR-18 HTTP Clients, PSR-17 HTTP Factories, PSR-14 Event Dispatchers, PSR-11 Containers, PSR-6 Caches and PSR-3 Logs.
This is largely intended for inclusion in libraries like SDKs that wish to support PSR interfaces without requiring hard dependencies on specific implementations or demanding extra configuration by users.
- Requirements
- Installation
- Meta-Packages
- PSR-18 HTTP Clients
- PSR-17 HTTP Factories
- PSR-14 Event Dispatchers
- PSR-11 Containers
- PSR-6 Caches
- PSR-3 Logs
- Handling Failures
- Exceptions
- Singletons
- Mocking Priority
- Preferring an Implementation
- Using a Specific Implementation
Requirements
- PHP 8.1+
- Composer 2.0+
The discovery of a particular interface requires the presence of a compatible implementation in the host application. This library does not install any implementations for you.
Installation
You should install the appropriate dependencies from the list below for the PSRs you wish to have discovery support for.
Meta-Packages
The psr-discovery/all meta-package includes all of the discovery suite packages. If you're looking for an all-in-one solution, this is the one you want.
Installation:
See the following sections for more information on the individual usage of each package.
PSR-18 HTTP Clients
Installation:
Usage:
Please see the psr-discovery/http-client-implementations repository for a list of the supported implementations. If a particular implementation is missing you'd like to see, please open a pull request adding support.
PSR-17 HTTP Factories
Installation:
Usage:
Please see the psr-discovery/http-factory-implementations repository for a list of the supported implementations. If a particular implementation is missing you'd like to see, please open a pull request adding support.
PSR-14 Event Dispatchers
Installation:
Usage:
Please see the psr-discovery/event-dispatcher-implementations repository for a list of the supported implementations. If a particular implementation is missing you'd like to see, please open a pull request adding support.
PSR-11 Containers
Installation:
Usage:
Please see the psr-discovery/container-implementations repository for a list of the supported implementations. If a particular implementation is missing you'd like to see, please open a pull request adding support.
PSR-6 Caches
Installation:
Usage:
Please see the psr-discovery/cache-implementations repository for a list of the supported implementations. If a particular implementation is missing you'd like to see, please open a pull request adding support.
PSR-3 Logs
Installation:
Usage:
Please see the psr-discovery/log-implementations repository for a list of the supported implementations. If a particular implementation is missing you'd like to see, please open a pull request adding support.
Handling Failures
If the library is unable to discover a suitable implementation, the relevant discovery method will simply return null
. This allows you to handle the failure gracefully, for example by falling back to a default implementation.
Example:
Exceptions
The library will expose a PsrDiscovery\Exceptions\SupportPackageNotFoundException
when a discovery method is called, but the required support package is not installed.
Singletons
By default, the discovery methods will always return a new instance of the discovered implementation. If you wish to use a singleton instance instead, simply pass true
to the $singleton
parameter of the discovery method.
Example:
Mocking Priority
This library will give priority to searching for an available PSR mocking library, like psr-mock/http-client-implementation
or php-http/mock-client
.
The expectation is that these mocking libraries will always be installed as development dependencies, and therefore if they are available, they are intended to be used.
Preferring an Implementation
If you wish to prefer a specific implementation over others, you can use the prefer()
on any installed discovery support libraries.
Example using psr-discovery/http-factories-implementations
:
This will cause the discovery method to return the preferred implementation if it is available, otherwise, it will fall back to the default behavior.
Note that assigning a preferred implementation will give it priority over the default preference of mocking libraries.
Using a Specific Implementation
If you wish to force a specific implementation and ignore the rest of the discovery candidates, you can use the use()
on any installed discovery support libraries.
Example using psr-discovery/http-factories-implementations
:
This will cause the discovery method to return the preferred implementation if it is available, otherwise, it will return null
.
This library is not produced or endorsed by, or otherwise affiliated with, the PHP-FIG.