<commit_before><?php

namespace Bruno\AdobeConnectClient;

/**
 * The Request to the Server
 *
 * Handler the Request and get the response in \SimpleXMLElement format.
 *
 * @todo Improve the Exceptions including better messages
 */
class RequestHandler
{
    const STATUS_OK = 'ok';

    /**
     * @var string Host
     */
    protected $host;

    /**
     * @var array Parameters to attach with the action
     */
    protected $params;

    /**
     * @var array cURL Options
     */
    protected $curlOptions = [];

    /**
     * Create a new Request Handler
     *
     * @param string $host
     * @param array $curlOptions An array with key is a CURLOPT_* constant.
     */
    public function __construct($host, array $curlOptions = [])
    {
        $this->host = $host;
        $this->setCurlOptions($curlOptions);
    }

    /**
     * The Host URL
     *
     * @return string
     */
    public function getHostUrl()
    {
        return $this->host;
    }

    /**
     * Set the cURL Options
     * @param array $curlOptions An array with key is a CURLOPT_* constant.
     */
    public function setCurlOptions(array $curlOptions)
    {
        $defaults = [
            CURLOPT_CONNECTTIMEOUT => 120,
            CURLOPT_TIMEOUT => 120,
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_SSL_VERIFYPEER => true,
            CURLOPT_SSL_VERIFYHOST => 2,
        ];
        $this->curlOptions = $curlOptions + $defaults;
        $this->curlOptions[CURLOPT_RETURNTRANSFER] = true;
        $this->curlOptions[CURLOPT_FOLLOWLOCATION] = true;
    }

    /**
     *
     * @param string $field
     * @param mixed $value
     */
    public function addParam($field, $value)
    {
        $this->params[$field] = $value;
    }

    public function setParams(array $params)
    {
        $this->params = $params;
    }

    public function clearParams()
    {
        $this->params = [];
    }

    /**
     * Get the Response from the server.
     * @param boolean $withHeader If true return with the HTTP Header
     * @return \SimpleXMLElement
     */
    public function getResponse($withHeader = false)
    {
        $result = $this->getWebServiceResponse($withHeader);

        $response = $withHeader
            ? $this->createResponseWithHeader($result)
            : $this->createResponseWithoutHeader($result);

        if (self::STATUS_OK != (string) $response->status->attributes()->code) {
            unset($response);
            throw new \Exception('Action with invalid response.');
        }
        return $response;
    }

    /**
     * Get the Final URL
     *
     * @return string
     */
    public function __toString()
    {
        return $this->getURL();
    }

    /**
     * Mount the URI
     */
    protected function getURI()
    {
        return http_build_query($this->params, '', '&');
    }<commit_msg>Documentation for the new methods<commit_after><?php

namespace Bruno\AdobeConnectClient;

/**
 * The Request to the Server
 *
 * Handler the Request and get the response in \SimpleXMLElement format.
 *
 * @todo Improve the Exceptions including better messages
 */
class RequestHandler
{
    const STATUS_OK = 'ok';

    /**
     * @var string Host
     */
    protected $host;

    /**
     * @var array Parameters to attach with the action
     */
    protected $params;

    /**
     * @var array cURL Options
     */
    protected $curlOptions = [];

    /**
     * Create a new Request Handler
     *
     * @param string $host
     * @param array $curlOptions An array with key is a CURLOPT_* constant.
     */
    public function __construct($host, array $curlOptions = [])
    {
        $this->host = $host;
        $this->setCurlOptions($curlOptions);
    }

    /**
     * The Host URL
     *
     * @return string
     */
    public function getHostUrl()
    {
        return $this->host;
    }

    /**
     * Set the cURL Options
     *
     * @param array $curlOptions An array with key is a CURLOPT_* constant.
     */
    public function setCurlOptions(array $curlOptions)
    {
        $defaults = [
            CURLOPT_CONNECTTIMEOUT => 120,
            CURLOPT_TIMEOUT => 120,
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_SSL_VERIFYPEER => true,
            CURLOPT_SSL_VERIFYHOST => 2,
        ];
        $this->curlOptions = $curlOptions + $defaults;
        $this->curlOptions[CURLOPT_RETURNTRANSFER] = true;
        $this->curlOptions[CURLOPT_FOLLOWLOCATION] = true;
    }

    /**
     * Add one Paramameter
     *
     * @param string $field
     * @param mixed $value
     */
    public function addParam($field, $value)
    {
        $this->params[$field] = $value;
    }

    /**
     * Set all Parameters
     *
     * @param array $params An array with the field in the key.
     */
    public function setParams(array $params)
    {
        $this->params = $params;
    }

    /**
     * Clear all Parameters
     */
    public function clearParams()
    {
        $this->params = [];
    }

    /**
     * Get the Response from the server.
     *
     * @param boolean $withHeader If true return with the HTTP Header
     * @return \SimpleXMLElement
     */
    public function getResponse($withHeader = false)
    {
        $result = $this->getWebServiceResponse($withHeader);

        $response = $withHeader
            ? $this->createResponseWithHeader($result)
            : $this->createResponseWithoutHeader($result);

        if (self::STATUS_OK != (string) $response->status->attributes()->code) {
            unset($response);
            throw new \Exception('Action with invalid response.');
        }
        return $response;
    }

    /**
     * Get the Final URL
     *
     * @return string
     */
    public function __toString()
    {
        return $this->getURL();
    }

    /**
     * Get the URI
     */
    protected function getURI()
    {
        return http_build_query($this->params, '', '&');
    }
{'fraction_non_alphanumeric': 0.11732973701955496, 'fraction_numerical': 0.0030343897505057315, 'mean_word_length': 1.9694694694694694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, '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': '7424187', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1694, 'n_words': 438}