<commit_before><?php

namespace Ergo\Error;

/**
 * A class for gathering contextual information when an error occurs
 */
class ErrorContext
{
	private $_context=array();

	public function export()
	{
		$context = \Ergo::isConsole() ? $this->_consoleContext() : $this->_webContext();

		return array_merge($context, $this->_context);
	}

	public function add($key, $value)
	{
		$this->_context[$key] = $value;
	}

	public function remove($key)
	{
		unset($this->_context[$key]);
	}

	protected function _consoleContext()
	{
		$user = isset($_SERVER['USER']) ? $_SERVER['USER'] : 'unknown';

		return array(
			'Environment'=>'Console',
			'Host Name'=>gethostname(),
			'User'=>$user,
			'Script'=>$_SERVER['SCRIPT_FILENAME'],
			'Working Dir'=>getcwd(),
			'Umask'=>sprintf("%04o", umask()),
		);
	}
<commit_msg>Add ErrorContext::get to allow easier interrogation of the error context<commit_after><?php

namespace Ergo\Error;

/**
 * A class for gathering contextual information when an error occurs
 */
class ErrorContext
{
	private $_context=array();

	public function export()
	{
		$context = \Ergo::isConsole() ? $this->_consoleContext() : $this->_webContext();

		return array_merge($context, $this->_context);
	}

	public function add($key, $value)
	{
		$this->_context[$key] = $value;
	}

	public function remove($key)
	{
		unset($this->_context[$key]);
	}

	public function get($key, $default = null)
	{
		return isset($this->_context[$key]) ? $this->_context[$key] : $default;
	}

	protected function _consoleContext()
	{
		$user = isset($_SERVER['USER']) ? $_SERVER['USER'] : 'unknown';

		return array(
			'Environment'=>'Console',
			'Host Name'=>gethostname(),
			'User'=>$user,
			'Script'=>$_SERVER['SCRIPT_FILENAME'],
			'Working Dir'=>getcwd(),
			'Umask'=>sprintf("%04o", umask()),
		);
	}

{'fraction_non_alphanumeric': 0.18895027624309393, 'fraction_numerical': 0.0022099447513812156, 'mean_word_length': 4.841935483870968, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '911123', 'n_tokens_mistral': 640, 'n_tokens_neox': 589, 'n_words': 128}