<commit_before><?php
function error($code, $exception = null) {
  static $error_code_values = array(
    '404' => 'Not Found',
    '500' => 'Internal Server Error'
  );
  if (!config('run_request')) {
    if ($exception) {
      throw $exception;
    } else {
      throw new Exception('Error: ' + $code);
    }
  }
  if (!isset($error_code_values[$code])) {
    $error_code_values = json_decode(file_get_contents(__DIR__ . '/data/http_codes.json'), true);
  }
  header("HTTP/1.0 {$code} {$error_code_values[$code]}", true, $code);

  if (env('ENV') === 'development') {
    echo get_template_contents(__DIR__ . '/templates/developer_error.php', array('exception' => $exception, 'code_reason' => $error_code_values[$code], 'code' => $code));
  } else {
    $show_default_page = true;
    $error_controller = config('error_controller');
    if ($error_controller) {
      if (function_exists('run_controller')) {
        if (run_controller($error_controller, array($code, $exception), array('error_' . $code, 'error'))) {
          $show_default_page = !Controller::$__rendered;
        }
      }
    }
    if ($show_default_page) {
      if (locate_template(config('pages_root') . '/' . config('error_root'), 'error' . $code, false)) {
        echo get_template_contents('error' . $code, array('message' => $exception->getMessage()));
      } else {
        if (file_exists(__DIR__ . '/templates/missing/' . $code . '.php')) {
          echo get_template_contents(__DIR__ . '/templates/missing/' . $code . '.php', array('exception' => $exception, 'code_reason' => $error_code_values[$code]));
        } else {
          echo get_template_contents(__DIR__ . '/templates/missing/default.php', array('exception' => $exception, 'code_reason' => $error_code_values[$code], 'code' => $code));
        }
      }
    }
  }
}
function redirect($page) {
  if (!preg_match('#^\w+://#', $page)) {
    if (substr($page, 0, 1) !== '/') {
      $page = '/' . $page;
    }
    $proto = 'http' . (request('HTTPS') !== null ? 's' : '') .'://';
    $host = request('HTTP_HOST');
    $root = request('root_dir');
    $page = $proto . $host . $root . $page;
  }
  header('Location: '. $page);
  exit;
}
function &session($key = null, $value = null) {
  $session_name = config('session_name');
  if ($session_name) {
    if (!session_id()) {
      session_name($session_name);
      $lifetime = max(config('session_lifetime', 0), ini_get('session.gc_maxlifetime'));
      ini_set('session.gc_maxlifetime', $lifetime);
      session_set_cookie_params($lifetime);
      session_start();
    }
    if ($key) {
      if ($value !== null) {
        $_SESSION[$key] = $value; // implment js style hash lookup (like config; maybe extract to look up hash funciton (taking dot separators))
        return $value;
      } else {
        return $_SESSION[$key];
      }
    } else {
      $session_id = session_id();
      return $session_id;
    }
  }
  $null = null;
  return $null;
}
<commit_msg>add set_header function and improve error (still needs work though)<commit_after><?php
function get_http_code_value($code) {
  $code = (string)$code;  
  static $error_code_values = array(
    '301' => 'Moved Permanently',
    '302' => 'Found',
    '404' => 'Not Found',
    '500' => 'Internal Server Error'
  );
  if (!isset($error_code_values[strval($code)])) {
    $error_code_values = json_decode(file_get_contents(__DIR__ . '/data/http_codes.json'), true);
  }
  return $error_code_values[$code];
}
// save headers to check them later?
function set_header($key, $value = null, $code = null) {
  if (is_numeric($key)) {
    $code = $key;
    $key = null;
  }
  if ($code !== null) {
    $error_code_value = get_http_code_value($code);
    header("HTTP/1.0 {$code} {$error_code_value}", true, $code);
  }
  if ($key) {
    if ($value) {
      header("{$key}: {$value}", true);
    } elseif ($key) {
      header($key, true);
    }
  }
  return isset($error_code_value) ? $error_code_value : null;
}
function error($code, $exception = null) {
  if (!config('run_request')) {
    if ($exception) {
      throw $exception;
    } else {
      throw new Exception('Error: ' + $code);
    }
  }
  $error_code_value = set_header($code);
  if (env('env') === 'development') {
    echo get_template_contents(__DIR__ . '/templates/developer_error.php', array('exception' => $exception, 'code_reason' => $error_code_value, 'code' => $code));
  } else {
    $show_default_page = true;
    $error_controller = config('error_controller');
    if ($error_controller) {
      if (function_exists('run_controller')) {
        if (run_controller($error_controller, array($code, $exception), array('error_' . $code, 'error'))) {
          $show_default_page = !Controller::$__rendered;
        }
      }
    }
    if ($show_default_page) {
      if (($template_path = locate_template(config('pages_root') . '/' . config('error_root'), 'error' . $code, false, false))) {
        echo get_template_contents($template_path, array('message' => $exception->getMessage()));
      } else {
        if (file_exists(__DIR__ . '/templates/missing/' . $code . '.php')) {
          echo get_template_contents(__DIR__ . '/templates/missing/' . $code . '.php', array('exception' => $exception, 'code_reason' => $error_code_value));
        } else {
          echo get_template_contents(__DIR__ . '/templates/missing/default.php', array('exception' => $exception, 'code_reason' => $error_code_value, 'code' => $code));
        }
      }
    }
  }
}
function redirect($page) {
  if (!preg_match('#^\w+://#', $page)) {
    if (substr($page, 0, 1) !== '/') {
      $page = '/' . $page;
    }
    $proto = 'http' . (request('HTTPS') !== null ? 's' : '') .'://';
    $host = request('HTTP_HOST');
    $root = request('root_dir');
    $page = $proto . $host . $root . $page;
  }
  header('Location: '. $page);
  exit;
}
function &session($key = null, $value = null) {
  $session_name = config('session_name');
  if ($session_name) {
    if (!session_id()) {
      session_name($session_name);
      $lifetime = max(config('session_lifetime', 0), ini_get('session.gc_maxlifetime'));
      ini_set('session.gc_maxlifetime', $lifetime);
      session_set_cookie_params($lifetime);
      session_start();
    }
    if ($key) {
      if ($value !== null) {
        $_SESSION[$key] = $value; // implment js style hash lookup (like config; maybe extract to look up hash funciton (taking dot separators))
        return $value;
      } else {
        return $_SESSION[$key];
      }
    } else {
      $session_id = session_id();
      return $session_id;
    }
  }
  $null = null;
  return $null;
}

{'fraction_non_alphanumeric': 0.18547047273825706, 'fraction_numerical': 0.004228968433771334, 'mean_word_length': 3.231309904153355, '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': '459041', 'n_tokens_mistral': 2197, 'n_tokens_neox': 2171, 'n_words': 443}