<commit_before><?php
namespace Colibri\Base;

use Colibri\Base\IDynamicCollection;

/**
 * class DynamicCollection
 * 
 * Реализует интерфейс для доступа к элементам при обращении к клвссу как к массиву
 * А также добавляет функции доступа к свойствам, реализованные в PropertyAccess
 * 
 * @author		<NAME> aka alek13 <<EMAIL>>
 * @package		xTeam
 * @subpackage	a13FW
 * @version		1.00.4
 */
abstract class DynamicCollection extends PropertyAccess implements IDynamicCollection
{
	protected	$_items=null;
	
	abstract protected	function fillItems();
	
	// ArrayAccess
	public function offsetExists($offset)		{	if ($this->_items===null)	$this->fillItems();return isset($this->_items[$offset]);	}
	public function offsetGet($offset)			{	if ($this->_items===null)	$this->fillItems();return $this->_items[$offset];			}
	public function offsetSet($offset, $data)	{	if ($this->_items===null)	$this->fillItems();return $this->_items[$offset]=$data;		}
	public function offsetUnset($offset)		{	if ($this->_items===null)	$this->fillItems();unset($this->_items[$offset]);			}
	
	// Iterator
	public function rewind()	{	if ($this->_items===null)	$this->fillItems();       reset($this->_items);		}
	public function current()	{	if ($this->_items===null)	$this->fillItems();return current($this->_items);	}
	public function key()		{	if ($this->_items===null)	$this->fillItems();return key($this->_items);		}
	public function next()		{	if ($this->_items===null)	$this->fillItems();return next($this->_items);		}
	public function valid()		{	if ($this->_items===null)	$this->fillItems();return $this->current()!==false;	}
	
	// Countable
	public function count()		{	if ($this->_items===null)	$this->fillItems();return count($this->_items);		}
	
	
	public function toArray()	{	if ($this->_items===null)	$this->fillItems();return array_values(get_object_vars($this));	}
	public function toDblArray()
	{
		if ($this->_items===null) $this->fillItems();
		$retArr=array();
		$count=count($this->_items);
		for ($i=0;$i<$count;$i++)
			$retArr[]=get_object_vars($this->_items[$i]);
		return $retArr;
	}
}
<commit_msg>toJson() for objects & collections<commit_after><?php
namespace Colibri\Base;

use Colibri\Base\IDynamicCollection;

/**
 * class DynamicCollection
 * 
 * Реализует интерфейс для доступа к элементам при обращении к клвссу как к массиву
 * А также добавляет функции доступа к свойствам, реализованные в PropertyAccess
 * 
 * @author		<NAME> aka alek13 <<EMAIL>>
 * @package		xTeam
 * @subpackage	a13FW
 * @version		1.00.4
 */
abstract class DynamicCollection extends PropertyAccess implements IDynamicCollection
{
	protected	$_items=null;
	
	abstract protected	function fillItems();
	
	// ArrayAccess
	public function offsetExists($offset)		{	if ($this->_items===null)	$this->fillItems();return isset($this->_items[$offset]);	}
	public function offsetGet($offset)			{	if ($this->_items===null)	$this->fillItems();return $this->_items[$offset];			}
	public function offsetSet($offset, $data)	{	if ($this->_items===null)	$this->fillItems();return $this->_items[$offset]=$data;		}
	public function offsetUnset($offset)		{	if ($this->_items===null)	$this->fillItems();unset($this->_items[$offset]);			}
	
	// Iterator
	public function rewind()	{	if ($this->_items===null)	$this->fillItems();       reset($this->_items);		}
	public function current()	{	if ($this->_items===null)	$this->fillItems();return current($this->_items);	}
	public function key()		{	if ($this->_items===null)	$this->fillItems();return key($this->_items);		}
	public function next()		{	if ($this->_items===null)	$this->fillItems();return next($this->_items);		}
	public function valid()		{	if ($this->_items===null)	$this->fillItems();return $this->current()!==false;	}
	
	// Countable
	public function count()		{	if ($this->_items===null)	$this->fillItems();return count($this->_items);		}
	
	
	public function toArray()	{	if ($this->_items===null)	$this->fillItems();return array_values(get_object_vars($this));	}
	public function toDblArray()
	{
		if ($this->_items===null) $this->fillItems();
		$retArr=array();
		$count=count($this->_items);
		for ($i=0;$i<$count;$i++)
			$retArr[]=get_object_vars($this->_items[$i]);
		return $retArr;
	}
    public function toJson()
    {
        return json_encode($this->toDblArray());
    }
}

{'fraction_non_alphanumeric': 0.18594368163835234, 'fraction_numerical': 0.004188969048173144, 'mean_word_length': 5.386329866270431, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 82, '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': '2185443', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1479, 'n_words': 302}