Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor parameter prevents usage with php-http/discovery #1

Open
seebeen opened this issue Jan 31, 2025 · 0 comments
Open

Constructor parameter prevents usage with php-http/discovery #1

seebeen opened this issue Jan 31, 2025 · 0 comments

Comments

@seebeen
Copy link

seebeen commented Jan 31, 2025

In order to you your library with php-http/discovery, HandlerStack parameter in WpClient needs to be nullable because ClassDiscovery calls the constructor without parameters.

Set HandlerStack like this.

class WpClient {
    /**
     * Constructor.
     *
     * @param HandlerInterface  $handler The handler to use for dispatching requests and receiving responses.
     * @param UriInterface|null $baseUri Optional base URI for all relative requests sent using this client.
     *
     * @throws InvalidArgumentException If the "base_uri" option is present and is not a valid URI.
     */
    public function __construct( ?HandlerInterface $handler = null, ?UriInterface $baseUri = null ) {
        $this->handler = $handler ?? HandlerStack::CreateDefault();
        $this->baseUri = $baseUri;
    }
}

This make your http client compatible with the discovery library.

@seebeen seebeen changed the title Set default HandlerStack in constructor Constructor parameter prevents usage with php-http/discovery Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant