3

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.