<commit_before><?php namespace Zephyrus\Network;

class Cookie
{
    public const DURATION_SESSION = 0;
    public const DURATION_HOUR = 3600;
    public const DURATION_DAY = 86400;
    public const DURATION_WEEK = 604800;
    public const DURATION_MONTH = 2419200;
    public const DURATION_YEAR = 29030400;
    public const DURATION_FOREVER = 145152000; // 5 years

    /**
     * Cookie name used to identify.
     *
     * @var string
     */
    private string $name;

    /**
     * Cookie value which will end stored on clients' side.
     *
     * @var string|null
     */
    private ?string $value;

    /**
     * Cookie expire time (timestamp).
     *
     * @var int
     */
    private int $lifetime = self::DURATION_SESSION;

    /**
     * The domain that the cookie is available to.
     *
     * @var string
     */
    private string $domain = '';

    /**
     * The path on the server which the cookie will be available on. If set to '/' (default value), the cookie will be
     * available to the entire specified domain.
     *
     * @var string
     */
    private string $path = '/';

    /**
     * Determines if the cookie should be sent only over HTTPS from the client side.
     *
     * @var bool
     */
    private bool $secure = true;

    /**
     * Determines if the cookie is made accessible only through the HTTP protocol and thus making it inaccessible from
     * frontend scripting language.
     *
     * @var bool
     */
    private bool $httpOnly = true;

    /**
     * Determines if url encoding should be used for the cookie value.
     *
     * @var bool
     */
    private bool $urlEncodedValue = false;

    /**
     * @var string
     */
    private string $sameSite = 'Strict';

    /**
     * Shorthand method to immediately read a cookie value or receive the default value in case the cookie doesn't
     * exist.
     *
     * @param string $name
     * @param string|null $defaultValue
     * @return string|null
     */
    public static function read(string $name, ?string $defaultValue = null): ?string
    {
        return $_COOKIE[$name] ?? $defaultValue;
    }

    /**
     * Cookie constructor which automatically create the cookie in the HTTP response header upon usage of the send
     * method once it's fully configured.
     *
     * @param string $name
     * @param string|null $value
     */
    public function __construct(string $name, ?string $value = null)
    {
        $this->name = $name;
        $this->value = (!is_null($value)) ? $value : self::read($name);
    }

    /**
     * Save the cookie in the HTTP response header using the default PHP functions setcookie or setrawcookie depending
     * on the need to save the cookie value without url encoding.
     *
     * @see http://php.net/manual/en/function.setcookie.php
     * @see http://php.net/manual/en/function.setrawcookie.php
     */
    public function send()
    {
        $options = [
            'expires' => time() + $this->lifetime,
            'path' => $this->path,
            'domain' => $this->domain,
            'secure' => $this->secure && ($_SERVER['HTTPS'] ?? false),
            'httponly' => $this->httpOnly,<commit_msg>Corrected cookie to allow expiration based on browser session<commit_after><?php namespace Zephyrus\Network;

class Cookie
{
    public const DURATION_SESSION = 0;
    public const DURATION_HOUR = 3600;
    public const DURATION_DAY = 86400;
    public const DURATION_WEEK = 604800;
    public const DURATION_MONTH = 2419200;
    public const DURATION_YEAR = 29030400;
    public const DURATION_FOREVER = 145152000; // 5 years

    /**
     * Cookie name used to identify.
     *
     * @var string
     */
    private string $name;

    /**
     * Cookie value which will end stored on clients' side.
     *
     * @var string|null
     */
    private ?string $value;

    /**
     * Cookie expire time (timestamp).
     *
     * @var int
     */
    private int $lifetime = self::DURATION_SESSION;

    /**
     * The domain that the cookie is available to.
     *
     * @var string
     */
    private string $domain = '';

    /**
     * The path on the server which the cookie will be available on. If set to '/' (default value), the cookie will be
     * available to the entire specified domain.
     *
     * @var string
     */
    private string $path = '/';

    /**
     * Determines if the cookie should be sent only over HTTPS from the client side.
     *
     * @var bool
     */
    private bool $secure = true;

    /**
     * Determines if the cookie is made accessible only through the HTTP protocol and thus making it inaccessible from
     * frontend scripting language.
     *
     * @var bool
     */
    private bool $httpOnly = true;

    /**
     * Determines if url encoding should be used for the cookie value.
     *
     * @var bool
     */
    private bool $urlEncodedValue = false;

    /**
     * @var string
     */
    private string $sameSite = 'Strict';

    /**
     * Shorthand method to immediately read a cookie value or receive the default value in case the cookie doesn't
     * exist.
     *
     * @param string $name
     * @param string|null $defaultValue
     * @return string|null
     */
    public static function read(string $name, ?string $defaultValue = null): ?string
    {
        return $_COOKIE[$name] ?? $defaultValue;
    }

    /**
     * Cookie constructor which automatically create the cookie in the HTTP response header upon usage of the send
     * method once it's fully configured.
     *
     * @param string $name
     * @param string|null $value
     */
    public function __construct(string $name, ?string $value = null)
    {
        $this->name = $name;
        $this->value = (!is_null($value)) ? $value : self::read($name);
    }

    /**
     * Save the cookie in the HTTP response header using the default PHP functions setcookie or setrawcookie depending
     * on the need to save the cookie value without url encoding.
     *
     * @see http://php.net/manual/en/function.setcookie.php
     * @see http://php.net/manual/en/function.setrawcookie.php
     */
    public function send()
    {
        $options = [
            'expires' => $this->lifetime  > 0 ? time() + $this->lifetime : 0,
            'path' => $this->path,
            'domain' => $this->domain,
            'secure' => $this->secure && ($_SERVER['HTTPS'] ?? false),
            'httponly' => $this->httpOnly,
{'fraction_non_alphanumeric': 0.10647214030731025, 'fraction_numerical': 0.013037404935589011, 'mean_word_length': 2.1696999508116086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '340398', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1822, 'n_words': 636}