<commit_before><?php
/**
 * Request
 *
 * @author     <NAME> <<EMAIL>>
 * @copyright  2016 <NAME>
 */

namespace Arvici\Heart\Http;
use Arvici\Heart\Collections\DataCollection;
use Arvici\Heart\Collections\ParameterCollection;
use Arvici\Heart\Collections\ServerCollection;

/**
 * Request Handler
 *
 * @package Arvici\Heart\Http
 *
 * @api
 */
class Request
{
    /** @var string $unique Unique Request ID */
    protected $unique;

    /** @var string $base Base URL. */
    protected $base;
    /** @var ParameterCollection $getParams Get Parameters (query params) */
    protected $getParams;
    /** @var ParameterCollection $postParams Post parameters */
    protected $postParams;
    /** @var ParameterCollection $cookies Cookies */
    protected $cookies;
    /** @var ServerCollection $server Server */
    protected $server;
    /** @var DataCollection $headers Headers */
    protected $headers;
    /** @var array $body Body */
    protected $body;
    /** @var DataCollection $files Files */
    protected $files;

    /** @var Session $session */
    protected $session;

    /**
     * Request constructor.
     *
     * @param array $get
     * @param array $post
     * @param array $cookies
     * @param array $server
     * @param array $files
     * @param string $body
     * @param null $base
     * @param null|Session $session
     */
    public function __construct(
        array $get = array(),
        array $post = array(),
        array $cookies = array(),
        array $server = array(),
        array $files = array(),
        $body = null,
        $base = null,
        $session = null
    )
    {
        $this->getParams = new ParameterCollection($get);
        $this->postParams = new ParameterCollection($post);
        $this->cookies = new ParameterCollection($cookies);
        $this->server = new ServerCollection($server);
        $this->headers = new DataCollection($this->server->getHeaders());
        $this->files = new DataCollection($files);
        $this->body = is_string($body) ? $body : null;
        $this->base = $base;
        $this->session = $session;
    }

    /**
     * Detect from globals
     * @param Session $session
     * @return Request
     */
    public static function detect($session)
    {
        return new self ($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, null, null, $session);
    }

    /**
     * Get unique identifier for request
     *
     * @return string Unique String Identifier.
     */
    public function unique()
    {
        if ($this->unique === null) {
            $this->unique = uniqid();
        }
        return $this->unique;
    }

    /**
     * Search for parameter value
     * ORDER:
     *  - GET
     *  - POST
     *
     * @param string $key
     * @param mixed $default Default value when not found. Default null.
     *
     * @return mixed
     */
    public function param($key, $default = null)
    {
        if ($this->getParams->exists($key)) {
            return $this->getParams->get($key);
        }
        if ($this->postParams->exists($key)) {
            return $this->postParams->get($key);
        }

        return $default;
    }

    /**
     * Search for parameter value in GET query.
     *
     * @param string $key
     * @param mixed $default Default value when not found. Default null.
     *
     * @return mixed
     */
    public function paramGet($key, $default = null)
    {
        return $this->getParams->get($key, $default);
    }

    /**
     * Search for parameter value in POST array.
     *
     * @param string $key
     * @param mixed $default Default value when not found. Default null.
     *
     * @return mixed
     */
    public function paramPost($key, $default = null)
    {
        return $this->postParams->get($key, $default);
    }

    /**
     * Return the GET collection
     *
     * @return ParameterCollection
     */
    public function get()
    {
        return $this->getParams;
    }

    /**
     * Returns the POST collection
     *
     * @return ParameterCollection
     */
    public function post()
    {
        return $this->postParams;
    }

    /**<commit_msg>Add files getter to request.<commit_after><?php
/**
 * Request
 *
 * @author     <NAME> <<EMAIL>>
 * @copyright  2016 <NAME>
 */

namespace Arvici\Heart\Http;
use Arvici\Heart\Collections\DataCollection;
use Arvici\Heart\Collections\ParameterCollection;
use Arvici\Heart\Collections\ServerCollection;

/**
 * Request Handler
 *
 * @package Arvici\Heart\Http
 *
 * @api
 */
class Request
{
    /** @var string $unique Unique Request ID */
    protected $unique;

    /** @var string $base Base URL. */
    protected $base;
    /** @var ParameterCollection $getParams Get Parameters (query params) */
    protected $getParams;
    /** @var ParameterCollection $postParams Post parameters */
    protected $postParams;
    /** @var ParameterCollection $cookies Cookies */
    protected $cookies;
    /** @var ServerCollection $server Server */
    protected $server;
    /** @var DataCollection $headers Headers */
    protected $headers;
    /** @var array $body Body */
    protected $body;
    /** @var DataCollection $files Files */
    protected $files;

    /** @var Session $session */
    protected $session;

    /**
     * Request constructor.
     *
     * @param array $get
     * @param array $post
     * @param array $cookies
     * @param array $server
     * @param array $files
     * @param string $body
     * @param null $base
     * @param null|Session $session
     */
    public function __construct(
        array $get = array(),
        array $post = array(),
        array $cookies = array(),
        array $server = array(),
        array $files = array(),
        $body = null,
        $base = null,
        $session = null
    )
    {
        $this->getParams = new ParameterCollection($get);
        $this->postParams = new ParameterCollection($post);
        $this->cookies = new ParameterCollection($cookies);
        $this->server = new ServerCollection($server);
        $this->headers = new DataCollection($this->server->getHeaders());
        $this->files = new DataCollection($files);
        $this->body = is_string($body) ? $body : null;
        $this->base = $base;
        $this->session = $session;
    }

    /**
     * Detect from globals
     * @param Session $session
     * @return Request
     */
    public static function detect($session)
    {
        return new self ($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, null, null, $session);
    }

    /**
     * Get unique identifier for request
     *
     * @return string Unique String Identifier.
     */
    public function unique()
    {
        if ($this->unique === null) {
            $this->unique = uniqid();
        }
        return $this->unique;
    }

    /**
     * Search for parameter value
     * ORDER:
     *  - GET
     *  - POST
     *
     * @param string $key
     * @param mixed $default Default value when not found. Default null.
     *
     * @return mixed
     */
    public function param($key, $default = null)
    {
        if ($this->getParams->exists($key)) {
            return $this->getParams->get($key);
        }
        if ($this->postParams->exists($key)) {
            return $this->postParams->get($key);
        }

        return $default;
    }

    /**
     * Search for parameter value in GET query.
     *
     * @param string $key
     * @param mixed $default Default value when not found. Default null.
     *
     * @return mixed
     */
    public function paramGet($key, $default = null)
    {
        return $this->getParams->get($key, $default);
    }

    /**
     * Search for parameter value in POST array.
     *
     * @param string $key
     * @param mixed $default Default value when not found. Default null.
     *
     * @return mixed
     */
    public function paramPost($key, $default = null)
    {
        return $this->postParams->get($key, $default);
    }

    /**
     * Return the GET collection
     *
     * @return ParameterCollection
     */
    public function get()
    {
        return $this->getParams;
    }

    /**
     * Returns the POST collection
     *
     * @return ParameterCollection
     */
    public function post()
    {
        return $this->postParams;
    }

    /**
     * Returns the FILES collection (raw).
     *
     * @return DataCollection
     */
    public function files()
    {
        return $this->files;
    }

    /**
{'fraction_non_alphanumeric': 0.13230260828514104, 'fraction_numerical': 0.0009441756166646997, 'mean_word_length': 2.0702898550724638, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 68, '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': '7129458', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2368, 'n_words': 670}