<commit_before><?php
namespace Entity;

use \Doctrine\Common\Collections\ArrayCollection;

/**
 * @Table(name="sessions", indexes={
 *   @index(name="cleanup_idx", columns={"expires"})
 * })
 * @Entity
 */
class Session extends \DF\Doctrine\Entity
{
    public function __construct()
    {
        $this->last_modified = time();
        $this->user_agent = $_SERVER['HTTP_USER_AGENT'];
    }

    /**
     * @Column(name="id", type="string", length=128)
     * @Id
     */
    protected $id;

    /** @Column(name="user_agent", type="string", length=255) */
    protected $user_agent;

    /** @Column(name="expires", type="integer") */
    protected $expires;

    public function setLifetime($lifetime)
    {
        $this->expires = time()+$lifetime;
    }

    /** @Column(name="last_modified", type="integer") */
    protected $last_modified;

    /** @Column(name="data", type="text", nullable=true) */
    protected $data;

    /*
     * Validate session.
     * @return boolean
     */
    public function isValid()
    {
        if ($this->expires < time())
            return false;

        $current_ua = $_SERVER['HTTP_USER_AGENT'];
        if (strcmp($this->user_agent, $current_ua) !== 0)
            return false;

        return true;
    }
}<commit_msg>Allow for null user agents in sessions.<commit_after><?php
namespace Entity;

use \Doctrine\Common\Collections\ArrayCollection;

/**
 * @Table(name="sessions", indexes={
 *   @index(name="cleanup_idx", columns={"expires"})
 * })
 * @Entity
 */
class Session extends \DF\Doctrine\Entity
{
    public function __construct()
    {
        $this->last_modified = time();
        $this->user_agent = $_SERVER['HTTP_USER_AGENT'];

        if (empty($this->user_agent))
            $this->user_agent = 'none';
    }

    /**
     * @Column(name="id", type="string", length=128)
     * @Id
     */
    protected $id;

    /** @Column(name="user_agent", type="string", length=255, nullable=true) */
    protected $user_agent;

    /** @Column(name="expires", type="integer") */
    protected $expires;

    public function setLifetime($lifetime)
    {
        $this->expires = time()+$lifetime;
    }

    /** @Column(name="last_modified", type="integer") */
    protected $last_modified;

    /** @Column(name="data", type="text", nullable=true) */
    protected $data;

    /*
     * Validate session.
     * @return boolean
     */
    public function isValid()
    {
        if ($this->expires < time())
            return false;

        $current_ua = $_SERVER['HTTP_USER_AGENT'];
        if (empty($current_ua))
            $current_ua = 'none';

        if (strcmp($this->user_agent, $current_ua) !== 0)
            return false;

        return true;
    }
}
{'fraction_non_alphanumeric': 0.17125045837917124, 'fraction_numerical': 0.005133846718005134, 'mean_word_length': 2.64218958611482, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '790184', 'n_tokens_mistral': 872, 'n_tokens_neox': 840, 'n_words': 159}