<commit_before><?php
namespace Terminus;

use Terminus\FileCache;
use Terminus;

class Session {
  static $instance;
  protected $data;


  public function __construct() {

    $cache = Terminus::get_cache();
    $session = $cache->get_data('session');

    if (!$session) {
      return false;
    }
    $this->data = $session;
    self::$instance = $this;
    return $this;
  }

  public function get($key = 'session', $default = false) {
    if ( isset($this->data) AND $this->data->$key )
      return $this->data->$key;
    return $default;
  }

  public function set($key, $value) {
    $this->data->$key = $value;
    return $this;
  }

  public static function instance( $session = null ) {
    if (!self::$instance) {
      self::$instance = new self($session);
    }
    return self::$instance;
  }

  public static function getValue( $key, $default = false ) {
    $session = Session::instance();
    return $session->get($key);
  }

  public static function getData() {
    $session = Session::instance();
    return $session->data;
  }

  public static function setData( $data ) {
    $cache = Terminus::get_cache();
    Terminus::line('Saving session data');
    $cache->put_data('session', $data);
    $session = self::instance();
    $session->set('data',$data);
    foreach ($data as $k=>$v) {
        $session->set($k,$v);
    }
  }

}
<commit_msg>set a default value when empty<commit_after><?php
namespace Terminus;

use Terminus\FileCache;
use Terminus;

class Session {
  static $instance;
  protected $data;


  public function __construct() {

    $cache = Terminus::get_cache();
    $session = $cache->get_data('session');

    if (!$session) {
      return false;
    }
    $this->data = $session;
    self::$instance = $this;
    return $this;
  }

  public function get($key = 'session', $default = false) {
    if ( isset($this->data) AND $this->data->$key )
      return $this->data->$key;
    return $default;
  }

  public function set($key, $value) {
    $this->data->$key = !empty($value) ? $value : null;
    return $this;
  }

  public static function instance( $session = null ) {
    if (!self::$instance) {
      self::$instance = new self($session);
    }
    return self::$instance;
  }

  public static function getValue( $key, $default = false ) {
    $session = Session::instance();
    return $session->get($key);
  }

  public static function getData() {
    $session = Session::instance();
    return $session->data;
  }

  public static function setData( $data ) {
    $cache = Terminus::get_cache();
    Terminus::line('Saving session data');
    $cache->put_data('session', $data);
    $session = self::instance();
    $session->set('data',$data);
    foreach ($data as $k=>$v) {
        $session->set($k,$v);
    }
  }

}

{'fraction_non_alphanumeric': 0.1716552470248828, 'fraction_numerical': 0.0, 'mean_word_length': 3.1279761904761907, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '3709603', 'n_tokens_mistral': 896, 'n_tokens_neox': 889, 'n_words': 215}