|
| 1 | +# FriendsOfPHP / Well-Known Implementations |
| 2 | + |
| 3 | +This package helps reduce the proliferation of same-abstraction implementations |
| 4 | +in vendor directories. |
| 5 | + |
| 6 | +It is targeted at SDK maintainers that write their code in a decoupled way but |
| 7 | +still need an actual implementation to provide a nice experience out of the box. |
| 8 | + |
| 9 | +Without this package, one would e.g. require the "php-http/client-implementation" |
| 10 | +virtual package to signal that a given SDK uses HTTPlug to make API calls, and |
| 11 | +would also require "php-http/guzzle7-adapter" to install an actual |
| 12 | +implementation in case none is wired by the consuming app when calling the SDK. |
| 13 | + |
| 14 | +But imagine that the consuming app already has a dependency on another |
| 15 | +"php-http/client-implementation": the SDK should ideally reuse that |
| 16 | +implementation and "php-http/guzzle7-adapter" should be removed from vendor/ with |
| 17 | +all its transitive dependencies. This would help with dependency-management and |
| 18 | +might enable better integration in debugging panels for example. |
| 19 | + |
| 20 | +By requiring "friendsofphp/well-known-implementations" instead of |
| 21 | +"php-http/guzzle7-adapter", SDK maintainers can provide ideal experiences: |
| 22 | +because this package is also a composer-plugin (*TODO*), it will auto-install an |
| 23 | +actual implementation of the required abstraction when none is already installed, |
| 24 | +or reuse it if one is found. |
| 25 | + |
| 26 | +In their constructors, SDKs should then reference the provided "well-known" |
| 27 | +classes and they will get whatever implementation is available: |
| 28 | + |
| 29 | +```php |
| 30 | +class MySdk |
| 31 | +{ |
| 32 | + public function __construct( |
| 33 | + private HttpClient $client = new WellKnownHttplugClient(), |
| 34 | + ) |
| 35 | + { |
| 36 | + // ... |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +As of now, the following abstractions are supported: |
| 42 | + - php-http/async-client-implementation |
| 43 | + - php-http/client-implementation |
| 44 | + - psr/http-client-implementation |
| 45 | + - psr/http-factory-implementation |
| 46 | + - psr/http-message-implementation |
| 47 | + |
| 48 | +And the following vendors are supported: |
| 49 | + - Guzzle |
| 50 | + - HTTPlug |
| 51 | + - Laminas |
| 52 | + - Nyholm |
| 53 | + - React |
| 54 | + - Slim |
| 55 | + - Symfony |
| 56 | + |
| 57 | +More abstractions / vendors can be added by contributions, e.g. for |
| 58 | +psr/log-implementation, psr/cache-implementation, psr/simple-cache-implementation. |
| 59 | + |
| 60 | +If your favorite SDK does not use this package yet, please let them know about it |
| 61 | +or better: the send them a PR! |
0 commit comments