<commit_before><?php
declare(strict_types = 1);

namespace Zortje\MVC\Network;

use Zortje\MVC\Storage\Cookie\Cookie;

/**
 * Class Request
 *
 * @package Zortje\MVC\Network
 */
class Request
{

    /**
     * @var Cookie Cookie
     */
    protected $cookie;

    /**
     * @var string Full URL
     */
    protected $url;

    /**
     * @var array POST data
     */
    public $post;

    /**
     * Request constructor.
     *
     * @param array  $server
     * @param array  $post
     * @param Cookie $cookie
     */
    public function __construct(Cookie $cookie, array $server = [], array $post = [])
    {
        $this->cookie = $cookie;
        $this->url    = $this->createUrlFromServerArray($server, !empty($server['HTTPS']));
        $this->post   = $post;
    }

    /**
     * Get request URL path
     *
     * @return string URL path
     */
    public function getPath(): string
    {
        $path = parse_url($this->url, PHP_URL_PATH);

        if (is_string($path) === false) {
            $path = '';
        }

        return $path;
    }

    /**
     * Get request POST data
     *
     * @return array POST data
     */
    public function getPost(): array
    {
        return $this->post;
    }

    /**
     * Get cookie
     *
     * @return Cookie
     */
    public function getCookie(): Cookie
    {
        return $this->cookie;
    }

    /**
     * Create URL from _SERVER array
     *
     * @param array $server _SERVER array
     * @param bool  $secure
     *
     * @return string URL
     */
    protected function createUrlFromServerArray(array $server, bool $secure = true): string
    {
        $protocol = $secure ? 'https' : 'http';
        $host     = !empty($server['HTTP_HOST']) ? $server['HTTP_HOST'] : 'www.example.com';
        $path     = !empty($server['REQUEST_URI']) ? $server['REQUEST_URI'] : '';

        $url = "$protocol://$host$path";

        return rtrim($url, '/');
    }
}<commit_msg>Adding method and headers to request object<commit_after><?php
declare(strict_types = 1);

namespace Zortje\MVC\Network;

use Zortje\MVC\Storage\Cookie\Cookie;

/**
 * Class Request
 *
 * @package Zortje\MVC\Network
 */
class Request
{

    /**
     * @var string Request method
     */
    protected $method;

    /**
     * @var string Full URL
     */
    protected $url;

    /**
     * @var array Request headers
     */
    protected $headers;

    /**
     * @var Cookie Cookie
     */
    protected $cookie;

    /**
     * @var array POST data
     */
    public $post;

    /**
     * Request constructor.
     *
     * @param array  $server
     * @param array  $post
     * @param Cookie $cookie
     */
    public function __construct(Cookie $cookie, array $server = [], array $post = [])
    {
        $this->method  = !empty($server['REQUEST_METHOD']) ? $server['REQUEST_METHOD'] : 'GET';
        $this->url     = $this->createUrlFromServerArray($server, !empty($server['HTTPS']));
        $this->headers = $this->parseHeaders($server);
        $this->cookie  = $cookie;
        $this->post    = $post;
    }

    public function getMethod(): string
    {
        return $this->method;
    }

    /**
     * Get request URL path
     *
     * @return string URL path
     */
    public function getPath(): string
    {
        $path = parse_url($this->url, PHP_URL_PATH);

        if (is_string($path) === false) {
            $path = '';
        }

        return $path;
    }

    public function getAcceptHeader(): string
    {
        return $this->headers['Accept'];
    }

    public function getAuthorizationHeader(): string
    {
        return $this->headers['Authorization'];
    }

    /**
     * Get cookie
     *
     * @return Cookie
     */
    public function getCookie(): Cookie
    {
        return $this->cookie;
    }

    /**
     * Get request POST data
     *
     * @return array POST data
     */
    public function getPost(): array
    {
        return $this->post;
    }

    /**
     * Create URL from _SERVER array
     *
     * @param array $server _SERVER array
     * @param bool  $secure
     *
     * @return string URL
     */
    protected function createUrlFromServerArray(array $server, bool $secure = true): string
    {
        $protocol = $secure ? 'https' : 'http';
        $host     = !empty($server['HTTP_HOST']) ? $server['HTTP_HOST'] : 'www.example.com';
        $path     = !empty($server['REQUEST_URI']) ? $server['REQUEST_URI'] : '';

        $url = "$protocol://$host$path";

        return rtrim($url, '/');
    }

    protected function parseHeaders(array $server): array
    {
        $headers = [
            'Accept'        => '',
            'Authorization' => ''
        ];

        foreach ($server as $header => $value) {
            if (substr($header, 0, 5) == 'HTTP_') {
                $header = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($header, 5)))));

                if (isset($headers[$header])) {
                    $headers[$header] = $value;
                }
            }
        }

        return $headers;
    }
}
{'fraction_non_alphanumeric': 0.15041289815178924, 'fraction_numerical': 0.0009830908375933936, 'mean_word_length': 1.857865168539326, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '2230481', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1503, 'n_words': 351}