Overload symfony2 vendor class to set curl verify_

2019-08-02 12:23发布

问题:

Using the Payum bundle with symfony2, I have the common unable to verify ssl certificate error.

I couldn't get rid of it by changing curl options in php.ini or by setting curl options in my php code.

However, modifying the vendor/kriswallsmith/buzz/lib/Buzz/Client/AbstractClient.php class and setting the default $verifyPeer option to false finally allows me to use Payum and PayPal express checkout locally with wamp.

EDIT: I can also override this class which uses the other one. I feel it's safer:

vendor/payum/core/Payum/Core/Bridge/Buzz/ClientFactory.php

How can I override this class (ideally conditionally ie in dev mode when I'm working locally) ?

回答1:

You can overwrite the service payum.buzz.client. Just define it in your bundle which is registered after PayumBundle.

<service id="payum.buzz.client" class="Buzz\Client\ClientInterface"     factory-class="Payum\Core\Bridge\Buzz\ClientFactory" factory- method="createCurl">
        <call method="setVerifyPeer">
            <argument>false</argument>
        </call>
</service>

or in yml

services:
    payum.buzz.client:
        class: Buzz\Client\ClientInterface
        factory_class: Payum\Core\Bridge\Buzz\ClientFactory
        factory_method: createCurl
        calls:
            - [setVerifyPeer, [false]]