<commit_before><?php

namespace Nether\Object;
use \Nether as Nether;

use \Closure as Closure;
use \Exception as Exception;
use \Iterator as Iterator;

class Datastore
implements Iterator {


	public function
	__Construct(?Array $Input=NULL) {

		if(is_array($Input))
		$this->SetData($Input);

		return;
	}

	////////////////////////////////
	////////////////////////////////

	protected
	$Data = [];
	/*//
	@type Array
	holds the data that we will operate upon.
	//*/

	public function
	GetData() {
	/*//
	@return Array
	get the literal array storing the data.
	//*/

		return $this->Data;
	}

	public function
	SetData(Array $Input) {
	/*//
	@argv Array InputData
	@return self
	force the data array to be the specified input.
	//*/

		$this->Data = $Input;
		return $this;
	}

	////////////////////////////////
	////////////////////////////////

	protected
	$Filename = '';
	/*//
	@type string
	the filename that we loaded from and will write to.
	//*/

	public function
	GetFilename():
	String {

		return $this->Filename;
	}

	public function
	SetFilename(String $Filename):
	Self {

		$this->Filename = $Filename;
		return $this;
	}

	////////////////////////////////
	////////////////////////////////

	const
	FormatPHP  = 1,
	FormatJSON = 2;

	protected
	$Format = self::FormatPHP;
	/*//
	@type Int
	defines the mode that will be used when serializing this object to write
	it to disk. valid values are php or json.
	//*/

	public function
	GetFormat():
	Int {
		return $this->Format;
	}

	public function
	SetFormat(Int $Format):
	Self {

		switch($Format) {
			case static::FormatPHP:
			case static::FormatJSON: {
				$this->Format = $Format;
				break;
			}
			default: {
				$this->Format = static::FormatPHP;
				break;
			}
		}

		return $this;
	}


	////////////////////////////////
	////////////////////////////////

	protected
	$Sorter = NULL;
	/*//
	@type Callable
	holds a callable method for sorting.
	//*/

	public function
	GetSorter() {
	/*//
	@todo strict type this when php 7 has nullable types.
	//*/

		return $this->Sorter;
	}

	public function
	SetSorter(Callable $Function):
	Self {

		$this->Sorter = $Function;
		return $this;
	}

	////////////////////////////////
	////////////////////////////////

	protected
	$Title = '';
	/*//
	@type String
	holds a title for this list for whatever purposes you wish to use it for.
	we mainly use it for grouped widgets which contain multiple of these
	datastores.
	//*/

	public function
	GetTitle():
	String {

		return $this->Title;
	}

	public function
	SetTitle(String $Title=''):
	Self {

		$this->Title = $Title;
		return $this;
	}

	////////////////////////////////
	////////////////////////////////

	// implementation of the iterator interface.
	// these allow the object to be used in things such as foreach loops.
<commit_msg>implement ArrayAccess and Countable<commit_after><?php

namespace Nether\Object;
use \Nether as Nether;

use
\Closure as Closure,
\Exception as Exception,
\Iterator as Iterator,
\ArrayAccess as ArrayAccess,
\Countable   as Countable;

class Datastore
implements Iterator, ArrayAccess, Countable {

	public function
	__Construct(?Array $Input=NULL) {

		if(is_array($Input))
		$this->SetData($Input);

		return;
	}

	////////////////////////////////
	////////////////////////////////

	protected
	$Data = [];
	/*//
	@type Array
	holds the data that we will operate upon.
	//*/

	public function
	GetData() {
	/*//
	@return Array
	get the literal array storing the data.
	//*/

		return $this->Data;
	}

	public function
	SetData(Array $Input) {
	/*//
	@argv Array InputData
	@return self
	force the data array to be the specified input.
	//*/

		$this->Data = $Input;
		return $this;
	}

	////////////////////////////////
	////////////////////////////////

	protected
	$Filename = '';
	/*//
	@type string
	the filename that we loaded from and will write to.
	//*/

	public function
	GetFilename():
	String {

		return $this->Filename;
	}

	public function
	SetFilename(String $Filename):
	Self {

		$this->Filename = $Filename;
		return $this;
	}

	////////////////////////////////
	////////////////////////////////

	const
	FormatPHP  = 1,
	FormatJSON = 2;

	protected
	$Format = self::FormatPHP;
	/*//
	@type Int
	defines the mode that will be used when serializing this object to write
	it to disk. valid values are php or json.
	//*/

	public function
	GetFormat():
	Int {
		return $this->Format;
	}

	public function
	SetFormat(Int $Format):
	Self {

		switch($Format) {
			case static::FormatPHP:
			case static::FormatJSON: {
				$this->Format = $Format;
				break;
			}
			default: {
				$this->Format = static::FormatPHP;
				break;
			}
		}

		return $this;
	}


	////////////////////////////////
	////////////////////////////////

	protected
	$Sorter = NULL;
	/*//
	@type Callable
	holds a callable method for sorting.
	//*/

	public function
	GetSorter() {
	/*//
	@todo strict type this when php 7 has nullable types.
	//*/

		return $this->Sorter;
	}

	public function
	SetSorter(Callable $Function):
	Self {

		$this->Sorter = $Function;
		return $this;
	}

	////////////////////////////////
	////////////////////////////////

	protected
	$Title = '';
	/*//
	@type String
	holds a title for this list for whatever purposes you wish to use it for.
	we mainly use it for grouped widgets which contain multiple of these
	datastores.
	//*/

	public function
	GetTitle():
	String {

		return $this->Title;
	}

	public function
	SetTitle(String $Title=''):
	Self {

		$this->Title = $Title;
		return $this;
	}

	////////////////////////////////
	////////////////////////////////

	// implementation of the array access interface.
	// these allow access like an array.

	public function
	OffsetExists($Key):
	Bool {

		return array_key_exists($Key,$this->Data);
	}

	public function
	OffsetGet($Key) {

		// php 7 is automatically calling our OffsetExists for us now.
		return $this->Data[$Key];
	}

	public function
	OffsetSet($Key,$Value):
	Void {

		$this->Data[$Key] = $Value;
		return;
	}

	public function
	OffsetUnset($Key):
	VOid {

		unset($this->Data[$Key]);
		return;
	}

	////////////////////////////////
	////////////////////////////////

	// implementation of the iterator interface.
	// these allow the object to be used in things such as foreach loops.

{'fraction_non_alphanumeric': 0.23719376391982183, 'fraction_numerical': 0.0011135857461024498, 'mean_word_length': 1.8230803771890436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '2207643', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1880, 'n_words': 583}