<commit_before><?php namespace Laravel;

use Closure;
use Laravel\Session\Drivers\Driver;
use Laravel\Session\Drivers\Sweeper;

if (Config::$items['application']['key'] === '')
{
	throw new \Exception("An application key is required to use sessions.");
}

class Session {

	/**
	 * The session array that is stored by the driver.
	 *
	 * @var array
	 */
	protected static $session;

	/**
	 * Indicates if the session already exists in storage.
	 *
	 * @var bool
	 */
	protected static $exists = true;

	/**
	 * Start the session handling for the current request.
	 *
	 * @param  Driver  $driver
	 * @return void
	 */
	public static function start(Driver $driver)
	{
		if ( ! is_null($id = Cookie::get(Config::$items['session']['cookie'])))
		{
			static::$session = $driver->load($id);
		}

		if (static::invalid())
		{
			static::$exists = false;

			static::$session = array('id' => Str::random(40), 'data' => array());
		}

		if ( ! static::has('csrf_token'))
		{
			// A CSRF token is stored in every session. The token is used by the
			// Form class and the "csrf" filter to protect the application from
			// cross-site request forgery attacks. The token is simply a long,
			// random string which should be posted with each request.
			static::put('csrf_token', Str::random(40));
		}
	}

	/**
	 * Deteremine if the session payload instance is valid.
	 *
	 * The session is considered valid if it exists and has not expired.
	 *
	 * @return bool
	 */
	protected static function invalid()
	{
		$lifetime = Config::$items['session']['lifetime'];

		$idle = time() - static::$session['last_activity'];

		return is_null(static::$session) or ($idle > ($lifetime * 60));
	}

	/**
	 * Determine if session handling has been started for the request.
	 *
	 * @return bool
	 */
	public static function started()
	{
		return is_array(static::$session);
	}

	/**<commit_msg>fix bug in session class.<commit_after><?php namespace Laravel;

use Closure;
use Laravel\Session\Drivers\Driver;
use Laravel\Session\Drivers\Sweeper;

if (Config::$items['application']['key'] === '')
{
	throw new \Exception("An application key is required to use sessions.");
}

class Session {

	/**
	 * The session array that is stored by the driver.
	 *
	 * @var array
	 */
	protected static $session;

	/**
	 * Indicates if the session already exists in storage.
	 *
	 * @var bool
	 */
	protected static $exists = true;

	/**
	 * Start the session handling for the current request.
	 *
	 * @param  Driver  $driver
	 * @return void
	 */
	public static function start(Driver $driver)
	{
		if ( ! is_null($id = Cookie::get(Config::$items['session']['cookie'])))
		{
			static::$session = $driver->load($id);
		}

		if (is_null(static::$session) or static::invalid())
		{
			static::$exists = false;

			static::$session = array('id' => Str::random(40), 'data' => array());
		}

		if ( ! static::has('csrf_token'))
		{
			// A CSRF token is stored in every session. The token is used by the
			// Form class and the "csrf" filter to protect the application from
			// cross-site request forgery attacks. The token is simply a long,
			// random string which should be posted with each request.
			static::put('csrf_token', Str::random(40));
		}
	}

	/**
	 * Deteremine if the session payload instance is valid.
	 *
	 * The session is considered valid if it exists and has not expired.
	 *
	 * @return bool
	 */
	protected static function invalid()
	{
		$lifetime = Config::$items['session']['lifetime'];

		return (time() - static::$session['last_activity']) > ($lifetime * 60);
	}

	/**
	 * Determine if session handling has been started for the request.
	 *
	 * @return bool
	 */
	public static function started()
	{
		return is_array(static::$session);
	}

	/**
{'fraction_non_alphanumeric': 0.14641327623126338, 'fraction_numerical': 0.0032119914346895075, 'mean_word_length': 3.448809523809524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '4469427', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1120, 'n_words': 374}