<commit_before><?php
/**
 *
 * Goals:
 * - Provide a struct of non-session superglobals as read-only properties.
 * - Add other read-only properties calculated from the superglobals ($method,
 *   $headers, $content, etc.) to the struct.
 * - Only build things that don't require application input; e.g., no negotiation,
 *   but build acceptables for application to work through.
 * - No methods, just properties (i.e., a struct).
 *
 * @property-read $acceptCharset
 * @property-read $acceptEncoding
 * @property-read $acceptLanguage
 * @property-read $acceptMedia
 * @property-read $authDigest
 * @property-read $authPw
 * @property-read $authType
 * @property-read $authUser
 * @property-read $content
 * @property-read $contentCharset
 * @property-read $contentLength
 * @property-read $contentMd5
 * @property-read $contentType
 * @property-read $cookie
 * @property-read $env
 * @property-read $files
 * @property-read $get
 * @property-read $headers
 * @property-read $method
 * @property-read $post
 * @property-read $secure
 * @property-read $server
 * @property-read $uploads
 * @property-read $url
 * @property-read $xhr
 *
 */
class StdRequest
{
    private $acceptCharset = [];
    private $acceptEncoding = [];
    private $acceptLanguage = [];
    private $acceptMedia = [];
    private $authDigest;
    private $authPw;
    private $authType;
    private $authUser;
    private $content;
    private $contentCharset;
    private $contentLength;
    private $contentMd5;
    private $contentType;
    private $cookie = [];
    private $env = [];
    private $files = [];
    private $get = [];
    private $headers = [];
    private $method = '';
    private $post = [];
    private $secure = false;
    private $server = [];
    private $uploads = [];
    private $url;
    private $xhr = false;

    public function __construct(array $globals = array())
    {
        $this->env = $globals['_ENV'] ?? $_ENV;
        $this->server = $globals['_SERVER'] ?? $_SERVER;

        $this->cookie = $globals['_COOKIE'] ?? $_COOKIE;
        $this->files = $globals['_FILES'] ?? $_FILES;
        $this->get = $globals['_GET'] ?? $_GET;
        $this->post = $globals['_POST'] ?? $_POST;

        $this->setMethod();
        $this->setHeaders();
        $this->setSecure();
        $this->setUrl();
        $this->setAccepts();
        $this->setAuth();
        $this->setContent();
        $this->setUploads();
    }

    public function __get($key) // : array
    {
        if (property_exists($this, $key)) {
            return $this->$key;
        }

        throw new RuntimeException("StdRequest::\${$key} does not exist.");
    }

    public function __set($key, $val) // : void
    {
        throw new RuntimeException("StdRequest is read-only.");
    }

    public function __isset($key) // : bool
    {
        if (property_exists($this, $key)) {
            return isset($this->$key);
        }

        return false;
    }

    public function __unset($key) // : void
    {
        if( property_exists($this, $key) ) {
            throw new RuntimeException("StdRequest is read-only.");
        }
    }

    protected function setMethod() // : void
    {
        if (isset($this->server['REQUEST_METHOD'])) {
            $this->method = strtoupper($this->server['REQUEST_METHOD']);
        }

        if ($this->method == 'POST' && isset($this->server['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
            $this->method = strtoupper($this->server['HTTP_X_HTTP_METHOD_OVERRIDE']);
            $this->xhr = true;
        }
    }
<commit_msg>Update actual reference implementation<commit_after><?php
/**
 *
 * Goals:
 * - Provide a struct of non-session superglobals as read-only properties.
 * - Add other read-only properties calculated from the superglobals ($method,
 *   $headers, $content, etc.) to the struct.
 * - Only build things that don't require application input; e.g., no negotiation,
 *   but build acceptables for application to work through.
 * - No methods, just properties (i.e., a struct).
 *
 * @property-read $acceptCharset
 * @property-read $acceptEncoding
 * @property-read $acceptLanguage
 * @property-read $acceptMedia
 * @property-read $authDigest
 * @property-read $authPw
 * @property-read $authType
 * @property-read $authUser
 * @property-read $content
 * @property-read $contentCharset
 * @property-read $contentLength
 * @property-read $contentMd5
 * @property-read $contentType
 * @property-read $cookie
 * @property-read $env
 * @property-read $files
 * @property-read $get
 * @property-read $headers
 * @property-read $method
 * @property-read $post
 * @property-read $secure
 * @property-read $server
 * @property-read $uploads
 * @property-read $url
 * @property-read $xhr
 *
 */
class StdRequest
{
    private $acceptCharset = [];
    private $acceptEncoding = [];
    private $acceptLanguage = [];
    private $acceptMedia = [];
    private $authDigest;
    private $authPw;
    private $authType;
    private $authUser;
    private $content;
    private $contentCharset;
    private $contentLength;
    private $contentMd5;
    private $contentType;
    private $cookie = [];
    private $env = [];
    private $files = [];
    private $get = [];
    private $headers = [];
    private $method = '';
    private $post = [];
    private $secure = false;
    private $server = [];
    private $uploads = [];
    private $url;
    private $xhr = false;

    public function __construct(array $globals = array())
    {
        $this->env = $globals['_ENV'] ?? $_ENV;
        $this->server = $globals['_SERVER'] ?? $_SERVER;

        $this->cookie = $globals['_COOKIE'] ?? $_COOKIE;
        $this->files = $globals['_FILES'] ?? $_FILES;
        $this->get = $globals['_GET'] ?? $_GET;
        $this->post = $globals['_POST'] ?? $_POST;

        $this->setMethod();
        $this->setHeaders();
        $this->setSecure();
        $this->setUrl();
        $this->setAccepts();
        $this->setAuth();
        $this->setContent();
        $this->setUploads();
    }

    public function __get($key) // : array
    {
        if (property_exists($this, $key)) {
            return $this->$key;
        }

        $class = get_class($this);
        throw new RuntimeException("{$class}::\${$key} does not exist.");
    }

    public function __set($key, $val) // : void
    {
        $class = get_class($this);
        throw new RuntimeException("{$class}::\${$key} is read-only.");
    }

    public function __isset($key) // : bool
    {
        if (property_exists($this, $key)) {
            return isset($this->$key);
        }

        return false;
    }

    public function __unset($key) // : void
    {
        if( property_exists($this, $key) ) {
            $class = get_class($this);
            throw new RuntimeException("{$class}::\${$key} is read-only.");
        }
    }

    protected function setMethod() // : void
    {
        if (isset($this->server['REQUEST_METHOD'])) {
            $this->method = strtoupper($this->server['REQUEST_METHOD']);
        }

        if ($this->method == 'POST' && isset($this->server['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
            $this->method = strtoupper($this->server['HTTP_X_HTTP_METHOD_OVERRIDE']);
            $this->xhr = true;
        }
    }

{'fraction_non_alphanumeric': 0.15880242825607063, 'fraction_numerical': 0.0005518763796909492, 'mean_word_length': 2.670379746835443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '5494575', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2183, 'n_words': 511}