Reputation: 3386
I'm writing a new composer.json file for a project so that it can be available or Packagist or direct reference to its GitHub repo. The project requires either one or both of the HTTP client extensions, pecl_http
or curl
. If I specify both of the packages under require
, Composer will give an error if both are not installed.
How can I tell Composer it's okay to have just one of those two extensions installed?
Upvotes: 3
Views: 327
Reputation: 70933
You cannot define it in a way that you only need one of these extensions, but make Composer fail if none are present.
The usual way for packages is to mention extensions as "suggest". Your code already has to deal with detecting which extension is present and select the correct code path, it's no additional problem to emit an error if all are missing.
Alternatively, have two packages with their dependency exactly on one extension. Or have a main package on top of that which suggests the two implementation packages and makes it clear via it's interface that the developer has to provide at least one implementation.
On the other hand: Dealing with HTTP stuff looks like you should probably rely on PSR-7 interfaces, and let the developer choose the HTTP client implementation to use.
Upvotes: 1