smalot / cups-ipp

CUPS Implementation of IPP - PHP Client API
GNU General Public License v2.0
107 stars 56 forks source link

Problem with SocketHttpClient constructor in src/Transport/Client.php #30

Open wash34000 opened 3 years ago

wash34000 commented 3 years ago

Hello,

I found a problem when I wanted to connect to a print server using HTTPS and a self-signed certificate.

        $client = new Client("printer", "edsfsdfgdsfdsfgdsfg", [
            "remote_socket" => "XXX.XXX.XXX.XXX:631",
            "ssl" => true,
            'stream_context_options' => [
                'ssl' => [
                    'allow_self_signed' => false,
                    'verify_peer' => false,
                    'verify_peer_name' => false
                ]
            ],
        ]);

My stream_context_optionsparameters was not working.

I found the solution in file /src/Transport/Client.php on line 73 : $socketClient = new SocketHttpClient($messageFactory, $socketClientOptions); replaced by : $socketClient = new SocketHttpClient($messageFactory, null, $socketClientOptions);

because the SocketHttpClient constructor is :

    /**
     * Constructor.
     *
     * @param array $config {
     *
     *    @var string $remote_socket          Remote entrypoint (can be a tcp or unix domain address)
     *    @var int    $timeout                Timeout before canceling request
     *    @var array  $stream_context_options Context options as defined in the PHP documentation
     *    @var array  $stream_context_param   Context params as defined in the PHP documentation
     *    @var bool   $ssl                    Use ssl, default to scheme from request, false if not present
     *    @var int    $write_buffer_size      Buffer when writing the request body, defaults to 8192
     *    @var int    $ssl_method             Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
     * }
     */
    public function __construct($config1 = [], $config2 = null, array $config = [])
    {
        if (\is_array($config1)) {
            $this->config = $this->configure($config1);

            return;
        }

        @trigger_error('Passing a Psr\Http\Message\ResponseFactoryInterface and a Psr\Http\Message\StreamFactoryInterface to SocketClient is deprecated, and will be removed in 3.0, you should only pass config options.', E_USER_DEPRECATED);

        $this->config = $this->configure($config);
    }

Kind regards