<commit_before><?php

/**
 * Request
 * Abstraction class for request operations
 *
 * @version   1.0.0
 * @author    <NAME> <http://git.io/joseluisq>
 */
class Request {

  protected $load;
  protected $input;

  public function __construct($params) {
    $this->load = $params['load'];
    $this->input = $params['input'];
  }

  /**
   * Returns GET data
   * @param string $key
   * @return mixed
   */
  function get($key = NULL) {
    return $this->request_data('get', $key);
  }

  /**
   * Returns POST data
   * @param string $key
   * @return mixed
   */
  function post($key = NULL) {
    return $this->request_data('post', $key);
  }

  /**
   * Returns PUT data
   * @param string $key
   * @return mixed
   */
  function put($key = NULL) {
    return $this->request_data('put', $key);
  }

  /**
   * Returns DELETE data
   * @param string $key
   * @return mixed
   */
  function delete($key = NULL) {
    return $this->request_data('delete', $key);
  }

  /**
   * If GET request
   * @return bool
   */
  function is_get() {
    return ($this->method() === 'get');
  }

  /**
   * If POST request
   * @return bool
   */
  function is_post() {
    return ($this->method() === 'post');
  }

  /**
   * If PUT request
   * @return bool
   */
  function is_put() {
    return ($this->method() === 'put');
  }

  /**
   * If DELETE request
   * @return bool
   */
  function is_delete() {
    return ($this->method() === 'delete');
  }

  /**
   * Get HTTP data by specific methods
   * @param string $method GET, POST, PUT and DELETE 
   * @param mixed $key
   * @return mixed
   */
  private function request_data($method, $key = NULL) {
    $values = NULL;

    switch ($method) {
      case 'get':
        if ($this->is_get()) {
          $values = $this->input->get($key);
        }

        break;
      case 'post':
        if ($this->is_post()) {
          $values = $this->input->post($key);
        }

        break;
      case 'put':
        if ($this->is_put()) {
          $values = $this->raw_request_data();
          break;
        }

        break;
      case 'delete':
        if ($this->is_delete()) {
          $values = $this->raw_request_data($key);
        }

        break;
    }

    return $values;
  }

  /**
   * Get raw request data
   * @param mixed $key
   * @return mixed
   */
  private function raw_request_data($key) {
    $values = $this->parse_raw_http_request($key);

    if ($key) {
      $values = isset($values[$key]) ? $values[$key] : NULL;
    }

    return $values;
  }

  /**
   * Parse raw HTTP request data
   * http://www.chlab.ch/blog/archives/php/manually-parse-raw-http-data-php
   *
   * Pass in $a_data as an array. This is done by reference to avoid copying
   * the data around too much.
   *
   * Any files found in the request will be added by their field name to the
   * $data['files'] array.
   *
   * @param   array  Empty array to fill with data
   * @return  array  Associative array of request data
   */
  function parse_raw_http_request() {<commit_msg>Fixed raw_request_data method<commit_after><?php

/**
 * Request
 * Abstraction class for request operations
 *
 * @version   1.0.0
 * @author    <NAME> <http://git.io/joseluisq>
 */
class Request {

  protected $load;
  protected $input;

  public function __construct($params) {
    $this->load = $params['load'];
    $this->input = $params['input'];
  }

  /**
   * Returns GET data
   * @param string $key
   * @return mixed
   */
  function get($key = NULL) {
    return $this->request_data('get', $key);
  }

  /**
   * Returns POST data
   * @param string $key
   * @return mixed
   */
  function post($key = NULL) {
    return $this->request_data('post', $key);
  }

  /**
   * Returns PUT data
   * @param string $key
   * @return mixed
   */
  function put($key = NULL) {
    return $this->request_data('put', $key);
  }

  /**
   * Returns DELETE data
   * @param string $key
   * @return mixed
   */
  function delete($key = NULL) {
    return $this->request_data('delete', $key);
  }

  /**
   * If GET request
   * @return bool
   */
  function is_get() {
    return ($this->method() === 'get');
  }

  /**
   * If POST request
   * @return bool
   */
  function is_post() {
    return ($this->method() === 'post');
  }

  /**
   * If PUT request
   * @return bool
   */
  function is_put() {
    return ($this->method() === 'put');
  }

  /**
   * If DELETE request
   * @return bool
   */
  function is_delete() {
    return ($this->method() === 'delete');
  }

  /**
   * Get HTTP data by specific methods
   * @param string $method GET, POST, PUT and DELETE 
   * @param mixed $key
   * @return mixed
   */
  private function request_data($method, $key = NULL) {
    $values = NULL;

    switch ($method) {
      case 'get':
        if ($this->is_get()) {
          $values = $this->input->get($key);
        }

        break;
      case 'post':
        if ($this->is_post()) {
          $values = $this->input->post($key);
        }

        break;
      case 'put':
        if ($this->is_put()) {
          $values = $this->raw_request_data($key);
          break;
        }

        break;
      case 'delete':
        if ($this->is_delete()) {
          $values = $this->raw_request_data($key);
        }

        break;
    }

    return $values;
  }

  /**
   * Get raw request data
   * @param mixed $key
   * @return mixed
   */
  private function raw_request_data($key) {
    $values = $this->parse_raw_http_request();

    if (!empty($key)) {
      $values = isset($values[$key]) ? $values[$key] : NULL;
    }

    return $values;
  }

  /**
   * Parse raw HTTP request data
   * http://www.chlab.ch/blog/archives/php/manually-parse-raw-http-data-php
   *
   * Pass in $a_data as an array. This is done by reference to avoid copying
   * the data around too much.
   *
   * Any files found in the request will be added by their field name to the
   * $data['files'] array.
   *
   * @param   array  Empty array to fill with data
   * @return  array  Associative array of request data
   */
  function parse_raw_http_request() {
{'fraction_non_alphanumeric': 0.15921787709497207, 'fraction_numerical': 0.000985869208018403, 'mean_word_length': 2.1785900783289818, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5428831', 'n_tokens_mistral': 2043, 'n_tokens_neox': 1992, 'n_words': 524}