<commit_before><?php
/**
 * curlsoapclient - SoapClient with php-curl. -
 *
 * @author    aaharu
 * @copyright Copyright (c) 2014 aaharu
 * @license   MIT License
 */

namespace Aaharu\Soap;

/**
 * @see https://github.com/php/php-src/tree/master/ext/soap
 */
class CurlSoapClient extends \SoapClient
{
    protected $curl = null; ///< cURL handle
    protected $redirect_max; ///< max redirect counts
    protected $curl_timeout; ///< cURL request time-out seconds
    private $redirect_count = 0;
    private $curlopts = array();

    public function __construct($wsdl, array $options)
    {
        parent::__construct($wsdl, $options);
        $this->redirect_max = 5;
        if (isset($options['redirect_max'])) {
            $this->redirect_max = (int) $options['redirect_max'];
        }
        $this->curl_timeout = 30;
        if (isset($options['curl_timeout'])) {
            $this->curl_timeout = (int) $options['curl_timeout'];
        }
        $this->curl = curl_init();
    }

    public function __destruct()
    {
        if (isset($this->curl)) {
            curl_close($this->curl);
        }
    }

    public function ___curlSetOpt($option, $value)
    {
        curl_setopt($this->curl, $option, $value);
        $this->curlopts[$option] = $value;
    }

    public function __getCookies()
    {
        if (isset($this->_cookies)) {
            return $this->_cookies;
        }
        return null;
    }

    public function __setCookie($name, $value = null)
    {
        $this->_cookies = $name;
    }

    /**
     * Execute SOAP requests.
     *
     * @param[in] string $request SOAP request
     * @param[in] string $location SOAP address
     * @param[in] string $action SOAP action
     * @param[in] int $version SOAP version
     * @param[in] int $one_way
     * @return mixed (string) SOAP response / (object) SoapFault object
     */
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->curl, CURLOPT_HEADER, true);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $request);
        if (isset($this->trace) && $this->trace) {
            curl_setopt($this->curl, CURLINFO_HEADER_OUT, true);
        }

        $this->___configHeader($action, $version);
        $this->___configCompression();
        $this->___configTimeout();
        if (isset($this->_user_agent) && is_string($this->_user_agent) && strlen($this->_user_agent) > 0) {
            curl_setopt($this->curl, CURLOPT_USERAGENT, $this->_user_agent);
        }

        try {
            $response = $this->___curlCall($location);
        } catch (\SoapFault $fault) {
            if (isset($this->_exceptions) && empty($this->_exceptions)) {
                // if exceptions option is false, retrun \SoapFault object
                return $fault;
            }
            throw $fault;
        }

        return $response;
    }

    private function ___configHeader($action, $version)
    {
        $header = array();
        if (isset($this->_keep_alive) && empty($this->_keep_alive)) {
            $header[] = 'Connection: close';
        } else {<commit_msg>one_way<commit_after><?php
/**
 * curlsoapclient - SoapClient with php-curl. -
 *
 * @author    aaharu
 * @copyright Copyright (c) 2014 aaharu
 * @license   MIT License
 */

namespace Aaharu\Soap;

/**
 * @see https://github.com/php/php-src/tree/master/ext/soap
 */
class CurlSoapClient extends \SoapClient
{
    protected $curl = null; ///< cURL handle
    protected $redirect_max; ///< max redirect counts
    protected $curl_timeout; ///< cURL request time-out seconds
    private $redirect_count = 0;
    private $curlopts = array();

    public function __construct($wsdl, array $options)
    {
        parent::__construct($wsdl, $options);
        $this->redirect_max = 5;
        if (isset($options['redirect_max'])) {
            $this->redirect_max = (int) $options['redirect_max'];
        }
        $this->curl_timeout = 30;
        if (isset($options['curl_timeout'])) {
            $this->curl_timeout = (int) $options['curl_timeout'];
        }
        $this->curl = curl_init();
    }

    public function __destruct()
    {
        if (isset($this->curl)) {
            curl_close($this->curl);
        }
    }

    public function ___curlSetOpt($option, $value)
    {
        curl_setopt($this->curl, $option, $value);
        $this->curlopts[$option] = $value;
    }

    public function __getCookies()
    {
        if (isset($this->_cookies)) {
            return $this->_cookies;
        }
        return null;
    }

    public function __setCookie($name, $value = null)
    {
        $this->_cookies = $name;
    }

    /**
     * Execute SOAP requests.
     *
     * @param[in] string $request SOAP request
     * @param[in] string $location SOAP address
     * @param[in] string $action SOAP action
     * @param[in] int $version SOAP version
     * @param[in] int $one_way
     * @return mixed (string) SOAP response / (object) SoapFault object
     */
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->curl, CURLOPT_HEADER, true);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $request);
        if (isset($this->trace) && $this->trace) {
            curl_setopt($this->curl, CURLINFO_HEADER_OUT, true);
        }

        $this->___configHeader($action, $version);
        $this->___configCompression();
        $this->___configTimeout();
        if (isset($this->_user_agent) && is_string($this->_user_agent) && strlen($this->_user_agent) > 0) {
            curl_setopt($this->curl, CURLOPT_USERAGENT, $this->_user_agent);
        }

        try {
            $response = $this->___curlCall($location);
        } catch (\SoapFault $fault) {
            if (isset($this->_exceptions) && empty($this->_exceptions)) {
                // if exceptions option is false, retrun \SoapFault object
                return $fault;
            }
            throw $fault;
        }

        if ($one_way) {
            return '';
        }

        return $response;
    }

    private function ___configHeader($action, $version)
    {
        $header = array();
        if (isset($this->_keep_alive) && empty($this->_keep_alive)) {
            $header[] = 'Connection: close';
        } else {
{'fraction_non_alphanumeric': 0.1453812771233726, 'fraction_numerical': 0.0030998140111593306, 'mean_word_length': 2.309230769230769, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 67, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3588587', 'n_tokens_mistral': 2062, 'n_tokens_neox': 1942, 'n_words': 411}